Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

colexec: add default comparison operator #52313

Merged
merged 2 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,9 @@ EXECGEN_TARGETS = \
pkg/sql/colexec/and_or_projection.eg.go \
pkg/sql/colexec/cast.eg.go \
pkg/sql/colexec/const.eg.go \
pkg/sql/colexec/default_cmp_expr.eg.go \
pkg/sql/colexec/default_cmp_proj_ops.eg.go \
pkg/sql/colexec/default_cmp_sel_ops.eg.go \
pkg/sql/colexec/distinct.eg.go \
pkg/sql/colexec/hashjoiner.eg.go \
pkg/sql/colexec/hashtable_distinct.eg.go \
Expand All @@ -872,6 +875,7 @@ EXECGEN_TARGETS = \
pkg/sql/colexec/hash_sum_agg.eg.go \
pkg/sql/colexec/hash_sum_int_agg.eg.go \
pkg/sql/colexec/hash_utils.eg.go \
pkg/sql/colexec/is_null_ops.eg.go \
pkg/sql/colexec/like_ops.eg.go \
pkg/sql/colexec/mergejoinbase.eg.go \
pkg/sql/colexec/mergejoiner_exceptall.eg.go \
Expand Down
4 changes: 2 additions & 2 deletions pkg/col/coldataext/datum_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func newDatumVec(t *types.T, n int, evalCtx *tree.EvalContext) coldata.DatumVec
// BinFn evaluates the provided binary function between the receiver and other.
// other can either be nil, tree.Datum, or *Datum.
func (d *Datum) BinFn(
binFn *tree.BinOp, evalCtx *tree.EvalContext, other interface{},
binFn tree.TwoArgFn, evalCtx *tree.EvalContext, other interface{},
) (tree.Datum, error) {
return binFn.Fn(evalCtx, d.Datum, maybeUnwrapDatum(other))
return binFn(evalCtx, d.Datum, maybeUnwrapDatum(other))
}

// CompareDatum returns the comparison between d and other. The other is
Expand Down
31 changes: 16 additions & 15 deletions pkg/sql/colexec/aggregators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
"github.com/cockroachdb/cockroach/pkg/util/timeofday"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -531,24 +532,24 @@ func TestAggregatorMultiFunc(t *testing.T) {
execinfrapb.AggregatorSpec_SUM_INT,
},
input: tuples{
{`{"id": null}`, -1},
{`{"id": 0, "data": "s1"}`, 1},
{`{"id": 0, "data": "s1"}`, 2},
{`{"id": 1, "data": "s2"}`, 10},
{`{"id": 1, "data": "s2"}`, 11},
{`{"id": 2, "data": "s3"}`, 100},
{`{"id": 2, "data": "s3"}`, 101},
{`{"id": 2, "data": "s4"}`, 102},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 0), -1},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 1), 1},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 1), 2},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 2), 10},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 2), 11},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 3), 100},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 3), 101},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 4), 102},
},
expected: tuples{
{`{"id": null}`, -1},
{`{"id": 0, "data": "s1"}`, 3},
{`{"id": 1, "data": "s2"}`, 21},
{`{"id": 2, "data": "s3"}`, 201},
{`{"id": 2, "data": "s4"}`, 102},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 0), -1},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 1), 3},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 2), 21},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 3), 201},
{tree.NewDTimeTZFromOffset(timeofday.FromInt(0), 4), 102},
},
typs: []*types.T{types.Jsonb, types.Int},
name: "GroupOnJsonColumns",
typs: []*types.T{types.TimeTZ, types.Int},
name: "GroupOnTimeTZColumns",
groupCols: []uint32{0},
aggCols: [][]uint32{
{0}, {1},
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/colexec/builtin_funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ func BenchmarkBuiltinFunctions(b *testing.B) {
// and the specialized operator.
func BenchmarkCompareSpecializedOperators(b *testing.B) {
ctx := context.Background()
tctx := tree.NewTestingEvalContext(cluster.MakeTestingClusterSettings())
evalCtx := tree.NewTestingEvalContext(cluster.MakeTestingClusterSettings())
defer evalCtx.Stop(ctx)

typs := []*types.T{types.String, types.Int, types.Int}
batch := testAllocator.NewMemBatch(typs)
Expand Down Expand Up @@ -189,7 +190,7 @@ func BenchmarkCompareSpecializedOperators(b *testing.B) {
defaultOp := &defaultBuiltinFuncOperator{
OneInputNode: NewOneInputNode(source),
allocator: testAllocator,
evalCtx: tctx,
evalCtx: evalCtx,
funcExpr: typedExpr.(*tree.FuncExpr),
outputIdx: outputIdx,
columnTypes: typs,
Expand Down
Loading