use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode in project hive by apache.
the class SubstitutionVisitor method splitFilter.
/**
* Maps a condition onto a target.
*
* <p>If condition is stronger than target, returns the residue.
* If it is equal to target, returns the expression that evaluates to
* the constant {@code true}. If it is weaker than target, returns
* {@code null}.</p>
*
* <p>The terms satisfy the relation</p>
*
* <pre>
* {@code condition = target AND residue}
* </pre>
*
* <p>and {@code residue} must be as weak as possible.</p>
*
* <p>Example #1: condition stronger than target</p>
* <ul>
* <li>condition: x = 1 AND y = 2</li>
* <li>target: x = 1</li>
* <li>residue: y = 2</li>
* </ul>
*
* <p>Note that residue {@code x > 0 AND y = 2} would also satisfy the
* relation {@code condition = target AND residue} but is stronger than
* necessary, so we prefer {@code y = 2}.</p>
*
* <p>Example #2: target weaker than condition (valid, but not currently
* implemented)</p>
* <ul>
* <li>condition: x = 1</li>
* <li>target: x = 1 OR z = 3</li>
* <li>residue: NOT (z = 3)</li>
* </ul>
*
* <p>Example #3: condition and target are equivalent</p>
* <ul>
* <li>condition: x = 1 AND y = 2</li>
* <li>target: y = 2 AND x = 1</li>
* <li>residue: TRUE</li>
* </ul>
*
* <p>Example #4: condition weaker than target</p>
* <ul>
* <li>condition: x = 1</li>
* <li>target: x = 1 AND y = 2</li>
* <li>residue: null (i.e. no match)</li>
* </ul>
*
* <p>There are many other possible examples. It amounts to solving
* whether {@code condition AND NOT target} can ever evaluate to
* true, and therefore is a form of the NP-complete
* <a href="http://en.wikipedia.org/wiki/Satisfiability">Satisfiability</a>
* problem.</p>
*/
@VisibleForTesting
public static RexNode splitFilter(final RexBuilder rexBuilder, RexNode condition, RexNode target) {
// First, try splitting into ORs.
// Given target c1 OR c2 OR c3 OR c4
// and condition c2 OR c4
// residue is NOT c1 AND NOT c3
// Also deals with case target [x] condition [x] yields residue [true].
RexNode z = splitOr(rexBuilder, condition, target);
if (z != null) {
return z;
}
RexNode x = andNot(rexBuilder, target, condition);
if (mayBeSatisfiable(x)) {
RexNode x2 = andNot(rexBuilder, condition, target);
return simplify(rexBuilder, x2);
}
return null;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode in project hive by apache.
the class HiveFilterJoinRule method validateJoinFilters.
/*
* Any predicates pushed down to joinFilters that aren't equality conditions:
* put them back as aboveFilters because Hive doesn't support not equi join
* conditions.
*/
@Override
protected void validateJoinFilters(List<RexNode> aboveFilters, List<RexNode> joinFilters, Join join, JoinRelType joinType) {
if (joinType.equals(JoinRelType.INNER)) {
ListIterator<RexNode> filterIter = joinFilters.listIterator();
while (filterIter.hasNext()) {
RexNode exp = filterIter.next();
if (exp instanceof RexCall) {
RexCall c = (RexCall) exp;
boolean validHiveJoinFilter = false;
if ((c.getOperator().getKind() == SqlKind.EQUALS)) {
validHiveJoinFilter = true;
for (RexNode rn : c.getOperands()) {
// (r1.x +r2.x)=(r1.y+r2.y) on join condition.
if (filterRefersToBothSidesOfJoin(rn, join)) {
validHiveJoinFilter = false;
break;
}
}
} else if ((c.getOperator().getKind() == SqlKind.LESS_THAN) || (c.getOperator().getKind() == SqlKind.GREATER_THAN) || (c.getOperator().getKind() == SqlKind.LESS_THAN_OR_EQUAL) || (c.getOperator().getKind() == SqlKind.GREATER_THAN_OR_EQUAL)) {
validHiveJoinFilter = true;
// r2.x) on join condition.
if (filterRefersToBothSidesOfJoin(c, join)) {
validHiveJoinFilter = false;
}
}
if (validHiveJoinFilter)
continue;
}
aboveFilters.add(exp);
filterIter.remove();
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode in project hive by apache.
the class HiveSubQRemoveRelBuilder method projects.
private List<RexNode> projects(RelDataType inputRowType) {
final List<RexNode> exprList = new ArrayList<>();
for (RelDataTypeField field : inputRowType.getFieldList()) {
final RexBuilder rexBuilder = cluster.getRexBuilder();
exprList.add(rexBuilder.makeInputRef(field.getType(), field.getIndex()));
}
return exprList;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode in project hive by apache.
the class HiveOpConverter method createColInfos.
private static Pair<ArrayList<ColumnInfo>, Set<Integer>> createColInfos(List<RexNode> calciteExprs, List<ExprNodeDesc> hiveExprs, List<String> projNames, OpAttr inpOpAf) {
if (hiveExprs.size() != projNames.size()) {
throw new RuntimeException("Column expressions list doesn't match Column Names list");
}
RexNode rexN;
ExprNodeDesc pe;
ArrayList<ColumnInfo> colInfos = new ArrayList<ColumnInfo>();
boolean vc;
Set<Integer> newVColSet = new HashSet<Integer>();
for (int i = 0; i < hiveExprs.size(); i++) {
pe = hiveExprs.get(i);
rexN = calciteExprs.get(i);
vc = false;
if (rexN instanceof RexInputRef) {
if (inpOpAf.vcolsInCalcite.contains(((RexInputRef) rexN).getIndex())) {
newVColSet.add(i);
vc = true;
}
}
colInfos.add(new ColumnInfo(projNames.get(i), pe.getTypeInfo(), inpOpAf.tabAlias, vc));
}
return new Pair<ArrayList<ColumnInfo>, Set<Integer>>(colInfos, newVColSet);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode in project storm by apache.
the class TridentCalcRel method tridentPlan.
@Override
public void tridentPlan(TridentPlanCreator planCreator) throws Exception {
// SingleRel
RelNode input = getInput();
StormRelUtils.getStormRelInput(input).tridentPlan(planCreator);
Stream inputStream = planCreator.pop().toStream();
String stageName = StormRelUtils.getStageName(this);
RelDataType inputRowType = getInput(0).getRowType();
List<String> outputFieldNames = getRowType().getFieldNames();
int outputCount = outputFieldNames.size();
// filter
ExecutableExpression filterInstance = null;
RexLocalRef condition = program.getCondition();
if (condition != null) {
RexNode conditionNode = program.expandLocalRef(condition);
filterInstance = planCreator.createScalarInstance(Lists.newArrayList(conditionNode), inputRowType, StormRelUtils.getClassName(this));
}
// projection
ExecutableExpression projectionInstance = null;
List<RexLocalRef> projectList = program.getProjectList();
if (projectList != null && !projectList.isEmpty()) {
List<RexNode> expandedNodes = new ArrayList<>();
for (RexLocalRef project : projectList) {
expandedNodes.add(program.expandLocalRef(project));
}
projectionInstance = planCreator.createScalarInstance(expandedNodes, inputRowType, StormRelUtils.getClassName(this));
}
if (projectionInstance == null && filterInstance == null) {
// it shouldn't be happen
throw new IllegalStateException("Either projection or condition, or both should be provided.");
}
final Stream finalStream = inputStream.flatMap(new EvaluationCalc(filterInstance, projectionInstance, outputCount, planCreator.getDataContext()), new Fields(outputFieldNames)).name(stageName);
planCreator.addStream(finalStream);
}
Aggregations