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");
}
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);
}
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))");
}
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);
}
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;
}
Aggregations