Skip to content

Commit

Permalink
coldataext: propagate evalCtx directly for casts
Browse files Browse the repository at this point in the history
This commit removes the reliance on propagating `datumVec` objects to
supply the cast function with an eval context. All casts in the datum
land have been refactored to use `tree.PerformCast` for simplicity.

Note that the eval context is not removed from the `datumVec` because it
is used by `CompareDatum` method which is a lot more common (and, thus,
would require more plumbing to get rid off).

Release note: None
  • Loading branch information
yuzefovich committed Jul 30, 2021
1 parent fe1fb73 commit 23f1497
Show file tree
Hide file tree
Showing 13 changed files with 810 additions and 123 deletions.
12 changes: 0 additions & 12 deletions pkg/col/coldataext/datum_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ func (d *Datum) CompareDatum(dVec, other interface{}) int {
return d.Datum.Compare(dVec.(*datumVec).evalCtx, maybeUnwrapDatum(other))
}

// Cast returns the result of casting d to the type toType. dVec is the
// datumVec that stores d and is used to supply the eval context.
func (d *Datum) Cast(dVec interface{}, toType *types.T) (tree.Datum, error) {
return PerformCast(dVec, d.Datum, toType)
}

// PerformCast returns the result of casting d to the type toType. dVec is a
// datumVec that is used to supply the eval context.
func PerformCast(dVec interface{}, d tree.Datum, toType *types.T) (tree.Datum, error) {
return tree.PerformCast(dVec.(*datumVec).evalCtx, d, toType)
}

// Hash returns the hash of the datum as a byte slice.
func (d *Datum) Hash(da *rowenc.DatumAlloc) []byte {
ed := rowenc.EncDatum{Datum: maybeUnwrapDatum(d)}
Expand Down
15 changes: 8 additions & 7 deletions pkg/sql/colexec/colbuilder/execplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ func NewColOperator(
args.DiskQueueCfg, args.FDSemaphore,
joinType, inputs[0].Root, inputs[1].Root, leftTypes, rightTypes,
core.MergeJoiner.LeftOrdering.Columns, core.MergeJoiner.RightOrdering.Columns,
diskAccount,
diskAccount, evalCtx,
)
if err != nil {
return r, err
Expand Down Expand Up @@ -1196,7 +1196,7 @@ func NewColOperator(
// We must cast to the expected argument type.
castIdx := len(typs)
input, err = colexecbase.GetCastOperator(
streamingAllocator, input, int(idx), castIdx, typs[idx], expectedType,
streamingAllocator, input, int(idx), castIdx, typs[idx], expectedType, evalCtx,
)
if err != nil {
colexecerror.InternalError(errors.AssertionFailedf(
Expand Down Expand Up @@ -1469,7 +1469,7 @@ func NewColOperator(
if !actual.Identical(expected) {
castedIdx := len(typesWithCasts)
r.Root, err = colexecbase.GetCastOperator(
streamingAllocator, r.Root, i, castedIdx, actual, expected,
streamingAllocator, r.Root, i, castedIdx, actual, expected, evalCtx,
)
if err != nil {
return r, errors.AssertionFailedf("unexpectedly couldn't plan a cast although IsCastSupported returned true: %v", err)
Expand Down Expand Up @@ -1953,9 +1953,10 @@ func planCastOperator(
fromType *types.T,
toType *types.T,
factory coldata.ColumnFactory,
evalCtx *tree.EvalContext,
) (op colexecop.Operator, resultIdx int, typs []*types.T, err error) {
outputIdx := len(columnTypes)
op, err = colexecbase.GetCastOperator(colmem.NewAllocator(ctx, acc, factory), input, inputIdx, outputIdx, fromType, toType)
op, err = colexecbase.GetCastOperator(colmem.NewAllocator(ctx, acc, factory), input, inputIdx, outputIdx, fromType, toType, evalCtx)
typs = appendOneType(columnTypes, toType)
return op, outputIdx, typs, err
}
Expand Down Expand Up @@ -2017,7 +2018,7 @@ func planProjectionOperators(
if err != nil {
return nil, 0, nil, err
}
op, resultIdx, typs, err = planCastOperator(ctx, acc, typs, op, resultIdx, expr.ResolvedType(), t.ResolvedType(), factory)
op, resultIdx, typs, err = planCastOperator(ctx, acc, typs, op, resultIdx, expr.ResolvedType(), t.ResolvedType(), factory, evalCtx)
return op, resultIdx, typs, err
case *tree.FuncExpr:
var inputCols []int
Expand Down Expand Up @@ -2158,7 +2159,7 @@ func planProjectionOperators(
// is given). In such case, we need to plan a cast.
fromType, toType := typs[thenIdxs[i]], typs[caseOutputIdx]
caseOps[i], thenIdxs[i], typs, err = planCastOperator(
ctx, acc, typs, caseOps[i], thenIdxs[i], fromType, toType, factory,
ctx, acc, typs, caseOps[i], thenIdxs[i], fromType, toType, factory, evalCtx,
)
if err != nil {
return nil, resultIdx, typs, err
Expand All @@ -2184,7 +2185,7 @@ func planProjectionOperators(
elseIdx := thenIdxs[len(t.Whens)]
fromType, toType := typs[elseIdx], typs[caseOutputIdx]
elseOp, thenIdxs[len(t.Whens)], typs, err = planCastOperator(
ctx, acc, typs, elseOp, elseIdx, fromType, toType, factory,
ctx, acc, typs, elseOp, elseIdx, fromType, toType, factory, evalCtx,
)
if err != nil {
return nil, resultIdx, typs, err
Expand Down
Loading

0 comments on commit 23f1497

Please sign in to comment.