Skip to content

Commit

Permalink
Reduce precision to 8 places for query tokens (including BBOX) so tha…
Browse files Browse the repository at this point in the history
…t tests pass on amd64 and arm64
  • Loading branch information
jchamberlain authored and ARolek committed Nov 9, 2023
1 parent a6f1b0c commit b7ad33b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions provider/hana/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ func replaceTokens(dbVersion uint, sql string, idFieldName string, geomFieldName
idFieldToken, idFieldName,
geomFieldToken, geomFieldName,
geomTypeToken, geoType,
scaleDenominatorToken, strconv.FormatFloat(scaleDenominator, 'f', -1, 64),
pixelWidthToken, strconv.FormatFloat(pixelWidth, 'f', -1, 64),
pixelHeightToken, strconv.FormatFloat(pixelHeight, 'f', -1, 64),
scaleDenominatorToken, strconv.FormatFloat(scaleDenominator, 'f', 8, 64),
pixelWidthToken, strconv.FormatFloat(pixelWidth, 'f', 8, 64),
pixelHeightToken, strconv.FormatFloat(pixelHeight, 'f', 8, 64),
)

uppercaseTokenSQL := uppercaseTokens(sql)
Expand Down Expand Up @@ -733,8 +733,8 @@ func extractQueryParamValues(pname string, maps []provider.Map, layer *Layer) pr

var tokenRe = regexp.MustCompile("![a-zA-Z0-9_-]+!")

// uppercaseTokens converts all !tokens! to uppercase !TOKENS!. Tokens can
// contain alphanumerics, dash and underline chars.
// uppercaseTokens converts all !tokens! to uppercase !TOKENS!. Tokens can
// contain alphanumerics, dash and underline chars.
func uppercaseTokens(str string) string {
return tokenRe.ReplaceAllStringFunc(str, strings.ToUpper)
}
Expand Down
2 changes: 1 addition & 1 deletion provider/hana/util_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestReplaceTokens(t *testing.T) {
sql: "SELECT id, !pixel_width! as width, !pixel_height! as height, !scale_denominator! as scale_denom FROM foo WHERE !BBOX!",
layer: Layer{srid: tegola.WebMercator, geomField: "geom"},
tile: provider.NewTile(11, 1070, 676, 64, tegola.WebMercator),
expected: `SELECT id, 76.43702827453671 as width, 76.43702827453671 as height, 272989.38669477403 as scale_denom FROM foo WHERE "geom".ST_IntersectsRectPlanar(NEW ST_POINT($1, $3), NEW ST_POINT($2, $3)) = 1`,
expected: `SELECT id, 76.43702827 as width, 76.43702827 as height, 272989.38669477 as scale_denom FROM foo WHERE "geom".ST_IntersectsRectPlanar(NEW ST_POINT($1, $3), NEW ST_POINT($2, $3)) = 1`,
},
}

Expand Down
8 changes: 4 additions & 4 deletions provider/postgis/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func replaceTokens(sql string, lyr *Layer, tile provider.Tile, withBuffer bool)

minPt, maxPt := minGeo.(geom.Point), maxGeo.(geom.Point)

bbox := fmt.Sprintf("ST_MakeEnvelope(%g,%g,%g,%g,%d)", minPt.X(), minPt.Y(), maxPt.X(), maxPt.Y(), srid)
bbox := fmt.Sprintf("ST_MakeEnvelope(%.8f,%.8f,%.8f,%.8f,%d)", minPt.X(), minPt.Y(), maxPt.X(), maxPt.Y(), srid)

