Skip to content

Commit 449f097

Browse files
craig[bot]yuzefovich
andcommitted
148778: geomfn: adjust two tests to work on s390x r=yuzefovich a=yuzefovich `angleFromCoords` function uses `atan` to compute some geometry functions. s390x system has architecture support for that trigonometric function which can produce slightly different result than when computing via math operations, which resulted in a false positive failure in a couple of tests. This commit teaches those tests to use our custom float comparison function that only checks 15 significant decimal digits. Fixes: #145985. Release note: None 148784: logictest: adjust a few of geo tests for s390x r=yuzefovich a=yuzefovich Similar to other patches, we need to do some rounding for a couple of geo logic tests. This is the case since s390x has architecture support for trigonometric functions which are used when computing `ST_Segmentize` and `ST_Rotate` builtins. Note that the "rounding" is performed via regexp replacement on top of the textual result. Relatedly, we have a couple of tests that print inverted index keys, and for some shapes / geographies we use s2 library which also uses trigonometric functions. Thus, this commit adjusts those tests to account for the minor differences. This behavior suggests another limitation for heterogeneous clusters - we cannot guarantee to correctly read inverted geo indexes when the SQL pod and the KV / storage node run on different architectures. I don't think there is any concern for "pure" s390x clusters since they will behave consistently within the cluster. This limitation is filed as #148783. Fixes: #146001. Fixes: #146007. Fixes: #146109. Release note: None Co-authored-by: Yahor Yuzefovich <[email protected]>
3 parents dddeb0d + fe0dcd2 + 9308fd0 commit 449f097

File tree

5 files changed

+102
-11
lines changed

5 files changed

+102
-11
lines changed

