Class NumericArgumentFunction
- Direct Known Subclasses:
Abs,Acos,Acosh,Asin,Asinh,Atan,Atan2,Atanh,Bitand,Bitnot,Bitor,BitShiftLeft,BitShiftRight,Bitxor,Cbrt,Ceil,Cos,Cosh,Cot,Degrees,Div0,Exp,Factorial,Floor,Getbit,Haversine,Ln,Log,Mod,Power,Radians,Round,Sign,Sin,Sinh,Sqrt,Square,Tan,Tanh,Trunc,Uniform,WidthBucket,ZeroIfNull
TextArgumentFunction,
and the same live message shape ("Invalid argument types for function 'ABS': (OBJECT)", SQLSTATE
42P13).
Every position, not merely the first — measured, not assumed. Live over an OBJECT
column, ROUND(o, 2) and ROUND(n, o) are both argument-type errors, as are
ATAN2(o, 1) / ATAN2(1, o), LOG(o, 2) / LOG(2, o),
HAVERSINE(o, 1, 2, 3) / HAVERSINE(1, 2, 3, o) and
WIDTH_BUCKET(1, o, 10, 3). A semi-structured value coerces to a NUMBER nowhere, so the
whole signature refuses it.
A declared BOOLEAN, a DATE / TIME / TIMESTAMP, a BINARY and a GEOGRAPHY are refused the same
way, in every position, with the same positioned sentence — live-verified member by member:
ABS(TRUE), ABS(d), ABS(t), ABS(ts), ABS(bn), ABS(g),
ROUND(d, 1) ("(DATE, NUMBER(1,0))"), ROUND(d, 'MONTH') ("(DATE, VARCHAR(5))"),
MOD(1, TRUE) ("(NUMBER(1,0), BOOLEAN)"), POWER(2, d), LOG(10, d),
UNIFORM(TRUE, 2, RANDOM()), WIDTH_BUCKET(TRUE, 0, 10, 2), BITAND(d, 1),
DIV0(TRUE, 1), SIGN, CEIL, FLOOR, SQRT, EXP,
SQUARE, FACTORIAL, CBRT, SIN, DEGREES, GETBIT,
LN, ATAN2, HAVERSINE — each "Invalid argument types for function 'X': (…)"
at the call's own position, listing every argument's declared type. The one arity-dependent
member is TRUNC, which over a temporal is DATE_TRUNC with a unit; see Trunc.
Membership is by measurement, so neighbours in the same package deliberately stay out.
NULLIFZERO is NULLIF(x, 0) and fails the conditional's way live — "Can not convert
parameter '0' of type [NUMBER(1,0)] into expected type [OBJECT]" over an OBJECT, [DATE] over a
DATE, [BINARY(8388608)] over a BINARY — there the argument wins the type unification and the
implicit literal is what is rejected, while a BOOLEAN is TAKEN (a NUMBER meets a BOOLEAN). The
conversion family (TO_NUMBER, TO_DOUBLE, TO_DECIMAL) rejects with the
"invalid type [...] for parameter" shape instead and is likewise not a member.
VARIANT is never refused, even when it holds an object: ABS(v) returned 1 and 2 live,
while ABS(vo) over a VARIANT HOLDING an object is a RUN-TIME cast failure — a different
outcome from the compile-time rejection here, and both are correct. An explicit conversion is legal
too; the rule reads the DECLARED type, so ABS(v::OBJECT) — the same value, cast — IS
refused.
At ROW time every argument IS read as a number, the way live converts: a numeric text in any
position converts — trimmed, in any spelling a number literal has (' 5 ', '1e2',
'+5', '5.', '.5') — while a text that reads as no number is refused with
live's own row-time sentence, "Numeric value 'x' is not recognized", the text echoed trimmed. The
dispatch does the reading, so a member never sees a numeric text and never has to word the refusal
(see the evaluator's numeric-text coercion). A text the member takes AS text — ROUND's rounding
mode — reads as no number and reaches it unchanged.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNumericArgumentFunction(String name, DataType returnType) -
Method Summary
Modifier and TypeMethodDescriptionbinaryRejection(int position) The refusal a position gives a statically BINARY-typed value.booleanRejection(int position) The refusal this position gives a declared BOOLEAN argument.semiStructuredRejection(int position) How argumentpositionrefuses a statically OBJECT- or ARRAY-typed value, orSemiStructuredRejection.NONEwhen it does not.temporalRejection(int position) The refusal this position gives a declared DATE / TIME / TIMESTAMP argument.vectorRejection(int position) A VECTOR reads as neither text nor a number, and is refused in every position (live-verified).Methods inherited from class dev.frostlake.functions.BuiltInFunction
approximateRejection, evaluate, evaluate, fileRejection, geoRejection, getMaxArgCount, getMinArgCount, getName, getReturnType, isVariadic, refusesMissingArgumentsByType, structuredRejection, temporalRejection, temporalRejection, textRejection, uuidRejection
-
Constructor Details
-
NumericArgumentFunction
-
-
Method Details
-
semiStructuredRejection
Description copied from class:BuiltInFunctionHow argumentpositionrefuses a statically OBJECT- or ARRAY-typed value, orSemiStructuredRejection.NONEwhen it does not. Snowflake never implicitly coerces a semi-structured value to the VARCHAR (or NUMBER) a text or numeric function reads, so such an argument is an argument-type error at COMPILE time rather than a stringification or a fabricated zero: live,UPPER(o)over an OBJECT column is "Invalid argument types for function 'UPPER': (OBJECT)",SUM(o)is the same sentence for 'SUM', andSPLIT_PART(s, o, 1)names the position it was given. VARIANT is never refused, even when it holds an object.Declared HERE, on the function, rather than in a name-keyed table beside the rule: the registry is already the authority on a function's types (
BuiltInFunction.getReturnType()), a declaration on the instance covers the function's ALIASES for free (SUBSTR and SUBSTRING are one object, and so are VARIANCE_POP and VAR_POP), and a per-position answer is the only shape that fits —ARRAY_TO_STRING(a, ',')takes an ARRAY in position 0 and refuses one in position 1.The answer is an ENUM rather than a boolean because Snowflake phrases the refusal three different ways, with three different SQLSTATEs — see
SemiStructuredRejection.The default is
NONE, meaning UNDECLARED rather than "accepts": a function that has not been measured against live Snowflake constrains nothing. Answering for every position is whatTextArgumentFunctionandNumericArgumentFunctionexist for.- Overrides:
semiStructuredRejectionin classBuiltInFunction- Parameters:
position- the zero-based argument position being asked about- Returns:
- the refusal this position gives a semi-structured value, or
NONEwhen undeclared
-
booleanRejection
Description copied from class:BuiltInFunctionThe refusal this position gives a declared BOOLEAN argument. Membership is declared per function and never assumed for a family: the whole NUMERIC family (NumericArgumentFunction) refuses a SQL BOOLEAN at compile time in every position — "Invalid argument types for function 'ABS': (BOOLEAN)",MOD(1, TRUE)listing "(NUMBER(1,0), BOOLEAN)" — while the SAME value inside a VARIANT converts to 1.0, and the conditionals (NULLIF(b, 0),NULLIFZERO(b)) take it. The rule reads the DECLARED type, like every channel here.- Overrides:
booleanRejectionin classBuiltInFunction- Parameters:
position- the zero-based argument position being asked about- Returns:
- the refusal this position gives a BOOLEAN value; by default none
-
vectorRejection
A VECTOR reads as neither text nor a number, and is refused in every position (live-verified).- Overrides:
vectorRejectionin classBuiltInFunction- Parameters:
position- the zero-based argument position being asked about- Returns:
- the refusal this position gives a VECTOR value; by default none
-
temporalRejection
Description copied from class:BuiltInFunctionThe refusal this position gives a declared DATE / TIME / TIMESTAMP argument. Declared per function: the numeric family refuses every temporal flavour at compile time, each named with its own parameters — (DATE), (TIME(9)), (TIMESTAMP_NTZ(9)) and the LTZ/TZ twins — where the datetime functions read them happily.- Overrides:
temporalRejectionin classBuiltInFunction- Parameters:
position- the zero-based argument position being asked about- Returns:
- the refusal this position gives a temporal value; by default none
-
binaryRejection
Description copied from class:BuiltInFunctionThe refusal a position gives a statically BINARY-typed value.A fifth question rather than a reuse of any of the four above, because BINARY sits on the opposite side of them: it is a scalar a text function is happy to be handed almost everywhere — live answers
LENGTH(bn),SUBSTR(bn, 1, 1),CONCAT(bn, bn)— where an OBJECT is refused. Only the functions that read their argument AS TEXT and would have to decode it refuse one, and they say so themselves:VALIDATE_UTF8(bn)andTRY_VALIDATE_UTF8(bn)are "Invalid argument types for function 'TRY_VALIDATE_UTF8': (BINARY(5))" while the same call over a VARCHAR, and even over a NUMBER, returns a value.The default is
NONE: undeclared means unconstrained, as for the other four.- Overrides:
binaryRejectionin classBuiltInFunction- Parameters:
position- the zero-based argument position being asked about- Returns:
- the refusal this position gives a BINARY value; by default none
-