From 7bd73cb4343c08fddfab85269b148471f73f1aa3 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Tue, 9 Jan 2024 18:19:40 +0000 Subject: [PATCH] distsql: improve columnar operator test harness for decimals We recently merged a change to add decimals with different numbers of trailing zeroes in the "interesting datums" set, and it made some existing tests fail because they used direct string comparison for equality. This commit adjusts the test harness to be smarter for decimals. Release note: None --- pkg/sql/distsql/columnar_utils_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkg/sql/distsql/columnar_utils_test.go b/pkg/sql/distsql/columnar_utils_test.go index 433192195ea6..aa6a2b20923c 100644 --- a/pkg/sql/distsql/columnar_utils_test.go +++ b/pkg/sql/distsql/columnar_utils_test.go @@ -35,6 +35,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/rowenc" "github.com/cockroachdb/cockroach/pkg/sql/rowexec" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" + "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/storage" "github.com/cockroachdb/cockroach/pkg/util/randutil" @@ -271,6 +272,26 @@ func verifyColOperator(t *testing.T, args verifyColOperatorArgs) error { return false, err } return math.Abs(expFloat-actualFloat) < floatPrecision, nil + case types.DecimalFamily: + // Decimals might have a different number of trailing zeroes, so + // they too require special handling. + + // We first try direct string matching. If that succeeds, then + // great! + if expected == actual { + return true, nil + } + // Now parse both strings as decimals and use decimal-specific + // comparison. + expDecimal, err := tree.ParseDDecimal(expected) + if err != nil { + return false, err + } + actualDecimal, err := tree.ParseDDecimal(actual) + if err != nil { + return false, err + } + return tree.CompareDecimals(&expDecimal.Decimal, &actualDecimal.Decimal) == 0, nil default: return expected == actual, nil }