Skip to content

Commit

Permalink
distsql: improve columnar operator test harness for decimals
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yuzefovich committed Jan 9, 2024
1 parent 417c06b commit 7bd73cb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/sql/distsql/columnar_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 7bd73cb

Please sign in to comment.