Skip to content

Commit

Permalink
sql: move NullableArgs function property to overload level
Browse files Browse the repository at this point in the history
Currently we only have builtins, and that all overloads of a
same function name share function properties. However, we're
going to support user defined functions whose properties can
vary as how users define them. So we need to move any property
that's relevant to UDF to overload level. Currently, `NullableArgs`
is the only one matters.

Release note: None.
  • Loading branch information
chengxiong-ruan committed Jul 6, 2022
1 parent 933b684 commit dceae64
Show file tree
Hide file tree
Showing 16 changed files with 457 additions and 462 deletions.
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.CanHandleNulls() {
if hasNulls && !b.funcExpr.ResolvedOverload().NullableArgs {
res = tree.DNull
} else {
res, err = b.funcExpr.ResolvedOverload().
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/execinfra/execagg/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func GetAggregateInfo(
return builtins.NewAnyNotNullAggregate, inputTypes[0], nil
}

props, builtins := builtins.GetBuiltinProperties(strings.ToLower(fn.String()))
_, builtins := builtins.GetBuiltinProperties(strings.ToLower(fn.String()))
for _, b := range builtins {
typs := b.Types.Types()
if len(typs) != len(inputTypes) {
Expand All @@ -47,7 +47,7 @@ func GetAggregateInfo(
match := true
for i, t := range typs {
if !inputTypes[i].Equivalent(t) {
if props.NullableArgs && inputTypes[i].IsAmbiguous() {
if b.NullableArgs && inputTypes[i].IsAmbiguous() {
continue
}
match = false
Expand Down Expand Up @@ -131,7 +131,7 @@ func GetWindowFunctionInfo(
"function is neither an aggregate nor a window function",
)
}
props, builtins := builtins.GetBuiltinProperties(strings.ToLower(funcStr))
_, builtins := builtins.GetBuiltinProperties(strings.ToLower(funcStr))
for _, b := range builtins {
typs := b.Types.Types()
if len(typs) != len(inputTypes) {
Expand All @@ -140,7 +140,7 @@ func GetWindowFunctionInfo(
match := true
for i, t := range typs {
if !inputTypes[i].Equivalent(t) {
if props.NullableArgs && inputTypes[i].IsAmbiguous() {
if b.NullableArgs && inputTypes[i].IsAmbiguous() {
continue
}
match = false
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/memo/constraint_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func (cb *constraintsBuilder) buildConstraintForTupleInequality(
func (cb *constraintsBuilder) buildFunctionConstraints(
f *FunctionExpr,
) (_ *constraint.Set, tight bool) {
if f.Properties.NullableArgs {
if f.FunctionPrivate.Overload.NullableArgs {
return unconstrained, false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/norm/fold_constants_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ func (c *CustomFuncs) FoldColumnAccess(
//
// See FoldFunctionWithNullArg for more details.
func (c *CustomFuncs) CanFoldFunctionWithNullArg(private *memo.FunctionPrivate) bool {
return !private.Properties.NullableArgs &&
return !private.Overload.NullableArgs &&
private.Properties.Class == tree.NormalClass
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/optbuilder/sql_fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (b *Builder) buildSQLFn(
))
}
exprs[i] = memo.ExtractConstDatum(info.args[i])
if exprs[i] == tree.DNull && !info.def.Properties.NullableArgs {
if exprs[i] == tree.DNull && !info.def.Overload.NullableArgs {
return b.factory.ConstructNull(info.ResolvedType())
}
}
Expand Down
434 changes: 202 additions & 232 deletions pkg/sql/sem/builtins/aggregate_builtins.go

Large diffs are not rendered by default.

Loading

0 comments on commit dceae64

Please sign in to comment.