github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/col/coldataext/extended_column_factory.go (about) 1 // Copyright 2020 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 coldataext 12 13 import ( 14 "github.com/cockroachdb/cockroach/pkg/col/coldata" 15 "github.com/cockroachdb/cockroach/pkg/col/typeconv" 16 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 17 "github.com/cockroachdb/cockroach/pkg/sql/types" 18 ) 19 20 // extendedColumnFactory stores an evalCtx which can be used to construct 21 // datumVec later. This is to prevent plumbing evalCtx to all vectorized 22 // operators as well as avoiding introducing dependency from coldata on tree 23 // package. 24 type extendedColumnFactory struct { 25 evalCtx *tree.EvalContext 26 } 27 28 var _ coldata.ColumnFactory = &extendedColumnFactory{} 29 30 // NewExtendedColumnFactory returns an extendedColumnFactory instance. 31 func NewExtendedColumnFactory(evalCtx *tree.EvalContext) coldata.ColumnFactory { 32 return &extendedColumnFactory{evalCtx: evalCtx} 33 } 34 35 func (cf *extendedColumnFactory) MakeColumn(t *types.T, n int) coldata.Column { 36 if typeconv.TypeFamilyToCanonicalTypeFamily(t.Family()) == typeconv.DatumVecCanonicalTypeFamily { 37 return newDatumVec(t, n, cf.evalCtx) 38 } 39 return coldata.StandardColumnFactory.MakeColumn(t, n) 40 }