Interface ScalarFunction
- All Known Subinterfaces:
LazyScalarFunction,StrictScalarFunction
The hierarchy is sealed over exactly two ways of receiving arguments, so the engine dispatches on a switch the compiler can check for completeness:
StrictScalarFunction— every argument is evaluated before the call. This is what a function wants unless it has a reason not to.LazyScalarFunction— arguments arrive as deferredArguments, and one that is never asked for is never evaluated. This is what makes a conditional usable as a guard: the branch not taken may be an expression that would fail on this row.
Both are non-sealed, so implementing either is open to any library; it
is the choice between them that is closed.
The engine checks the declared Arity before invoking, so an
implementation may read the arguments its signature allows without counting them
first.
-
Method Summary
Modifier and TypeMethodDescriptiondefault Set<ScalarType> argumentTypes(int index) The types the argument atindexmay have, for analysis to accept a call before it runs.blocking(Blocking.Bound bound, BigDecimal threshold) How to find, among many values, the few that a call compared against a constant could accept — so that a join onF(left.x, right.y) >= tneed not callFon every pair.default Stringname()default PushdownSpellingpushdown()How this function is spelled in a backend that could evaluate it itself.default ScalarTypereturnTypeFor(List<ScalarType> argumentTypes) The result type of a call with these argument types.The form of this function — name, parameters, arity, return type, properties.
-
Method Details
-
signature
FunctionSignature signature()The form of this function — name, parameters, arity, return type, properties.- Returns:
- the signature; never
null
-
name
- Returns:
- the canonical spelling of this function's name
-
returnTypeFor
The result type of a call with these argument types.Defaults to the declared return type, which is the answer whenever the result type is fixed. Override it for a function whose result follows its arguments — a conditional returning whichever branch it selects, a
Coalesceover a homogeneous list — and the engine's schema inference uses the narrower type.- Parameters:
argumentTypes- the argument types at the call site, in order- Returns:
- the result type of that call
-
argumentTypes
The types the argument atindexmay have, for analysis to accept a call before it runs.Defaults to the parameter's declared type, or every type when the parameter is declared
ScalarType.ANY, orindexis past the declared parameters, or the function takes a range of argument counts, where an argument's position need not be its parameter's:InStr(start, s, find)besideInStr(s, find). Override it for a parameter that takes several types but not every one — a date part that reads aDATEor aTIMESTAMP— so that a call passing any other is refused at analysis rather than when it runs. An argument whose type analysis cannot tell is always accepted.- Parameters:
index- the argument's position, from 0- Returns:
- the accepted types; never empty
-
pushdown
How this function is spelled in a backend that could evaluate it itself.Defaults to
PushdownSpelling.NONE— no backend spelling, so the engine evaluates every call. Supplying one is how a library's own function folds into a pushed query alongside the built-ins.- Returns:
- the pushdown spelling; never
null
-
blocking
How to find, among many values, the few that a call compared against a constant could accept — so that a join onF(left.x, right.y) >= tneed not callFon every pair.Defaults to empty, which leaves such a join to compare every pair. A two-argument similarity function overrides it to offer a
Blockingfor the comparisons it can bound; theBlockingcontract says what the offer promises.- Parameters:
bound- how the call's result is compared with the threshold, read with the call on the left:F(a, b) bound thresholdthreshold- the constant the result is compared with- Returns:
- a blocking for that comparison, or empty when there is none
-