use of org.apache.calcite.plan.RelTraitSet in project storm by apache.
the class TridentModifyRule method convert.
@Override
public RelNode convert(RelNode rel) {
final TableModify tableModify = (TableModify) rel;
final RelNode input = tableModify.getInput();
final RelOptCluster cluster = tableModify.getCluster();
final RelTraitSet traitSet = tableModify.getTraitSet().replace(TridentLogicalConvention.INSTANCE);
final RelOptTable relOptTable = tableModify.getTable();
final Prepare.CatalogReader catalogReader = tableModify.getCatalogReader();
final RelNode convertedInput = convert(input, input.getTraitSet().replace(TridentLogicalConvention.INSTANCE));
final TableModify.Operation operation = tableModify.getOperation();
final List<String> updateColumnList = tableModify.getUpdateColumnList();
final List<RexNode> sourceExpressionList = tableModify.getSourceExpressionList();
final boolean flattened = tableModify.isFlattened();
final Table table = tableModify.getTable().unwrap(Table.class);
switch(table.getJdbcTableType()) {
case STREAM:
if (operation != TableModify.Operation.INSERT) {
throw new UnsupportedOperationException(String.format("Streams doesn't support %s modify operation", operation));
}
return new TridentStreamInsertRel(cluster, traitSet, relOptTable, catalogReader, convertedInput, operation, updateColumnList, sourceExpressionList, flattened);
default:
throw new IllegalArgumentException(String.format("Unsupported table type: %s", table.getJdbcTableType()));
}
}
use of org.apache.calcite.plan.RelTraitSet in project hive by apache.
the class HiveCalciteUtil method createUDTFForSetOp.
public static HiveTableFunctionScan createUDTFForSetOp(RelOptCluster cluster, RelNode input) throws SemanticException {
RelTraitSet traitSet = TraitsUtil.getDefaultTraitSet(cluster);
List<RexNode> originalInputRefs = Lists.transform(input.getRowType().getFieldList(), new Function<RelDataTypeField, RexNode>() {
@Override
public RexNode apply(RelDataTypeField input) {
return new RexInputRef(input.getIndex(), input.getType());
}
});
ImmutableList.Builder<RelDataType> argTypeBldr = ImmutableList.<RelDataType>builder();
for (int i = 0; i < originalInputRefs.size(); i++) {
argTypeBldr.add(originalInputRefs.get(i).getType());
}
RelDataType retType = input.getRowType();
String funcName = "replicate_rows";
FunctionInfo fi = FunctionRegistry.getFunctionInfo(funcName);
SqlOperator calciteOp = SqlFunctionConverter.getCalciteOperator(funcName, fi.getGenericUDTF(), argTypeBldr.build(), retType);
// Hive UDTF only has a single input
List<RelNode> list = new ArrayList<>();
list.add(input);
RexNode rexNode = cluster.getRexBuilder().makeCall(calciteOp, originalInputRefs);
return HiveTableFunctionScan.create(cluster, traitSet, list, rexNode, null, retType, null);
}
use of org.apache.calcite.plan.RelTraitSet in project drill by apache.
the class UnionAllPrule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final DrillUnionRel union = (DrillUnionRel) call.rel(0);
final List<RelNode> inputs = union.getInputs();
List<RelNode> convertedInputList = Lists.newArrayList();
PlannerSettings settings = PrelUtil.getPlannerSettings(call.getPlanner());
boolean allHashDistributed = true;
for (int i = 0; i < inputs.size(); i++) {
RelNode child = inputs.get(i);
List<DistributionField> childDistFields = Lists.newArrayList();
RelNode convertedChild;
for (RelDataTypeField f : child.getRowType().getFieldList()) {
childDistFields.add(new DistributionField(f.getIndex()));
}
if (settings.isUnionAllDistributeEnabled()) {
/*
* Strictly speaking, union-all does not need re-distribution of data; but in Drill's execution
* model, the data distribution and parallelism operators are the same. Here, we insert a
* hash distribution operator to allow parallelism to be determined independently for the parent
* and children. (See DRILL-4833).
* Note that a round robin distribution would have sufficed but we don't have one.
*/
DrillDistributionTrait hashChild = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(childDistFields));
RelTraitSet traitsChild = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL).plus(hashChild);
convertedChild = convert(child, PrelUtil.fixTraits(call, traitsChild));
} else {
RelTraitSet traitsChild = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL);
convertedChild = convert(child, PrelUtil.fixTraits(call, traitsChild));
allHashDistributed = false;
}
convertedInputList.add(convertedChild);
}
try {
RelTraitSet traits;
if (allHashDistributed) {
// since all children of union-all are hash distributed, propagate the traits of the left child
traits = convertedInputList.get(0).getTraitSet();
} else {
// output distribution trait is set to ANY since union-all inputs may be distributed in different ways
// and unlike a join there are no join keys that allow determining how the output would be distributed.
// Note that a downstream operator may impose a required distribution which would be satisfied by
// inserting an Exchange after the Union-All.
traits = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL).plus(DrillDistributionTrait.ANY);
}
Preconditions.checkArgument(convertedInputList.size() >= 2, "Union list must be at least two items.");
RelNode left = convertedInputList.get(0);
for (int i = 1; i < convertedInputList.size(); i++) {
left = new UnionAllPrel(union.getCluster(), traits, ImmutableList.of(left, convertedInputList.get(i)), false);
}
call.transformTo(left);
} catch (InvalidRelException e) {
tracer.warning(e.toString());
}
}
use of org.apache.calcite.plan.RelTraitSet in project drill by apache.
the class UnionDistinctPrule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final DrillUnionRel union = (DrillUnionRel) call.rel(0);
final List<RelNode> inputs = union.getInputs();
List<RelNode> convertedInputList = Lists.newArrayList();
RelTraitSet traits = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL);
try {
for (int i = 0; i < inputs.size(); i++) {
RelNode convertedInput = convert(inputs.get(i), PrelUtil.fixTraits(call, traits));
convertedInputList.add(convertedInput);
}
traits = call.getPlanner().emptyTraitSet().plus(Prel.DRILL_PHYSICAL).plus(DrillDistributionTrait.SINGLETON);
UnionDistinctPrel unionDistinct = new UnionDistinctPrel(union.getCluster(), traits, convertedInputList, false);
call.transformTo(unionDistinct);
} catch (InvalidRelException e) {
tracer.warning(e.toString());
}
}
use of org.apache.calcite.plan.RelTraitSet in project drill by apache.
the class WriterPrule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final DrillWriterRel writer = call.rel(0);
final RelNode input = call.rel(1);
final List<Integer> keys = writer.getPartitionKeys();
final RelCollation collation = getCollation(keys);
final boolean hashDistribute = PrelUtil.getPlannerSettings(call.getPlanner()).getOptions().getOption(ExecConstants.CTAS_PARTITIONING_HASH_DISTRIBUTE_VALIDATOR);
final RelTraitSet traits = hashDistribute ? input.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collation).plus(getDistribution(keys)) : input.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collation);
final RelNode convertedInput = convert(input, traits);
if (!new WriteTraitPull(call).go(writer, convertedInput)) {
DrillWriterRelBase newWriter = new WriterPrel(writer.getCluster(), convertedInput.getTraitSet(), convertedInput, writer.getCreateTableEntry());
call.transformTo(newWriter);
}
}
Aggregations