extent, _ = tile.Extent()
// TODO: Always convert to meter if we support different projections
Expand All @@ -161,9 +161,9 @@ func replaceTokens(sql string, lyr *Layer, tile provider.Tile, withBuffer bool)
config.ZToken, strconv.FormatUint(uint64(z), 10),
config.XToken, strconv.FormatUint(uint64(x), 10),
config.YToken, strconv.FormatUint(uint64(y), 10),
config.ScaleDenominatorToken, strconv.FormatFloat(scaleDenominator, 'f', -1, 64),
config.PixelWidthToken, strconv.FormatFloat(pixelWidth, 'f', -1, 64),
config.PixelHeightToken, strconv.FormatFloat(pixelHeight, 'f', -1, 64),
config.ScaleDenominatorToken, strconv.FormatFloat(scaleDenominator, 'f', 8, 64),
config.PixelWidthToken, strconv.FormatFloat(pixelWidth, 'f', 8, 64),
config.PixelHeightToken, strconv.FormatFloat(pixelHeight, 'f', 8, 64),
config.IdFieldToken, lyr.IDFieldName(),
config.GeomFieldToken, lyr.GeomFieldName(),
config.GeomTypeToken, geoType,
Expand Down
10 changes: 5 additions & 5 deletions provider/postgis/util_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,31 @@ func TestReplaceTokens(t *testing.T) {
sql: "SELECT * FROM foo WHERE geom && !BBOX!",
layer: Layer{srid: tegola.WebMercator},
tile: provider.NewTile(2, 1, 1, 64, tegola.WebMercator),
expected: "SELECT * FROM foo WHERE geom && ST_MakeEnvelope(-1.017529720390625e+07,-156543.03390625,156543.03390625,1.017529720390625e+07,3857)",
expected: "SELECT * FROM foo WHERE geom && ST_MakeEnvelope(-10175297.20390625,-156543.03390625,156543.03390625,10175297.20390625,3857)",
},
"replace BBOX with != in query": {
sql: "SELECT * FROM foo WHERE geom && !BBOX! AND bar != 42",
layer: Layer{srid: tegola.WebMercator},
tile: provider.NewTile(2, 1, 1, 64, tegola.WebMercator),
expected: "SELECT * FROM foo WHERE geom && ST_MakeEnvelope(-1.017529720390625e+07,-156543.03390625,156543.03390625,1.017529720390625e+07,3857) AND bar != 42",
expected: "SELECT * FROM foo WHERE geom && ST_MakeEnvelope(-10175297.20390625,-156543.03390625,156543.03390625,10175297.20390625,3857) AND bar != 42",
},
"replace BBOX and ZOOM 1": {
sql: "SELECT id, scalerank=!ZOOM! FROM foo WHERE geom && !BBOX!",
layer: Layer{srid: tegola.WebMercator},
tile: provider.NewTile(2, 1, 1, 64, tegola.WebMercator),
expected: "SELECT id, scalerank=2 FROM foo WHERE geom && ST_MakeEnvelope(-1.017529720390625e+07,-156543.03390625,156543.03390625,1.017529720390625e+07,3857)",
expected: "SELECT id, scalerank=2 FROM foo WHERE geom && ST_MakeEnvelope(-10175297.20390625,-156543.03390625,156543.03390625,10175297.20390625,3857)",
},
"replace BBOX and ZOOM 2": {
sql: "SELECT id, scalerank=!ZOOM! FROM foo WHERE geom && !BBOX!",
layer: Layer{srid: tegola.WebMercator},
tile: provider.NewTile(16, 11241, 26168, 64, tegola.WebMercator),
expected: "SELECT id, scalerank=16 FROM foo WHERE geom && ST_MakeEnvelope(-1.3163688815956049e+07,4.0352540420407765e+06,-1.3163058210472783e+07,4.035884647524042e+06,3857)",
expected: "SELECT id, scalerank=16 FROM foo WHERE geom && ST_MakeEnvelope(-13163688.81595605,4035254.04204078,-13163058.21047278,4035884.64752404,3857)",
},
"replace pixel_width/height and scale_denominator": {
sql: "SELECT id, !pixel_width! as width, !pixel_height! as height, !scale_denominator! as scale_denom FROM foo WHERE geom && !BBOX!",
layer: Layer{srid: tegola.WebMercator},
tile: provider.NewTile(11, 1070, 676, 64, tegola.WebMercator),
expected: "SELECT id, 76.43702827453671 as width, 76.43702827453671 as height, 272989.38669477403 as scale_denom FROM foo WHERE geom && ST_MakeEnvelope(899816.6968478388,6.789748347570495e+06,919996.0723123164,6.809927723034973e+06,3857)",
expected: "SELECT id, 76.43702827 as width, 76.43702827 as height, 272989.38669477 as scale_denom FROM foo WHERE geom && ST_MakeEnvelope(899816.69684784,6789748.34757049,919996.07231232,6809927.72303497,3857)",
},
}

Expand Down

0 comments on commit b7ad33b

Please sign in to comment.