private void defineImplementor( SqlOperator operator, NullPolicy nullPolicy, NotNullImplementor implementor, boolean harmonize) { CallImplementor callImplementor = createImplementor(implementor, nullPolicy, harmonize); map.put(operator, callImplementor); }
private void defineMethod( SqlOperator operator, String functionName, NullPolicy nullPolicy) { defineImplementor( operator, nullPolicy, new MethodNameImplementor(functionName), false); }
/** Translates a call to an operator or function. */ private Expression translateCall(RexCall call, RexImpTable.NullAs nullAs) { final SqlOperator operator = call.getOperator(); CallImplementor implementor = RexImpTable.INSTANCE.get(operator); if (implementor == null) { throw new RuntimeException("cannot translate call " + call); } return implementor.implement(this, call, nullAs); }
RexImpTable() { defineMethod(ROW, BuiltInMethod.ARRAY.method, NullPolicy.ANY); defineMethod(UPPER, BuiltInMethod.UPPER.method, NullPolicy.STRICT); defineMethod(LOWER, BuiltInMethod.LOWER.method, NullPolicy.STRICT); defineMethod(INITCAP, BuiltInMethod.INITCAP.method, NullPolicy.STRICT); defineMethod(SUBSTRING, BuiltInMethod.SUBSTRING.method, NullPolicy.STRICT); defineMethod(REPLACE, BuiltInMethod.REPLACE.method, NullPolicy.STRICT); defineMethod(TRANSLATE3, BuiltInMethod.TRANSLATE3.method, NullPolicy.STRICT); defineMethod(CHARACTER_LENGTH, BuiltInMethod.CHAR_LENGTH.method, NullPolicy.STRICT); defineMethod(CHAR_LENGTH, BuiltInMethod.CHAR_LENGTH.method, NullPolicy.STRICT); defineMethod(CONCAT, BuiltInMethod.STRING_CONCAT.method, NullPolicy.STRICT); defineMethod(OVERLAY, BuiltInMethod.OVERLAY.method, NullPolicy.STRICT); defineMethod(POSITION, BuiltInMethod.POSITION.method, NullPolicy.STRICT); defineImplementor(TRIM, NullPolicy.STRICT, trimImplementor, false); defineBinary(AND, AndAlso, NullPolicy.AND, null); defineBinary(OR, OrElse, NullPolicy.OR, null); defineUnary(NOT, Not, NullPolicy.NOT); defineBinary(LESS_THAN, LessThan, NullPolicy.STRICT, "lt"); defineBinary(LESS_THAN_OR_EQUAL, LessThanOrEqual, NullPolicy.STRICT, "le"); defineBinary(GREATER_THAN, GreaterThan, NullPolicy.STRICT, "gt"); defineBinary(GREATER_THAN_OR_EQUAL, GreaterThanOrEqual, NullPolicy.STRICT, "ge"); defineBinary(EQUALS, Equal, NullPolicy.STRICT, "eq"); defineBinary(NOT_EQUALS, NotEqual, NullPolicy.STRICT, "ne");
case STRICT: case SEMI_STRICT: return (translator, call, nullAs) -> implementNullSemantics0( translator, call, nullAs, nullPolicy, harmonize, implementor); : "AND null semantics is supported only for AND operator. Actual operator is " + String.valueOf(call.getOperator()); final RexCall call2 = call2(false, translator, call); switch (nullAs) { case NOT_POSSIBLE: // Just foldAnd : "OR null semantics is supported only for OR operator. Actual operator is " + String.valueOf(call.getOperator()); final RexCall call2 = call2(harmonize, translator, call); switch (nullAs) { case NOT_POSSIBLE: // Just foldOr case NONE: return (translator, call, nullAs) -> { final RexCall call2 = call2(false, translator, call); return implementCall( translator, call2, implementor, nullAs); };
public final void implementReset(AggContext info, AggResetContext reset) { if (trackNullsPerRow) { List<Expression> acc = reset.accumulator(); Expression flag = acc.get(acc.size() - 1); BlockBuilder block = reset.currentBlock(); block.add( Expressions.statement( Expressions.assign(flag, RexImpTable.getDefaultValue(flag.getType())))); } implementNotNullReset(info, reset); }
final RexCall call2 = call2(harmonize, translator, call); try { return implementNullSemantics( translator, call2, nullAs, nullPolicy, implementor); } catch (RexToLixTranslator.AlwaysNull e) {
RexImpTable() { defineMethod(ROW, BuiltInMethod.ARRAY.method, NullPolicy.ANY); defineMethod(UPPER, BuiltInMethod.UPPER.method, NullPolicy.STRICT); defineMethod(LOWER, BuiltInMethod.LOWER.method, NullPolicy.STRICT); defineMethod(INITCAP, BuiltInMethod.INITCAP.method, NullPolicy.STRICT); defineMethod(SUBSTRING, BuiltInMethod.SUBSTRING.method, NullPolicy.STRICT); defineMethod(REPLACE, BuiltInMethod.REPLACE.method, NullPolicy.STRICT); defineMethod(TRANSLATE3, BuiltInMethod.TRANSLATE3.method, NullPolicy.STRICT); defineMethod(CHARACTER_LENGTH, BuiltInMethod.CHAR_LENGTH.method, NullPolicy.STRICT); defineMethod(CHAR_LENGTH, BuiltInMethod.CHAR_LENGTH.method, NullPolicy.STRICT); defineMethod(CONCAT, BuiltInMethod.STRING_CONCAT.method, NullPolicy.STRICT); defineMethod(OVERLAY, BuiltInMethod.OVERLAY.method, NullPolicy.STRICT); defineMethod(POSITION, BuiltInMethod.POSITION.method, NullPolicy.STRICT); defineImplementor(TRIM, NullPolicy.STRICT, trimImplementor, false); defineBinary(AND, AndAlso, NullPolicy.AND, null); defineBinary(OR, OrElse, NullPolicy.OR, null); defineUnary(NOT, Not, NullPolicy.NOT); defineBinary(LESS_THAN, LessThan, NullPolicy.STRICT, "lt"); defineBinary(LESS_THAN_OR_EQUAL, LessThanOrEqual, NullPolicy.STRICT, "le"); defineBinary(GREATER_THAN, GreaterThan, NullPolicy.STRICT, "gt"); defineBinary(GREATER_THAN_OR_EQUAL, GreaterThanOrEqual, NullPolicy.STRICT, "ge"); defineBinary(EQUALS, Equal, NullPolicy.STRICT, "eq"); defineBinary(NOT_EQUALS, NotEqual, NullPolicy.STRICT, "ne");
case STRICT: case SEMI_STRICT: return (translator, call, nullAs) -> implementNullSemantics0( translator, call, nullAs, nullPolicy, harmonize, implementor); : "AND null semantics is supported only for AND operator. Actual operator is " + String.valueOf(call.getOperator()); final RexCall call2 = call2(false, translator, call); switch (nullAs) { case NOT_POSSIBLE: // Just foldAnd : "OR null semantics is supported only for OR operator. Actual operator is " + String.valueOf(call.getOperator()); final RexCall call2 = call2(harmonize, translator, call); switch (nullAs) { case NOT_POSSIBLE: // Just foldOr case NONE: return (translator, call, nullAs) -> { final RexCall call2 = call2(false, translator, call); return implementCall( translator, call2, implementor, nullAs); };
public final void implementReset(AggContext info, AggResetContext reset) { if (trackNullsPerRow) { List<Expression> acc = reset.accumulator(); Expression flag = acc.get(acc.size() - 1); BlockBuilder block = reset.currentBlock(); block.add( Expressions.statement( Expressions.assign(flag, RexImpTable.getDefaultValue(flag.getType())))); } implementNotNullReset(info, reset); }
final RexCall call2 = call2(harmonize, translator, call); try { return implementNullSemantics( translator, call2, nullAs, nullPolicy, implementor); } catch (RexToLixTranslator.AlwaysNull e) {
private void defineImplementor( SqlOperator operator, NullPolicy nullPolicy, NotNullImplementor implementor, boolean harmonize) { CallImplementor callImplementor = createImplementor(implementor, nullPolicy, harmonize); map.put(operator, callImplementor); }
protected void implementNotNullReset(AggContext info, AggResetContext reset) { BlockBuilder block = reset.currentBlock(); List<Expression> accumulator = reset.accumulator(); for (int i = 0; i < getStateSize(); i++) { Expression exp = accumulator.get(i); block.add( Expressions.statement( Expressions.assign(exp, RexImpTable.getDefaultValue(exp.getType())))); } }
private void defineMethod( SqlOperator operator, Method method, NullPolicy nullPolicy) { defineImplementor( operator, nullPolicy, new MethodImplementor(method), false); }
public AggImpState(int aggIdx, AggregateCall call, boolean windowContext) { this.aggIdx = aggIdx; this.call = call; this.implementor = RexImpTable.INSTANCE.get(call.getAggregation(), windowContext); if (implementor == null) { throw new IllegalArgumentException( "Unable to get aggregate implementation for aggregate " + call.getAggregation() + (windowContext ? " in window context" : "")); } } }
private static CallImplementor createImplementor(final Method method) { return RexImpTable.createImplementor( new ReflectiveCallNotNullImplementor(method) { public Expression implement(RexToLixTranslator translator, RexCall call, List<Expression> translatedOperands) { Expression expr = super.implement(translator, call, translatedOperands); final Class<?> returnType = method.getReturnType(); if (QueryableTable.class.isAssignableFrom(returnType)) { Expression queryable = Expressions.call( Expressions.convert_(expr, QueryableTable.class), BuiltInMethod.QUERYABLE_TABLE_AS_QUERYABLE.method, Expressions.call(DataContext.ROOT, BuiltInMethod.DATA_CONTEXT_GET_QUERY_PROVIDER.method), Expressions.constant(null, SchemaPlus.class), Expressions.constant(call.getOperator().getName(), String.class)); expr = Expressions.call(queryable, BuiltInMethod.QUERYABLE_AS_ENUMERABLE.method); } else { expr = Expressions.call(expr, BuiltInMethod.SCANNABLE_TABLE_SCAN.method, DataContext.ROOT); } return expr; } }, NullPolicy.ANY, false); }
protected void implementNotNullReset(AggContext info, AggResetContext reset) { BlockBuilder block = reset.currentBlock(); List<Expression> accumulator = reset.accumulator(); for (int i = 0; i < getStateSize(); i++) { Expression exp = accumulator.get(i); block.add( Expressions.statement( Expressions.assign(exp, RexImpTable.getDefaultValue(exp.getType())))); } }
private void defineUnary( SqlOperator operator, ExpressionType expressionType, NullPolicy nullPolicy) { defineImplementor( operator, nullPolicy, new UnaryImplementor(expressionType), false); }