Skip to content

Commit c616af2

Browse files
authored
Merge pull request #147229 from yuzefovich/blathers/backport-release-25.2-147051
release-25.2: roachtest: fix unsortedMatricesDiffWithFloatComp helper for numerics
2 parents 5f55ce5 + 99a9d61 commit c616af2

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

pkg/cmd/roachtest/tests/query_comparison_util.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,18 @@ func isFloatArray(colType string) bool {
620620
}
621621
}
622622

623+
func isDecimal(colType string) bool {
624+
switch colType {
625+
case "DECIMAL", "NUMERIC":
626+
return true
627+
default:
628+
return false
629+
}
630+
}
631+
623632
func isDecimalArray(colType string) bool {
624633
switch colType {
625-
case "[]DECIMAL", "_DECIMAL":
634+
case "[]DECIMAL", "_DECIMAL", "[]NUMERIC", "_NUMERIC":
626635
return true
627636
default:
628637
return false
@@ -633,7 +642,7 @@ func needApproximateMatch(colType string) bool {
633642
// On s390x, check that values for both float and decimal coltypes are
634643
// approximately equal to take into account platform differences in floating
635644
// point calculations. On other architectures, check float values only.
636-
return (runtime.GOARCH == "s390x" && (colType == "DECIMAL" || isDecimalArray(colType))) ||
645+
return (runtime.GOARCH == "s390x" && (isDecimal(colType) || isDecimalArray(colType))) ||
637646
colType == "FLOAT4" || colType == "FLOAT8" || isFloatArray(colType)
638647
}
639648

@@ -714,7 +723,7 @@ func unsortedMatricesDiffWithFloatComp(
714723
}
715724
var needCustomMatch bool
716725
for _, colType := range colTypes {
717-
if needApproximateMatch(colType) || colType == "DECIMAL" || isDecimalArray(colType) {
726+
if needApproximateMatch(colType) || isDecimal(colType) || isDecimalArray(colType) {
718727
needCustomMatch = true
719728
break
720729
}
@@ -748,7 +757,7 @@ func unsortedMatricesDiffWithFloatComp(
748757
}
749758
} else {
750759
switch {
751-
case colType == "DECIMAL":
760+
case isDecimal(colType):
752761
// For decimals, remove any trailing zeroes.
753762
row1[j] = trimDecimalTrailingZeroes(row1[j])
754763
row2[j] = trimDecimalTrailingZeroes(row2[j])

pkg/cmd/roachtest/tests/query_comparison_util_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,30 @@ func TestUnsortedMatricesDiff(t *testing.T) {
156156
exactMatch: false,
157157
approxMatch: true,
158158
},
159+
{
160+
name: "decimals as numerics with trailing zeroes",
161+
colTypes: []string{"NUMERIC"},
162+
t1: [][]string{{"1.20"}, {"1.000"}},
163+
t2: [][]string{{"1.200"}, {"1"}},
164+
exactMatch: false,
165+
approxMatch: true,
166+
},
167+
{
168+
name: "decimals as numerics with non-trailing zeroes",
169+
colTypes: []string{"NUMERIC"},
170+
t1: [][]string{{"10"}, {"1.000"}},
171+
t2: [][]string{{"1.0"}, {"1000"}},
172+
exactMatch: false,
173+
approxMatch: false,
174+
},
175+
{
176+
name: "decimals as numerics with trailing zeroes in array",
177+
colTypes: []string{"_NUMERIC"}, // this is how []DECIMAL can be named in lib/pq driver
178+
t1: [][]string{{"1.0,1.000"}, {"3.0,4.000"}},
179+
t2: [][]string{{"1.00,1"}, {"3.00,4"}},
180+
exactMatch: false,
181+
approxMatch: true,
182+
},
159183
}
160184
for _, tc := range tcs {
161185
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)