Search in sources :

Example 81 with RexNode

use of org.apache.calcite.rex.RexNode in project drill by apache.

the class DrillOptiqTest method testUnsupportedRexNode.

/* Method checks if we raise the appropriate error while dealing with RexNode that cannot be converted to
   * equivalent Drill expressions
   */
@Test
public void testUnsupportedRexNode() {
    try {
        // Create the data type factory.
        RelDataTypeFactory relFactory = new SqlTypeFactoryImpl(DrillRelDataTypeSystem.DRILL_REL_DATATYPE_SYSTEM);
        // Create the rex builder
        RexBuilder rex = new RexBuilder(relFactory);
        RelDataType anyType = relFactory.createSqlType(SqlTypeName.ANY);
        List<RexNode> emptyList = new LinkedList<>();
        ImmutableList<RexFieldCollation> e = ImmutableList.copyOf(new RexFieldCollation[0]);
        // create a dummy RexOver object.
        RexNode window = rex.makeOver(anyType, SqlStdOperatorTable.AVG, emptyList, emptyList, e, null, null, true, false, false);
        DrillOptiq.toDrill(null, (RelNode) null, window);
    } catch (UserException e) {
        if (e.getMessage().contains(DrillOptiq.UNSUPPORTED_REX_NODE_ERROR)) {
            // got expected error return
            return;
        }
        Assert.fail("Hit exception with unexpected error message");
    }
    Assert.fail("Failed to raise the expected exception");
}
Also used : SqlTypeFactoryImpl(org.apache.calcite.sql.type.SqlTypeFactoryImpl) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RexBuilder(org.apache.calcite.rex.RexBuilder) RelDataType(org.apache.calcite.rel.type.RelDataType) UserException(org.apache.drill.common.exceptions.UserException) RexFieldCollation(org.apache.calcite.rex.RexFieldCollation) LinkedList(java.util.LinkedList) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Example 82 with RexNode

use of org.apache.calcite.rex.RexNode in project drill by apache.

the class FilterSplitTest method badFunc.

@Test
public void badFunc() {
    // (dir0 = 1 and dir1 = 2) OR (a < 5)
    RexNode n = fn(cs(0), cs(1));
    BitSet bs = new BitSet();
    bs.set(1);
    bs.set(2);
    FindPartitionConditions c = new FindPartitionConditions(bs, builder);
    c.analyze(n);
    RexNode partNode = c.getFinalCondition();
    assertEquals("||($0, $1)", n.toString());
    assertTrue(partNode == null);
}
Also used : FindPartitionConditions(org.apache.drill.exec.planner.logical.partition.FindPartitionConditions) BitSet(java.util.BitSet) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Example 83 with RexNode

use of org.apache.calcite.rex.RexNode in project drill by apache.

the class FilterSplitTest method simpleCompound.

@Test
public void simpleCompound() {
    // a < 1 AND dir0 in (2,3)
    RexNode n = and(lt(c(0), lit(1)), or(eq(c(1), lit(2)), eq(c(1), lit(3))));
    BitSet bs = new BitSet();
    bs.set(1);
    FindPartitionConditions c = new FindPartitionConditions(bs, builder);
    c.analyze(n);
    RexNode partNode = c.getFinalCondition();
    assertEquals(n.toString(), "AND(<($0, 1), OR(=($1, 2), =($1, 3)))");
    assertEquals(partNode.toString(), "OR(=($1, 2), =($1, 3))");
}
Also used : FindPartitionConditions(org.apache.drill.exec.planner.logical.partition.FindPartitionConditions) BitSet(java.util.BitSet) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Example 84 with RexNode

use of org.apache.calcite.rex.RexNode in project drill by apache.

the class CreateTableHandler method createPartitionColComparator.

private RexNode createPartitionColComparator(final RexBuilder rexBuilder, List<RexNode> inputs) {
    final DrillSqlOperator op = new DrillSqlOperator(WriterPrel.PARTITION_COMPARATOR_FUNC, 1, true, false);
    final List<RexNode> compFuncs = Lists.newArrayListWithExpectedSize(inputs.size());
    for (final RexNode input : inputs) {
        compFuncs.add(rexBuilder.makeCall(op, ImmutableList.of(input)));
    }
    return composeDisjunction(rexBuilder, compFuncs);
}
Also used : DrillSqlOperator(org.apache.drill.exec.planner.sql.DrillSqlOperator) RexNode(org.apache.calcite.rex.RexNode)

Example 85 with RexNode

use of org.apache.calcite.rex.RexNode in project drill by apache.

the class JoinUtils method checkCartesianJoin.

/**
     * Check if the given RelNode contains any Cartesian join.
     * Return true if find one. Otherwise, return false.
     *
     * @param relNode     the RelNode to be inspected.
     * @param leftKeys    a list used for the left input into the join which has
     *                    equi-join keys. It can be empty or not (but not null),
     *                    this method will clear this list before using it.
     * @param rightKeys   a list used for the right input into the join which has
     *                    equi-join keys. It can be empty or not (but not null),
     *                    this method will clear this list before using it.
     * @param filterNulls The join key positions for which null values will not
     *                    match.
     * @return            Return true if the given relNode contains Cartesian join.
     *                    Otherwise, return false
     */
public static boolean checkCartesianJoin(RelNode relNode, List<Integer> leftKeys, List<Integer> rightKeys, List<Boolean> filterNulls) {
    if (relNode instanceof Join) {
        leftKeys.clear();
        rightKeys.clear();
        Join joinRel = (Join) relNode;
        RelNode left = joinRel.getLeft();
        RelNode right = joinRel.getRight();
        RexNode remaining = RelOptUtil.splitJoinCondition(left, right, joinRel.getCondition(), leftKeys, rightKeys, filterNulls);
        if (joinRel.getJoinType() == JoinRelType.INNER) {
            if (leftKeys.isEmpty() || rightKeys.isEmpty()) {
                return true;
            }
        } else {
            if (!remaining.isAlwaysTrue() || leftKeys.isEmpty() || rightKeys.isEmpty()) {
                return true;
            }
        }
    }
    for (RelNode child : relNode.getInputs()) {
        if (checkCartesianJoin(child, leftKeys, rightKeys, filterNulls)) {
            return true;
        }
    }
    return false;
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Join(org.apache.calcite.rel.core.Join) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

RexNode (org.apache.calcite.rex.RexNode)204 RelNode (org.apache.calcite.rel.RelNode)75 ArrayList (java.util.ArrayList)68 RexBuilder (org.apache.calcite.rex.RexBuilder)52 RelDataType (org.apache.calcite.rel.type.RelDataType)48 RexInputRef (org.apache.calcite.rex.RexInputRef)43 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)41 RexCall (org.apache.calcite.rex.RexCall)32 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)28 Pair (org.apache.calcite.util.Pair)22 HashMap (java.util.HashMap)21 AggregateCall (org.apache.calcite.rel.core.AggregateCall)21 RexLiteral (org.apache.calcite.rex.RexLiteral)19 ImmutableList (com.google.common.collect.ImmutableList)18 Project (org.apache.calcite.rel.core.Project)17 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)14 Filter (org.apache.calcite.rel.core.Filter)12 HashSet (java.util.HashSet)11 CalciteSemanticException (org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)11 BigDecimal (java.math.BigDecimal)10