pkg/geo/geomfn/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ go_test(
111111
"//pkg/geo/geopb",
112112
"//pkg/geo/geos",
113113
"//pkg/geo/geotest",
114+
"//pkg/testutils/floatcmp",
114115
"@com_github_cockroachdb_errors//:errors",
115116
"@com_github_stretchr_testify//assert",
116117
"@com_github_stretchr_testify//require",

pkg/geo/geomfn/angle_test.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,32 @@ package geomfn
88
import (
99
"fmt"
1010
"math"
11+
"runtime"
12+
"strconv"
1113
"testing"
1214

1315
"github.com/cockroachdb/cockroach/pkg/geo"
1416
"github.com/cockroachdb/cockroach/pkg/geo/geopb"
17+
"github.com/cockroachdb/cockroach/pkg/testutils/floatcmp"
1518
"github.com/stretchr/testify/require"
1619
)
1720

21+
func assertFloatsMatch(t *testing.T, expected, actual float64) {
22+
if runtime.GOARCH != "s390x" {
23+
require.Equal(t, expected, actual)
24+
return
25+
}
26+
// s390x system has architecture support for 'atan' function (which is used
27+
// in 'angleFromCoords') and produces slightly different result than math
28+
// operations we do to get the expected number. To go around this, we use
29+
// the custom float comparison that checks 15 significant decimal digits.
30+
exp := strconv.FormatFloat(expected, 'f', -1, 64)
31+
act := strconv.FormatFloat(actual, 'f', -1, 64)
32+
matched, err := floatcmp.FloatsMatch(exp, act)
33+
require.NoError(t, err)
34+
require.True(t, matched)
35+
}
36+
1837
func TestAngle(t *testing.T) {
1938
pf := func(f float64) *float64 {
2039
return &f
@@ -58,7 +77,7 @@ func TestAngle(t *testing.T) {
5877
angle, err := Angle(g1, g2, g3, g4)
5978
require.NoError(t, err)
6079
if tc.expected != nil && angle != nil {
61-
require.Equal(t, *tc.expected, *angle)
80+
assertFloatsMatch(t, *tc.expected, *angle)
6281
} else {
6382
require.Equal(t, tc.expected, angle)
6483
}
@@ -134,7 +153,7 @@ func TestAngleLineString(t *testing.T) {
134153
angle, err := AngleLineString(g1, g2)
135154
require.NoError(t, err)
136155
if tc.expected != nil && angle != nil {
137-
require.Equal(t, *tc.expected, *angle)
156+
assertFloatsMatch(t, *tc.expected, *angle)
138157
} else {
139158
require.Equal(t, tc.expected, angle)
140159
}

pkg/sql/logictest/testdata/logic_test/distsql_stats

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,13 +1672,29 @@ let $hist_id_1
16721672
SELECT histogram_id FROM [SHOW STATISTICS FOR TABLE geo_table]
16731673
WHERE statistics_name = 's' AND column_names = '{geog}'
16741674

1675+
# s390x produces slightly different inverted index key for the linestring (among
1676+
# other shapes) because it has architecture support for trigonometric functions
1677+
# (used by s2 library), so we have different expectations for s390x vs other
1678+
# systems. s390x is the only big endian system we support right now, so we abuse
1679+
# the corresponding option a bit.
1680+
skipif bigendian
1681+
16751682
query TIRI colnames,nosort
16761683
SHOW HISTOGRAM $hist_id_1
16771684
----
16781685
upper_bound range_rows distinct_range_rows equal_rows
16791686
'\x42fd1000000000000000000000000000000000bcc00000000000003ffbecde5da115a83ff661bdc396bcdc' 0 0 1
16801687
'\x42fd5000000000000000000000000000000000bcc00000000000003ffbecde5da115a83ff661bdc396bcdc' 0 0 1
16811688

1689+
skipif littleendian
1690+
1691+
query TIRI colnames,nosort
1692+
SHOW HISTOGRAM $hist_id_1
1693+
----
1694+
upper_bound range_rows distinct_range_rows equal_rows
1695+
'\x42fd1000000000000000000000000000000000bcc00000000000003ffbecde5da115a93ff661bdc396bcdc' 0 0 1
1696+
'\x42fd5000000000000000000000000000000000bcc00000000000003ffbecde5da115a93ff661bdc396bcdc' 0 0 1
1697+
16821698
statement ok
16831699
DROP INDEX geo_table@geog_idx_1;
16841700

@@ -1690,6 +1706,8 @@ let $hist_id_1
16901706
SELECT histogram_id FROM [SHOW STATISTICS FOR TABLE geo_table]
16911707
WHERE statistics_name = 's' AND column_names = '{geog}'
16921708

1709+
skipif bigendian
1710+
16931711
query TIRI colnames,nosort
16941712
SHOW HISTOGRAM $hist_id_1
16951713
----
@@ -1699,6 +1717,17 @@ upper_bound
16991717
'\x42fd4700000000000000000000000000000000bcc00000000000003ffbecde5da115a83ff661bdc396bcdc' 0 0 1
17001718
'\x42fd5ad4000000000000000000000000000000bcc00000000000003ffbecde5da115a83ff661bdc396bcdc' 0 0 1
17011719

1720+
skipif littleendian
1721+
1722+
query TIRI colnames,nosort
1723+
SHOW HISTOGRAM $hist_id_1
1724+
----
1725+
upper_bound range_rows distinct_range_rows equal_rows
1726+
'\x42fd1000000000000000000000000000000000bcc00000000000003ffbecde5da115a93ff661bdc396bcdc' 0 0 1
1727+
'\x42fd4500000000000000000000000000000000bcc00000000000003ffbecde5da115a93ff661bdc396bcdc' 0 0 1
1728+
'\x42fd4700000000000000000000000000000000bcc00000000000003ffbecde5da115a93ff661bdc396bcdc' 0 0 1
1729+
'\x42fd5ad4000000000000000000000000000000bcc00000000000003ffbecde5da115a93ff661bdc396bcdc' 0 0 1
1730+
17021731
# Stats for multi-column inverted indexes.
17031732
statement ok
17041733
CREATE TABLE multi_col (

pkg/sql/logictest/testdata/logic_test/geospatial

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4702,11 +4702,15 @@ Square overlapping left and right square Square (right)
47024702
Square overlapping left and right square Square overlapping left and right square true true true
47034703

47044704
# ST_Segmentize
4705+
#
4706+
# ST_Segmentize uses some trigonometric functions implicitly (via s2 library),
4707+
# which have architecture suppport on some systems like s390x, which can produce
4708+
# slightly different results, so we perform "rounding" via regexp replacement.
47054709
query TTT
47064710
SELECT
47074711
dsc,
47084712
ST_AsText(ST_Segmentize(geog, 100000)),
4709-
ST_AsText(ST_Segmentize(geog, 50000))
4713+
regexp_replace(ST_AsText(ST_Segmentize(geog, 50000)), '1.000028552944326', '1.000028552944327', 'g')
47104714
FROM geog_operators_test
47114715
ORDER BY dsc
47124716
----
@@ -4719,7 +4723,7 @@ NULL NULL
47194723
Nested Geometry Collection GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0))) GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
47204724
Point middle of Left Square POINT (-0.5 0.5) POINT (-0.5 0.5)
47214725
Point middle of Right Square POINT (0.5 0.5) POINT (0.5 0.5)
4722-
Square (left) POLYGON ((-1 0, -0.5 0, 0 0, 0 0.5, 0 1, -0.5 1.000038070652873, -1 1, -1 0.5, -1 0)) POLYGON ((-1 0, -0.75 0, -0.5 0, -0.25 0, 0 0, 0 0.25, 0 0.5, 0 0.75, 0 1, -0.249999998550193 1.000028552944327, -0.5 1.000038070652873, -0.750000001449807 1.000028552944326, -1 1, -1 0.75, -1 0.5, -1 0.25, -1 0))
4726+
Square (left) POLYGON ((-1 0, -0.5 0, 0 0, 0 0.5, 0 1, -0.5 1.000038070652873, -1 1, -1 0.5, -1 0)) POLYGON ((-1 0, -0.75 0, -0.5 0, -0.25 0, 0 0, 0 0.25, 0 0.5, 0 0.75, 0 1, -0.249999998550193 1.000028552944327, -0.5 1.000038070652873, -0.750000001449807 1.000028552944327, -1 1, -1 0.75, -1 0.5, -1 0.25, -1 0))
47234727
Square (right) POLYGON ((0 0, 0.5 0, 1 0, 1 0.5, 1 1, 0.5 1.000038070652873, 0 1, 0 0.5, 0 0)) POLYGON ((0 0, 0.25 0, 0.5 0, 0.75 0, 1 0, 1 0.25, 1 0.5, 1 0.75, 1 1, 0.750000001449807 1.000028552944327, 0.5 1.000038070652873, 0.249999998550193 1.000028552944327, 0 1, 0 0.75, 0 0.5, 0 0.25, 0 0))
47244728
Square overlapping left and right square POLYGON ((-0.1 0, 0.45 0, 1 0, 1 0.5, 1 1, 0.45 1.000046065796834, -0.1 1, -0.1 0.5, -0.1 0)) POLYGON ((-0.1 0, 0.175 0, 0.45 0, 0.725 0, 1 0, 1 0.25, 1 0.5, 1 0.75, 1 1, 0.725000001929716 1.000034549281259, 0.45 1.000046065796834, 0.174999998070284 1.000034549281259, -0.1 1, -0.1 0.75, -0.1 0.5, -0.1 0.25, -0.1 0))
47254729

@@ -5469,11 +5473,14 @@ POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)) POLYGON ((0 -0.1, 0 1, 1
54695473
POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0)) POLYGON ((0 -1, 0 0, 1 0, 1 -1, 0 -1))
54705474
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))
54715475

