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

colexecbase: add all casts of native types to strings #85681

Merged
merged 2 commits into from
Aug 8, 2022
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
8,214 changes: 6,184 additions & 2,030 deletions pkg/sql/colexec/colexecbase/cast.eg.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/sql/colexec/colexecbase/cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestRandomizedCast(t *testing.T) {
}
}
}
const numTypePairs = 5
var numTypePairs = rng.Intn(10) + 1
numRows := 1 + rng.Intn(coldata.BatchSize()) + rng.Intn(3)*coldata.BatchSize()
log.Infof(ctx, "num rows = %d", numRows)
for run := 0; run < numTypePairs; run++ {
Expand Down
18 changes: 11 additions & 7 deletions pkg/sql/colexec/colexecbase/cast_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package colexecbase

import (
"bytes"
"context"
"fmt"
"math"
Expand Down Expand Up @@ -81,7 +82,7 @@ const _TYPE_WIDTH = 0
// "castOp" template in the scope of this value's "callsite".
const _GENERATE_CAST_OP = 0

func _CAST(to, from, evalCtx, toType interface{}) {
func _CAST(to, from, evalCtx, toType, buf interface{}) {
colexecerror.InternalError(errors.AssertionFailedf(""))
}

Expand Down Expand Up @@ -235,6 +236,7 @@ type castOpBase struct {
colIdx int
outputIdx int
evalCtx *eval.Context
buf bytes.Buffer
}

func (c *castOpBase) Reset(ctx context.Context) {
Expand Down Expand Up @@ -448,15 +450,15 @@ func (c *cast_NAMEOp) Next() coldata.Batch {
if inputVec.MaybeHasNulls() {
outputNulls.Copy(inputNulls)
if sel != nil {
castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, true, true)
castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, &c.buf, true, true)
} else {
castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, true, false)
castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, &c.buf, true, false)
}
} else {
if sel != nil {
castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, false, true)
castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, &c.buf, false, true)
} else {
castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, false, false)
castTuples(inputCol, inputNulls, outputCol, outputNulls, toType, n, sel, c.evalCtx, &c.buf, false, false)
}
}
},
Expand Down Expand Up @@ -516,11 +518,13 @@ func castTuples(
n int,
sel []int,
evalCtx *eval.Context,
buf *bytes.Buffer,
hasNulls bool,
hasSel bool,
) {
// Silence unused warning.
// Silence unused warnings.
_ = evalCtx
_ = buf
if !hasSel {
// {{if $fromInfo.Sliceable}}
_ = inputCol.Get(n - 1)
Expand All @@ -546,7 +550,7 @@ func castTuples(
}
v := inputCol.Get(tupleIdx)
var r _TO_GO_TYPE
_CAST(r, v, evalCtx, toType)
_CAST(r, v, evalCtx, toType, buf)
if !hasSel {
// {{if .Sliceable}}
//gcassert:bce
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/colexec/execgen/cmd/execgen/avg_agg_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func genAvgAgg(inputFileContents string, wr io.Writer) error {
// canonical representatives, so we can operate with their type family
// directly.
for _, inputTypeFamily := range []types.Family{types.IntFamily, types.DecimalFamily, types.FloatFamily, types.IntervalFamily} {
tmplInfo := avgAggTypeTmplInfo{TypeFamily: toString(inputTypeFamily)}
tmplInfo := avgAggTypeTmplInfo{TypeFamily: familyToString(inputTypeFamily)}
for _, inputTypeWidth := range supportedWidthsByCanonicalTypeFamily[inputTypeFamily] {
// Note that we don't use execinfrapb.GetAggregateInfo because we don't
// want to bring in a dependency on that package to reduce the burden
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/colexec/execgen/cmd/execgen/cast_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func genCastOperators(inputFileContents string, wr io.Writer) error {
)
s := r.Replace(inputFileContents)

castRe := makeFunctionRegex("_CAST", 4)
s = castRe.ReplaceAllString(s, makeTemplateFunctionCall("Cast", 4))
castRe := makeFunctionRegex("_CAST", 5)
s = castRe.ReplaceAllString(s, makeTemplateFunctionCall("Cast", 5))

tmpl, err := template.New("cast").Funcs(template.FuncMap{"buildDict": buildDict}).Parse(s)
if err != nil {
Expand Down
Loading