Wrap any TokenizedLiteral expression with this so that we can invoke literal
initialization code within the .init()
method of the generated class.
Wrap any TokenizedLiteral expression with this so that we can invoke literal
initialization code within the .init()
method of the generated class.
This pushes itself as reference object and uses a call to eval() on itself for actual
evaluation and avoids embedding any generated code. This allows it to keep the
generated code identical regardless of the constant expression (and in addition
DynamicReplacableConstant trait casts to itself rather than actual object type).
We try to locate first foldable expression in a query tree such that all its child is foldable
but parent isn't. That way we locate the exact point where an expression is safe to evaluate
once instead of evaluating every row.
Expressions like select c from tab where
case col2 when 1 then col3 else 'y' end = 22
like queries don't convert literal evaluation into init method.
minimal expression tree that can be evaluated only once and turn into a constant.
Unlike Spark's InSet expression, this allows for TokenizedLiterals that can change dynamically in executions.
In addition to TokenLiteral, this class can also be used in plan caching so allows for internal value to be updated in subsequent runs when the plan is re-used with different constants.
In addition to TokenLiteral, this class can also be used in plan caching so allows for internal value to be updated in subsequent runs when the plan is re-used with different constants. For that reason this does not extend Literal (to avoid Analyzer/Optimizer etc doing constant propagation for example) and its hash/equals ignores the value matching and only the position of the literal in the plan is used with the data type.
Where ever ParamLiteral case matching is required, it must match for DynamicReplacableConstant and use .eval(..) for code generation. see SNAP-1597 for more details.
A Literal that passes its value as a reference object in generated code instead of embedding as a constant to allow generated code reuse.