Search in sources :

Example 11 with Tuple2

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;
    }
}
Also used : RexCall(org.apache.calcite.rex.RexCall) Tuple2(com.hazelcast.jet.datamodel.Tuple2) RexInputRef(org.apache.calcite.rex.RexInputRef) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

Tuple2 (com.hazelcast.jet.datamodel.Tuple2)10 Tuple2.tuple2 (com.hazelcast.jet.datamodel.Tuple2.tuple2)7 List (java.util.List)7 Entry (java.util.Map.Entry)7 DAG (com.hazelcast.jet.core.DAG)6 Map (java.util.Map)6 Function (java.util.function.Function)6 JetException (com.hazelcast.jet.JetException)5 Edge (com.hazelcast.jet.core.Edge)5 ItemsByTag (com.hazelcast.jet.datamodel.ItemsByTag)5 ArrayList (java.util.ArrayList)5 Collections.singletonList (java.util.Collections.singletonList)5 Nonnull (javax.annotation.Nonnull)5 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)4 AggregateOperation1 (com.hazelcast.jet.aggregate.AggregateOperation1)4 AggregateOperations.coAggregateOperationBuilder (com.hazelcast.jet.aggregate.AggregateOperations.coAggregateOperationBuilder)4 CoAggregateOperationBuilder (com.hazelcast.jet.aggregate.CoAggregateOperationBuilder)4 Tag (com.hazelcast.jet.datamodel.Tag)4 Tuple3 (com.hazelcast.jet.datamodel.Tuple3)4 Tuple3.tuple3 (com.hazelcast.jet.datamodel.Tuple3.tuple3)4