public class BeamSqlIntervalMultiplyExpression extends BeamSqlExpression
One use case of this is implementation of TIMESTAMPADD(). Calcite converts TIMESTAMPADD(date, multiplier, inteval) into DATETIME_PLUS(date, multiplier * interval). The 'multiplier * interval' part is what this class implements. It's not a regular numerical multiplication because the return type is expected to be an interval, and the value is expected to use corresponding TimeUnit's internal value (e.g. 12 for YEAR, 60000 for MINUTE).
operands, outputType
Constructor and Description |
---|
BeamSqlIntervalMultiplyExpression(java.util.List<BeamSqlExpression> operands) |
Modifier and Type | Method and Description |
---|---|
boolean |
accept()
Requires exactly 2 operands.
|
BeamSqlPrimitive |
evaluate(Row inputRow,
BoundedWindow window,
BeamSqlExpressionEnvironment env)
Evaluates the number of times the interval should be repeated, times the TimeUnit multiplier.
|
getOperands, getOutputType, numberOfOperands, op, opType, opValueEvaluated
public BeamSqlIntervalMultiplyExpression(java.util.List<BeamSqlExpression> operands)
public boolean accept()
accept
in class BeamSqlExpression
public BeamSqlPrimitive evaluate(Row inputRow, BoundedWindow window, BeamSqlExpressionEnvironment env)
This is due to the fact that TimeUnit has different internal multipliers for each interval, e.g. MONTH is 12, but MINUTE is 60000. When Calcite parses SQL interval literals, it returns those internal multipliers. This means we need to do similar thing, so that this multiplication expression behaves the same way as literal interval expression.
That is, we need to make sure that this: "TIMESTAMP '1984-04-19 01:02:03' + INTERVAL '2' YEAR" is equivalent tot this: "TIMESTAMPADD(YEAR, 2, TIMESTAMP '1984-04-19 01:02:03')"
evaluate
in class BeamSqlExpression