5476+
# ST_Rotate uses some trigonometric functions internally, which have
5477+
# architecture suppport on some systems like s390x, which can produce slightly
5478+
# different results, so we perform "rounding" via regexp replacement.
54725479
query TTT
54735480
SELECT
54745481
ST_AsText(a.geom) d,
54755482
ST_AsText(ST_Rotate(a.geom, pi())),
5476-
ST_AsText(ST_Rotate(a.geom, pi()/4))
5483+
regexp_replace(ST_AsText(ST_Rotate(a.geom, pi()/4)), 'POINT \(0.000000000000001 7.071067811865476\)', 'POINT (0 7.071067811865476)', 'g')
54775484
FROM geom_operators_test a
54785485
ORDER BY d ASC
54795486
----

pkg/sql/opt/exec/execbuilder/testdata/geospatial

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,75 @@ CPut /Table/106/1/1/0 -> /TUPLE/
3131
CPut /Table/106/1/2/0 -> /TUPLE/
3232

3333
query T kvtrace
34-
INSERT INTO c VALUES
35-
(1, 'POINT(1.0 1.0)', 'POINT(2.0 2.0)'),
36-
(2, 'LINESTRING(1.0 1.0, 2.0 2.0)', 'POINT(1.0 1.0)')
34+
INSERT INTO c VALUES (1, 'POINT(1.0 1.0)', 'POINT(2.0 2.0)')
3735
----
3836
Scan /Table/20/1/10{7-8}
3937
CPut /Table/107/1/1/0 -> /TUPLE/
4038
Put /Table/107/2/"B\xfd\x10\x01D\x15@\x80K\xd5\x01?\x91\xdfF\xa2R\x9d9?\x91\xdfF\xa2R\x9d9\x89\x88" -> /BYTES/
4139
Put /Table/107/3/"B\xfd\x10\x00\x00\x00\x00\x00\x00\x01\x01@\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\x89\x88" -> /BYTES/
40+
41+
# s390x produces slightly different inverted index key for the linestring (among
42+
# other shapes) because it has architecture support for trigonometric functions
43+
# (used by s2 library), so we have different expectations for s390x vs other
44+
# systems. s390x is the only big endian system we support right now, so we abuse
45+
# the corresponding option a bit.
46+
skipif bigendian
47+
48+
query T kvtrace
49+
INSERT INTO c VALUES (2, 'LINESTRING(1.0 1.0, 2.0 2.0)', 'POINT(1.0 1.0)')
50+
----
4251
CPut /Table/107/1/2/0 -> /TUPLE/
4352
Put /Table/107/2/"B\xfd\x10\x01P\x00\x00\x00\x00\x00\x00?\x91\xdfF\xa2R\x9d8?\x91\xdfF\xa2R\x9c\xb9?\xa1\xdfF\xa2R\x9d9?\xa1\xdfF\xa2R\x9dx\x8a\x88" -> /BYTES/
4453
Put /Table/107/2/"B\xfd\x10\x03\xff\xff\xfc\x00\x00\x00\x00?\x91\xdfF\xa2R\x9d8?\x91\xdfF\xa2R\x9c\xb9?\xa1\xdfF\xa2R\x9d9?\xa1\xdfF\xa2R\x9dx\x8a\x88" -> /BYTES/
4554
Put /Table/107/2/"B\xfd\x10\x05\x00\x00\x00\x00\x00\x00\x00?\x91\xdfF\xa2R\x9d8?\x91\xdfF\xa2R\x9c\xb9?\xa1\xdfF\xa2R\x9d9?\xa1\xdfF\xa2R\x9dx\x8a\x88" -> /BYTES/
4655
Put /Table/107/3/"B\xfd\x10\x00\x00\x00\x00\x00\x00\x01\x01?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00\x8a\x88" -> /BYTES/
4756

