Skip to content

Commit

Permalink
sql: rename NullableArgs to CalledOnNullInput
Browse files Browse the repository at this point in the history
Previously, the `Overload.NullableArgs` boolean indicated whether or not
a function was evaluated in the presence of `NULL` inputs. This name was
confusing because it did not describe the behavior of the function.
Arguments to all functions can be `NULL` (i.e., "nullable") so the
difference between `NullableArgs` being `true` and `false` was unclear
without reading the detailed description of the field.

This commit renames the field, and all related variables throughout the
codebase, to `CalledOnNullInput`, making it clear that `true` indicates
that the function is called if any inputs are `NULL`, and `false`
indicates that the function is not called if any inputs are `NULL`. This
name also maps more closely to SQL syntax such as
`CREATE FUNCTION ... CALLED ON NULL INPUT ...`.

Release note: None
  • Loading branch information
mgartner committed Aug 6, 2022
1 parent 7d06d8d commit 31ffb42
Show file tree
Hide file tree
Showing 38 changed files with 2,535 additions and 2,513 deletions.
7 changes: 5 additions & 2 deletions pkg/sql/catalog/funcdesc/func_desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func (desc *immutable) ToOverload() (ret *tree.Overload, err error) {
if err != nil {
return nil, err
}
ret.NullableArgs, err = desc.getOverloadNullableArgs()
ret.CalledOnNullInput, err = desc.calledOnNullInput()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -517,7 +517,10 @@ func (desc *immutable) getOverloadVolatility() (volatility.V, error) {
return ret, nil
}

func (desc *immutable) getOverloadNullableArgs() (bool, error) {
// calledOnNullInput returns true if the function should be called when any of
// its input arguments are NULL. See Overload.CalledOnNullInput for more
// details.
func (desc *immutable) calledOnNullInput() (bool, error) {
switch desc.NullInputBehavior {
case catpb.Function_CALLED_ON_NULL_INPUT:
return true, nil
Expand Down
14 changes: 7 additions & 7 deletions pkg/sql/catalog/funcdesc/func_desc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func TestToOverload(t *testing.T) {
},
},
{
// Test NullableArgs matters.
// Test CalledOnNullInput matters.
desc: descpb.FunctionDescriptor{
ID: 1,
Args: []descpb.FunctionDescriptor_Argument{{Name: "arg1", Type: types.Int}},
Expand All @@ -559,12 +559,12 @@ func TestToOverload(t *testing.T) {
Types: tree.ArgTypes{
{Name: "arg1", Typ: types.Int},
},
ReturnType: tree.FixedReturnType(types.Int),
ReturnSet: true,
Volatility: volatility.Leakproof,
Body: "ANY QUERIES",
IsUDF: true,
NullableArgs: true,
ReturnType: tree.FixedReturnType(types.Int),
ReturnSet: true,
Volatility: volatility.Leakproof,
Body: "ANY QUERIES",
IsUDF: true,
CalledOnNullInput: true,
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/colexec/builtin_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (b *defaultBuiltinFuncOperator) Next() coldata.Batch {
err error
)
// Some functions cannot handle null arguments.
if hasNulls && !b.funcExpr.ResolvedOverload().NullableArgs {
if hasNulls && !b.funcExpr.ResolvedOverload().CalledOnNullInput {
res = tree.DNull
} else {
res, err = b.funcExpr.ResolvedOverload().
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/colexec/colbuilder/execplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,7 @@ func planProjectionOperators(
}
return planProjectionExpr(
ctx, evalCtx, t.Operator, t.ResolvedType(), leftExpr, rightExpr,
columnTypes, input, acc, factory, t.Op.EvalOp, nil /* cmpExpr */, releasables, t.Op.NullableArgs,
columnTypes, input, acc, factory, t.Op.EvalOp, nil /* cmpExpr */, releasables, t.Op.CalledOnNullInput,
)
case *tree.CaseExpr:
allocator := colmem.NewAllocator(ctx, acc, factory)
Expand Down Expand Up @@ -2191,7 +2191,7 @@ func planProjectionOperators(
case *tree.ComparisonExpr:
return planProjectionExpr(
ctx, evalCtx, t.Operator, t.ResolvedType(), t.TypedLeft(), t.TypedRight(),
columnTypes, input, acc, factory, nil /* binFn */, t, releasables, t.Op.NullableArgs,
columnTypes, input, acc, factory, nil /* binFn */, t, releasables, t.Op.CalledOnNullInput,
)
case tree.Datum:
op, err = projectDatum(t)
Expand Down Expand Up @@ -2358,7 +2358,7 @@ func planProjectionExpr(
binOp tree.BinaryEvalOp,
cmpExpr *tree.ComparisonExpr,
releasables *[]execreleasable.Releasable,
nullableArgs bool,
calledOnNullInput bool,
) (op colexecop.Operator, resultIdx int, typs []*types.T, err error) {
if err := checkSupportedProjectionExpr(left, right); err != nil {
return nil, resultIdx, typs, err
Expand Down Expand Up @@ -2395,7 +2395,7 @@ func planProjectionExpr(
// appended to the input batch.
op, err = colexecprojconst.GetProjectionLConstOperator(
allocator, typs, left.ResolvedType(), outputType, projOp, input,
rightIdx, lConstArg, resultIdx, evalCtx, binOp, cmpExpr, nullableArgs,
rightIdx, lConstArg, resultIdx, evalCtx, binOp, cmpExpr, calledOnNullInput,
)
} else {
var leftIdx int
Expand Down Expand Up @@ -2472,7 +2472,7 @@ func planProjectionExpr(
// all other projection operators.
op, err = colexecprojconst.GetProjectionRConstOperator(
allocator, typs, right.ResolvedType(), outputType, projOp,
input, leftIdx, rConstArg, resultIdx, evalCtx, binOp, cmpExpr, nullableArgs,
input, leftIdx, rConstArg, resultIdx, evalCtx, binOp, cmpExpr, calledOnNullInput,
)
}
} else {
Expand All @@ -2487,7 +2487,7 @@ func planProjectionExpr(
resultIdx = len(typs)
op, err = colexecproj.GetProjectionOperator(
allocator, typs, outputType, projOp, input, leftIdx, rightIdx,
resultIdx, evalCtx, binOp, cmpExpr, nullableArgs,
resultIdx, evalCtx, binOp, cmpExpr, calledOnNullInput,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/colexec/colexeccmp/default_cmp_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewComparisonExprAdapter(
expr: expr,
}
}
nullable := expr.Op.NullableArgs
nullable := expr.Op.CalledOnNullInput
_, _, _, flipped, negate := tree.FoldComparisonExpr(op, nil /* left */, nil /* right */)
if nullable {
if flipped {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/colexec/colexeccmp/default_cmp_expr_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type _EXPR_NAME struct {
var _ ComparisonExprAdapter = &_EXPR_NAME{}

func (c *_EXPR_NAME) Eval(left, right tree.Datum) (tree.Datum, error) {
// {{if not .NullableArgs}}
// {{if not .CalledOnNullInput}}
if left == tree.DNull || right == tree.DNull {
return tree.DNull, nil
}
Expand Down
Loading

0 comments on commit 31ffb42

Please sign in to comment.