use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project hive by apache.
the class PlanModifierForReturnPath method introduceProjectIfNeeded.
private static RelNode introduceProjectIfNeeded(RelNode optimizedOptiqPlan, List<FieldSchema> resultSchema) throws CalciteSemanticException {
List<String> fieldNames = new ArrayList<>();
for (FieldSchema fieldSchema : resultSchema) {
fieldNames.add(fieldSchema.getName());
}
RelNode newRoot = null;
List<RexNode> projectList = null;
if (!(optimizedOptiqPlan instanceof Project)) {
projectList = HiveCalciteUtil.getProjsFromBelowAsInputRef(optimizedOptiqPlan);
newRoot = HiveProject.create(optimizedOptiqPlan, projectList, fieldNames);
} else {
HiveProject project = (HiveProject) optimizedOptiqPlan;
newRoot = HiveProject.create(project.getInput(0), project.getProjects(), fieldNames);
}
return newRoot;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project hive by apache.
the class MaterializedViewRewritingRelVisitor method visit.
@Override
public void visit(RelNode node, int ordinal, RelNode parent) {
if (node instanceof Aggregate) {
this.containsAggregate = true;
// Aggregate mode - it should be followed by union
// that we need to analyze
RelNode input = node.getInput(0);
if (input instanceof Union) {
check((Union) input);
}
} else if (node instanceof Union) {
// Non aggregate mode - analyze union operator
check((Union) node);
} else if (node instanceof Project) {
// Project operator, we can continue
super.visit(node, ordinal, parent);
}
throw new ReturnedValue(false);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project hive by apache.
the class MaterializedViewRewritingRelVisitor method check.
private void check(Union union) {
// We found the Union
if (union.getInputs().size() != 2) {
// Bail out
throw new ReturnedValue(false);
}
// First branch should have the query (with write ID filter conditions)
new RelVisitor() {
@Override
public void visit(RelNode node, int ordinal, RelNode parent) {
if (node instanceof TableScan || node instanceof Filter || node instanceof Project || node instanceof Join) {
// We can continue
super.visit(node, ordinal, parent);
} else if (node instanceof Aggregate && containsAggregate) {
Aggregate aggregate = (Aggregate) node;
for (int i = 0; i < aggregate.getAggCallList().size(); ++i) {
AggregateCall aggregateCall = aggregate.getAggCallList().get(i);
if (aggregateCall.getAggregation().getKind() == SqlKind.COUNT && aggregateCall.getArgList().size() == 0) {
countIndex = i + aggregate.getGroupCount();
break;
}
}
// We can continue
super.visit(node, ordinal, parent);
} else {
throw new ReturnedValue(false);
}
}
}.go(union.getInput(0));
// Second branch should only have the MV
new RelVisitor() {
@Override
public void visit(RelNode node, int ordinal, RelNode parent) {
if (node instanceof TableScan) {
// We can continue
// TODO: Need to check that this is the same MV that we are rebuilding
RelOptHiveTable hiveTable = (RelOptHiveTable) node.getTable();
if (!hiveTable.getHiveTableMD().isMaterializedView()) {
// If it is not a materialized view, we do not rewrite it
throw new ReturnedValue(false);
}
if (containsAggregate && !AcidUtils.isFullAcidTable(hiveTable.getHiveTableMD())) {
// we do not rewrite it (we need MERGE support)
throw new ReturnedValue(false);
}
} else if (node instanceof Project) {
// We can continue
super.visit(node, ordinal, parent);
} else {
throw new ReturnedValue(false);
}
}
}.go(union.getInput(1));
// We pass all the checks, we can rewrite
throw new ReturnedValue(true);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project hive by apache.
the class FilterSelectivityEstimator method isPartitionPredicate.
private boolean isPartitionPredicate(RexNode expr, RelNode r) {
if (r instanceof Project) {
expr = RelOptUtil.pushFilterPastProject(expr, (Project) r);
return isPartitionPredicate(expr, ((Project) r).getInput());
} else if (r instanceof Filter) {
return isPartitionPredicate(expr, ((Filter) r).getInput());
} else if (r instanceof HiveTableScan) {
RelOptHiveTable table = (RelOptHiveTable) ((HiveTableScan) r).getTable();
ImmutableBitSet cols = RelOptUtil.InputFinder.bits(expr);
return table.containsPartitionColumnsOnly(cols);
}
return false;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project hive by apache.
the class HiveRelDecorrelator method projectedLiteral.
/**
* Returns a literal output field, or null if it is not literal.
*/
private static RexLiteral projectedLiteral(RelNode rel, int i) {
if (rel instanceof Project) {
final Project project = (Project) rel;
final RexNode node = project.getProjects().get(i);
if (node instanceof RexLiteral) {
return (RexLiteral) node;
}
}
return null;
}
Aggregations