github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/colexec/rowstovec_tmpl.go (about) 1 // Copyright 2018 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 // {{/* 12 // +build execgen_template 13 // 14 // This file is the execgen template for rowstovec.eg.go. It's formatted in a 15 // special way, so it's both valid Go and a valid text/template input. This 16 // permits editing this file with editor support. 17 // 18 // */}} 19 20 package colexec 21 22 import ( 23 "fmt" 24 25 "github.com/cockroachdb/cockroach/pkg/col/coldata" 26 "github.com/cockroachdb/cockroach/pkg/col/typeconv" 27 "github.com/cockroachdb/cockroach/pkg/sql/colexec/execgen" 28 "github.com/cockroachdb/cockroach/pkg/sql/colexecbase/colexecerror" 29 "github.com/cockroachdb/cockroach/pkg/sql/colmem" 30 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 31 "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" 32 "github.com/cockroachdb/cockroach/pkg/sql/types" 33 ) 34 35 // Remove unused warning. 36 var _ = execgen.UNSAFEGET 37 38 // {{/* 39 40 // _CANONICAL_TYPE_FAMILY is the template variable. 41 const _CANONICAL_TYPE_FAMILY = types.UnknownFamily 42 43 // _TYPE_WIDTH is the template variable. 44 const _TYPE_WIDTH = 0 45 46 type _GOTYPE interface{} 47 48 func _ROWS_TO_COL_VEC( 49 rows sqlbase.EncDatumRows, vec coldata.Vec, columnIdx int, alloc *sqlbase.DatumAlloc, 50 ) error { // */}} 51 // {{define "rowsToColVec" -}} 52 col := vec.TemplateType() 53 datumToPhysicalFn := getDatumToPhysicalFn(t) 54 var v interface{} 55 for i := range rows { 56 row := rows[i] 57 if row[columnIdx].Datum == nil { 58 if err = row[columnIdx].EnsureDecoded(t, alloc); err != nil { 59 return 60 } 61 } 62 datum := row[columnIdx].Datum 63 if datum == tree.DNull { 64 vec.Nulls().SetNull(i) 65 } else { 66 v, err = datumToPhysicalFn(datum) 67 if err != nil { 68 return 69 } 70 71 castV := v.(_GOTYPE) 72 execgen.SET(col, i, castV) 73 } 74 } 75 // {{end}} 76 // {{/* 77 } 78 79 // */}} 80 81 // EncDatumRowsToColVec converts one column from EncDatumRows to a column 82 // vector. columnIdx is the 0-based index of the column in the EncDatumRows. 83 func EncDatumRowsToColVec( 84 allocator *colmem.Allocator, 85 rows sqlbase.EncDatumRows, 86 vec coldata.Vec, 87 columnIdx int, 88 t *types.T, 89 alloc *sqlbase.DatumAlloc, 90 ) error { 91 var err error 92 allocator.PerformOperation( 93 []coldata.Vec{vec}, 94 func() { 95 switch typeconv.TypeFamilyToCanonicalTypeFamily(t.Family()) { 96 // {{range .}} 97 case _CANONICAL_TYPE_FAMILY: 98 switch t.Width() { 99 // {{range .WidthOverloads}} 100 case _TYPE_WIDTH: 101 _ROWS_TO_COL_VEC(rows, vec, columnIdx, t, alloc) 102 // {{end}} 103 } 104 // {{end}} 105 default: 106 colexecerror.InternalError(fmt.Sprintf("unsupported type %s", t)) 107 } 108 }, 109 ) 110 return err 111 }