github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/colexec/const_test.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package colexec 12 13 import ( 14 "context" 15 "testing" 16 17 "github.com/cockroachdb/cockroach/pkg/settings/cluster" 18 "github.com/cockroachdb/cockroach/pkg/sql/colexecbase" 19 "github.com/cockroachdb/cockroach/pkg/sql/execinfra" 20 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 21 "github.com/cockroachdb/cockroach/pkg/sql/types" 22 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 23 ) 24 25 func TestConst(t *testing.T) { 26 defer leaktest.AfterTest(t)() 27 ctx := context.Background() 28 st := cluster.MakeTestingClusterSettings() 29 evalCtx := tree.MakeTestingEvalContext(st) 30 defer evalCtx.Stop(ctx) 31 flowCtx := &execinfra.FlowCtx{ 32 EvalCtx: &evalCtx, 33 Cfg: &execinfra.ServerConfig{ 34 Settings: st, 35 }, 36 } 37 tcs := []struct { 38 tuples tuples 39 expected tuples 40 }{ 41 { 42 tuples: tuples{{1}, {1}}, 43 expected: tuples{{1, 9}, {1, 9}}, 44 }, 45 { 46 tuples: tuples{}, 47 expected: tuples{}, 48 }, 49 } 50 for _, tc := range tcs { 51 runTestsWithTyps(t, []tuples{tc.tuples}, [][]*types.T{{types.Int}}, tc.expected, orderedVerifier, 52 func(input []colexecbase.Operator) (colexecbase.Operator, error) { 53 return createTestProjectingOperator( 54 ctx, flowCtx, input[0], []*types.T{types.Int}, 55 "9" /* projectingExpr */, false, /* canFallbackToRowexec */ 56 ) 57 }) 58 } 59 } 60 61 func TestConstNull(t *testing.T) { 62 defer leaktest.AfterTest(t)() 63 ctx := context.Background() 64 st := cluster.MakeTestingClusterSettings() 65 evalCtx := tree.MakeTestingEvalContext(st) 66 defer evalCtx.Stop(ctx) 67 flowCtx := &execinfra.FlowCtx{ 68 EvalCtx: &evalCtx, 69 Cfg: &execinfra.ServerConfig{ 70 Settings: st, 71 }, 72 } 73 tcs := []struct { 74 tuples tuples 75 expected tuples 76 }{ 77 { 78 tuples: tuples{{1}, {1}}, 79 expected: tuples{{1, nil}, {1, nil}}, 80 }, 81 { 82 tuples: tuples{}, 83 expected: tuples{}, 84 }, 85 } 86 for _, tc := range tcs { 87 runTestsWithTyps(t, []tuples{tc.tuples}, [][]*types.T{{types.Int}}, tc.expected, orderedVerifier, 88 func(input []colexecbase.Operator) (colexecbase.Operator, error) { 89 return createTestProjectingOperator( 90 ctx, flowCtx, input[0], []*types.T{types.Int}, 91 "NULL::INT" /* projectingExpr */, false, /* canFallbackToRowexec */ 92 ) 93 }) 94 } 95 }