57+
skipif littleendian
58+
59+
query T kvtrace
60+
INSERT INTO c VALUES (2, 'LINESTRING(1.0 1.0, 2.0 2.0)', 'POINT(1.0 1.0)')
61+
----
62+
CPut /Table/107/1/2/0 -> /TUPLE/
63+
Put /Table/107/2/"B\xfd\x10\x01P\x00\x00\x00\x00\x00\x00?\x91\xdfF\xa2R\x9d8?\x91\xdfF\xa2R\x9c\xb8?\xa1\xdfF\xa2R\x9d9?\xa1\xdfF\xa2R\x9dx\x8a\x88" -> /BYTES/
64+
Put /Table/107/2/"B\xfd\x10\x03\xff\xff\xfc\x00\x00\x00\x00?\x91\xdfF\xa2R\x9d8?\x91\xdfF\xa2R\x9c\xb8?\xa1\xdfF\xa2R\x9d9?\xa1\xdfF\xa2R\x9dx\x8a\x88" -> /BYTES/
65+
Put /Table/107/2/"B\xfd\x10\x05\x00\x00\x00\x00\x00\x00\x00?\x91\xdfF\xa2R\x9d8?\x91\xdfF\xa2R\x9c\xb8?\xa1\xdfF\xa2R\x9d9?\xa1\xdfF\xa2R\x9dx\x8a\x88" -> /BYTES/
66+
Put /Table/107/3/"B\xfd\x10\x00\x00\x00\x00\x00\x00\x01\x01?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00\x8a\x88" -> /BYTES/
67+
4868
statement ok
4969
CREATE INVERTED INDEX geog_idx ON b(geog)
5070

