use of com.hazelcast.jet.datamodel.Tuple2 in project hazelcast by hazelcast.
the class OptUtils method extractKeyConstantExpression.
@SuppressWarnings("checkstyle:AvoidNestedBlocks")
public static RexNode extractKeyConstantExpression(RelOptTable relTable, RexBuilder rexBuilder) {
HazelcastTable table = relTable.unwrap(HazelcastTable.class);
RexNode filter = table.getFilter();
if (filter == null) {
return null;
}
int keyIndex = findKeyIndex(table.getTarget());
switch(filter.getKind()) {
// WHERE __key = true, calcite simplifies to just `WHERE __key`
case INPUT_REF:
{
return ((RexInputRef) filter).getIndex() == keyIndex ? rexBuilder.makeLiteral(true) : null;
}
// WHERE __key = false, calcite simplifies to `WHERE NOT __key`
case NOT:
{
RexNode operand = ((RexCall) filter).getOperands().get(0);
return operand.getKind() == SqlKind.INPUT_REF && ((RexInputRef) operand).getIndex() == keyIndex ? rexBuilder.makeLiteral(false) : null;
}
// __key = ...
case EQUALS:
{
Tuple2<Integer, RexNode> constantExpressionByIndex = extractConstantExpression((RexCall) filter);
// noinspection ConstantConditions
return constantExpressionByIndex != null && constantExpressionByIndex.getKey() == keyIndex ? constantExpressionByIndex.getValue() : null;
}
default:
return null;
}
}
Aggregations