use of org.apache.calcite.rel.core.Project in project hive by apache.
the class HiveProjectMergeRule method matches.
@Override
public boolean matches(RelOptRuleCall call) {
// Currently we do not support merging windowing functions with other
// windowing functions i.e. embedding windowing functions within each
// other
final Project topProject = call.rel(0);
final Project bottomProject = call.rel(1);
for (RexNode expr : topProject.getProjects()) {
if (expr instanceof RexOver) {
Set<Integer> positions = HiveCalciteUtil.getInputRefs(expr);
for (int pos : positions) {
if (bottomProject.getProjects().get(pos) instanceof RexOver) {
return false;
}
}
}
}
return super.matches(call);
}
use of org.apache.calcite.rel.core.Project in project hive by apache.
the class HiveFilterProjectTSTransposeRule method onMatch.
// ~ Methods ----------------------------------------------------------------
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
final Filter filter = call.rel(0);
final Project project = call.rel(1);
if (RexOver.containsOver(project.getProjects(), null)) {
// it can be pushed down. For now we don't support this.
return;
}
if (RexUtil.containsCorrelation(filter.getCondition())) {
// Correlate from being de-correlated.
return;
}
// convert the filter to one that references the child of the project
RexNode newCondition = RelOptUtil.pushPastProject(filter.getCondition(), project);
// Remove cast of BOOLEAN NOT NULL to BOOLEAN or vice versa. Filter accepts
// nullable and not-nullable conditions, but a CAST might get in the way of
// other rewrites.
final RelDataTypeFactory typeFactory = filter.getCluster().getTypeFactory();
if (RexUtil.isNullabilityCast(typeFactory, newCondition)) {
newCondition = ((RexCall) newCondition).getOperands().get(0);
}
RelNode newFilterRel = filterFactory == null ? filter.copy(filter.getTraitSet(), project.getInput(), newCondition) : filterFactory.createFilter(project.getInput(), newCondition);
RelNode newProjRel = projectFactory == null ? project.copy(project.getTraitSet(), newFilterRel, project.getProjects(), project.getRowType()) : projectFactory.createProject(newFilterRel, Collections.emptyList(), project.getProjects(), project.getRowType().getFieldNames());
call.transformTo(newProjRel);
}
use of org.apache.calcite.rel.core.Project in project hive by apache.
the class HiveCalciteUtil method getExprNodes.
public static List<ExprNodeDesc> getExprNodes(List<Integer> inputRefs, RelNode inputRel, String inputTabAlias) {
List<ExprNodeDesc> exprNodes = new ArrayList<ExprNodeDesc>();
List<RexNode> rexInputRefs = getInputRef(inputRefs, inputRel);
List<RexNode> exprs = inputRel instanceof Project ? ((Project) inputRel).getProjects() : null;
// TODO: Change ExprNodeConverter to be independent of Partition Expr
ExprNodeConverter exprConv = new ExprNodeConverter(inputTabAlias, inputRel.getRowType(), new HashSet<Integer>(), inputRel.getCluster().getTypeFactory());
for (int index = 0; index < rexInputRefs.size(); index++) {
// check the corresponding expression in exprs to see if it is literal
if (exprs != null && index < exprs.size() && exprs.get(inputRefs.get(index)) instanceof RexLiteral) {
// because rexInputRefs represent ref expr corresponding to value in inputRefs it is used to get
// corresponding index
ExprNodeDesc exprNodeDesc = exprConv.visitLiteral((RexLiteral) exprs.get(inputRefs.get(index)));
exprNodes.add(exprNodeDesc);
} else {
RexNode iRef = rexInputRefs.get(index);
exprNodes.add(iRef.accept(exprConv));
}
}
return exprNodes;
}
use of org.apache.calcite.rel.core.Project in project hive by apache.
the class CorrelateProjectExtractor method findCorrelationDependentCalls.
/**
* Traverses a plan and finds all simply correlated row expressions with the specified id.
*/
private static Set<RexNode> findCorrelationDependentCalls(CorrelationId corrId, RelNode plan) {
SimpleCorrelationCollector finder = new SimpleCorrelationCollector(corrId);
plan.accept(new RelHomogeneousShuttle() {
@Override
public RelNode visit(RelNode other) {
if (other instanceof Project || other instanceof Filter) {
other.accept(finder);
}
return super.visit(other);
}
});
return finder.correlations;
}
use of org.apache.calcite.rel.core.Project in project hive by apache.
the class HiveJdbcConverter method generateSql.
public String generateSql() {
SqlDialect dialect = getJdbcDialect();
final HiveJdbcImplementor jdbcImplementor = new HiveJdbcImplementor(dialect, (JavaTypeFactory) getCluster().getTypeFactory());
Project topProject;
if (getInput() instanceof Project) {
topProject = (Project) getInput();
} else {
// If it is not a project operator, we add it on top of the input
// to force generating the column names instead of * while
// translating to SQL
RelNode nodeToTranslate = getInput();
RexBuilder builder = getCluster().getRexBuilder();
List<RexNode> projects = new ArrayList<>(nodeToTranslate.getRowType().getFieldList().size());
for (int i = 0; i < nodeToTranslate.getRowType().getFieldCount(); i++) {
projects.add(builder.makeInputRef(nodeToTranslate, i));
}
topProject = new JdbcProject(nodeToTranslate.getCluster(), nodeToTranslate.getTraitSet(), nodeToTranslate, projects, nodeToTranslate.getRowType());
}
final HiveJdbcImplementor.Result result = jdbcImplementor.visitRoot(topProject);
return result.asStatement().toSqlString(dialect).getSql();
}
Aggregations