5171
statement ok
5272
CREATE INVERTED INDEX geom_idx ON b(geom)
5373

5474
query T kvtrace
55-
INSERT INTO b VALUES
56-
(3, 'POINT(1.0 1.0)', 'POINT(2.0 2.0)'),
57-
(4, 'LINESTRING(1.0 1.0, 2.0 2.0)', 'POINT(1.0 1.0)')
75+
INSERT INTO b VALUES (3, 'POINT(1.0 1.0)', 'POINT(2.0 2.0)')
5876
----
5977
CPut /Table/106/1/3/0 -> /TUPLE/
6078
Put /Table/106/2/"B\xfd\x10\x01D\x15@\x80K\xd5\x01?\x91\xdfF\xa2R\x9d9?\x91\xdfF\xa2R\x9d9\x8b\x88" -> /BYTES/
6179
Put /Table/106/4/"B\xfd\x10\x00\x00\x00\x00\x00\x00\x01\x01@\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\x8b\x88" -> /BYTES/
80+
81+
skipif bigendian
82+
83+
query T kvtrace
84+
INSERT INTO b VALUES (4, 'LINESTRING(1.0 1.0, 2.0 2.0)', 'POINT(1.0 1.0)')
85+
----
6286
CPut /Table/106/1/4/0 -> /TUPLE/
6387
Put /Table/106/2/"B\xfd\x10\x01P\x00\x00\x00\x00\x00\x00?\x91\xdfF\xa2R\x9d8?\x91\xdfF\xa2R\x9c\xb9?\xa1\xdfF\xa2R\x9d9?\xa1\xdfF\xa2R\x9dx\x8c\x88" -> /BYTES/
6488
Put /Table/106/2/"B\xfd\x10\x03\xff\xff\xfc\x00\x00\x00\x00?\x91\xdfF\xa2R\x9d8?\x91\xdfF\xa2R\x9c\xb9?\xa1\xdfF\xa2R\x9d9?\xa1\xdfF\xa2R\x9dx\x8c\x88" -> /BYTES/
6589
Put /Table/106/2/"B\xfd\x10\x05\x00\x00\x00\x00\x00\x00\x00?\x91\xdfF\xa2R\x9d8?\x91\xdfF\xa2R\x9c\xb9?\xa1\xdfF\xa2R\x9d9?\xa1\xdfF\xa2R\x9dx\x8c\x88" -> /BYTES/
6690
Put /Table/106/4/"B\xfd\x10\x00\x00\x00\x00\x00\x00\x01\x01?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00\x8c\x88" -> /BYTES/
6791

92+
skipif littleendian
93+
94+
query T kvtrace
95+
INSERT INTO b VALUES (4, 'LINESTRING(1.0 1.0, 2.0 2.0)', 'POINT(1.0 1.0)')
96+
----
97+
CPut /Table/106/1/4/0 -> /TUPLE/
98+
Put /Table/106/2/"B\xfd\x10\x01P\x00\x00\x00\x00\x00\x00?\x91\xdfF\xa2R\x9d8?\x91\xdfF\xa2R\x9c\xb8?\xa1\xdfF\xa2R\x9d9?\xa1\xdfF\xa2R\x9dx\x8c\x88" -> /BYTES/
99+
Put /Table/106/2/"B\xfd\x10\x03\xff\xff\xfc\x00\x00\x00\x00?\x91\xdfF\xa2R\x9d8?\x91\xdfF\xa2R\x9c\xb8?\xa1\xdfF\xa2R\x9d9?\xa1\xdfF\xa2R\x9dx\x8c\x88" -> /BYTES/
100+
Put /Table/106/2/"B\xfd\x10\x05\x00\x00\x00\x00\x00\x00\x00?\x91\xdfF\xa2R\x9d8?\x91\xdfF\xa2R\x9c\xb8?\xa1\xdfF\xa2R\x9d9?\xa1\xdfF\xa2R\x9dx\x8c\x88" -> /BYTES/
101+
Put /Table/106/4/"B\xfd\x10\x00\x00\x00\x00\x00\x00\x01\x01?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00\x8c\x88" -> /BYTES/
102+
68103
statement ok
69104
CREATE TABLE ltable(
70105
k int primary key,

0 commit comments

Comments
 (0)