private List<RexNode> extractFilterPreds(Filter filterOp) { List<RexNode> conjs = new ArrayList<>(); for (RexNode r : HiveRelOptUtil.conjunctions(filterOp.getCondition())) { if (r.getKind() == SqlKind.IS_NOT_NULL) { RexCall isNotNullNode = (RexCall) r; if (RexUtil.isReferenceOrAccess(isNotNullNode.getOperands().get(0), true)) { ImmutableBitSet ref = RelOptUtil.InputFinder.bits(isNotNullNode); RelColumnOrigin co = mq.getColumnOrigin(filterOp, ref.nextSetBit(0)); if (co == null) { // We add it back conjs.add(r); continue; } RelOptHiveTable table = (RelOptHiveTable) co.getOriginTable(); List<ColStatistics> colStats = table.getColStat(ImmutableList.of(co.getOriginColumnOrdinal()), true); if (colStats == null || colStats.isEmpty() || colStats.get(0).getNumNulls() != 0) { // We add it back conjs.add(r); } } } else { conjs.add(r); } } return conjs; }
case LESS_THAN_OR_EQUAL: case GREATER_THAN_OR_EQUAL: if (rexBuilder != null && RexUtil.isReferenceOrAccess(call.operands.get(1), true) && RexUtil.isLiteral(call.operands.get(0), true)) {
if (!RexUtil.isReferenceOrAccess(eqOp1, true)) { if (!RexUtil.isReferenceOrAccess(eqOp2, true)) {
} else if (RexUtil.isReferenceOrAccess(childRexNodeLst.get(0), true)) {
/** * Returns whether a node represents an input reference or field access. * * @param node The node, never null. * @param allowCast whether to regard CAST(x) as true * @return Whether the node is a reference or access */ public static boolean isReferenceOrAccess(RexNode node, boolean allowCast) { assert node != null; if (node instanceof RexInputRef || node instanceof RexFieldAccess) { return true; } if (allowCast) { if (node.isA(SqlKind.CAST)) { RexCall call = (RexCall) node; return isReferenceOrAccess(call.operands.get(0), false); } } return false; }
/** * Returns whether a node represents an input reference or field access. * * @param node The node, never null. * @param allowCast whether to regard CAST(x) as true * @return Whether the node is a reference or access */ public static boolean isReferenceOrAccess(RexNode node, boolean allowCast) { assert node != null; if (node instanceof RexInputRef || node instanceof RexFieldAccess) { return true; } if (allowCast) { if (node.isA(SqlKind.CAST)) { RexCall call = (RexCall) node; return isReferenceOrAccess(call.operands.get(0), false); } } return false; }
private static boolean isLowerBound(final RexNode e) { final List<RexNode> operands; switch (e.getKind()) { case LESS_THAN: case LESS_THAN_OR_EQUAL: operands = ((RexCall) e).getOperands(); return RexUtil.isReferenceOrAccess(operands.get(1), true) && operands.get(0).isA(SqlKind.LITERAL); case GREATER_THAN: case GREATER_THAN_OR_EQUAL: operands = ((RexCall) e).getOperands(); return RexUtil.isReferenceOrAccess(operands.get(0), true) && operands.get(1).isA(SqlKind.LITERAL); default: return false; } }
private static boolean isUpperBound(final RexNode e) { final List<RexNode> operands; switch (e.getKind()) { case LESS_THAN: case LESS_THAN_OR_EQUAL: operands = ((RexCall) e).getOperands(); return RexUtil.isReferenceOrAccess(operands.get(0), true) && operands.get(1).isA(SqlKind.LITERAL); case GREATER_THAN: case GREATER_THAN_OR_EQUAL: operands = ((RexCall) e).getOperands(); return RexUtil.isReferenceOrAccess(operands.get(1), true) && operands.get(0).isA(SqlKind.LITERAL); default: return false; } }
private static boolean isUpperBound(final RexNode e) { final List<RexNode> operands; switch (e.getKind()) { case LESS_THAN: case LESS_THAN_OR_EQUAL: operands = ((RexCall) e).getOperands(); return RexUtil.isReferenceOrAccess(operands.get(0), true) && operands.get(1).isA(SqlKind.LITERAL); case GREATER_THAN: case GREATER_THAN_OR_EQUAL: operands = ((RexCall) e).getOperands(); return RexUtil.isReferenceOrAccess(operands.get(1), true) && operands.get(0).isA(SqlKind.LITERAL); default: return false; } }
private static boolean isLowerBound(final RexNode e) { final List<RexNode> operands; switch (e.getKind()) { case LESS_THAN: case LESS_THAN_OR_EQUAL: operands = ((RexCall) e).getOperands(); return RexUtil.isReferenceOrAccess(operands.get(1), true) && operands.get(0).isA(SqlKind.LITERAL); case GREATER_THAN: case GREATER_THAN_OR_EQUAL: operands = ((RexCall) e).getOperands(); return RexUtil.isReferenceOrAccess(operands.get(0), true) && operands.get(1).isA(SqlKind.LITERAL); default: return false; } }
/** Creates an IS predicate, or returns null. */ static IsPredicate of(RexNode e) { switch (e.getKind()) { case IS_NULL: case IS_NOT_NULL: RexNode pA = ((RexCall) e).getOperands().get(0); if (!RexUtil.isReferenceOrAccess(pA, true)) { return null; } return new IsPredicate(pA, e.getKind()); } return null; } }
/** Creates an IS predicate, or returns null. */ static IsPredicate of(RexNode e) { switch (e.getKind()) { case IS_NULL: case IS_NOT_NULL: RexNode pA = ((RexCall) e).getOperands().get(0); if (!RexUtil.isReferenceOrAccess(pA, true)) { return null; } return new IsPredicate(pA, e.getKind()); } return null; } }
private RexNode simplifyIsPredicate(SqlKind kind, RexNode a) { if (!RexUtil.isReferenceOrAccess(a, true)) { return null; } for (RexNode p : predicates.pulledUpPredicates) { IsPredicate pred = IsPredicate.of(p); if (pred == null || !a.toString().equals(pred.ref.toString())) { continue; } if (kind == pred.kind) { return rexBuilder.makeLiteral(true); } } return null; }
private RexNode simplifyIsPredicate(SqlKind kind, RexNode a) { if (!RexUtil.isReferenceOrAccess(a, true)) { return null; } for (RexNode p : predicates.pulledUpPredicates) { IsPredicate pred = IsPredicate.of(p); if (pred == null || !a.equals(pred.ref)) { continue; } if (kind == pred.kind) { return rexBuilder.makeLiteral(true); } } return null; }
case EQUALS: RexCall eqCall = (RexCall) e; if (RexUtil.isReferenceOrAccess(eqCall.getOperands().get(0), false) && RexUtil.isReferenceOrAccess(eqCall.getOperands().get(1), false)) { equiColumnsPreds.add(e); } else if ((RexUtil.isReferenceOrAccess(eqCall.getOperands().get(0), false) && RexUtil.isConstant(eqCall.getOperands().get(1))) || (RexUtil.isReferenceOrAccess(eqCall.getOperands().get(1), false) && RexUtil.isConstant(eqCall.getOperands().get(0)))) { rangePreds.add(e); case NOT_EQUALS: RexCall rangeCall = (RexCall) e; if ((RexUtil.isReferenceOrAccess(rangeCall.getOperands().get(0), false) && RexUtil.isConstant(rangeCall.getOperands().get(1))) || (RexUtil.isReferenceOrAccess(rangeCall.getOperands().get(1), false) && RexUtil.isConstant(rangeCall.getOperands().get(0)))) { rangePreds.add(e);
case EQUALS: RexCall eqCall = (RexCall) e; if (RexUtil.isReferenceOrAccess(eqCall.getOperands().get(0), false) && RexUtil.isReferenceOrAccess(eqCall.getOperands().get(1), false)) { equiColumnsPreds.add(e); } else if ((RexUtil.isReferenceOrAccess(eqCall.getOperands().get(0), false) && RexUtil.isConstant(eqCall.getOperands().get(1))) || (RexUtil.isReferenceOrAccess(eqCall.getOperands().get(1), false) && RexUtil.isConstant(eqCall.getOperands().get(0)))) { rangePreds.add(e); case NOT_EQUALS: RexCall rangeCall = (RexCall) e; if ((RexUtil.isReferenceOrAccess(rangeCall.getOperands().get(0), false) && RexUtil.isConstant(rangeCall.getOperands().get(1))) || (RexUtil.isReferenceOrAccess(rangeCall.getOperands().get(1), false) && RexUtil.isConstant(rangeCall.getOperands().get(0)))) { rangePreds.add(e);
/** Creates a comparison, or returns null. */ static Comparison of(RexNode e) { switch (e.getKind()) { case EQUALS: case NOT_EQUALS: case LESS_THAN: case GREATER_THAN: case LESS_THAN_OR_EQUAL: case GREATER_THAN_OR_EQUAL: final RexCall call = (RexCall) e; final RexNode left = call.getOperands().get(0); final RexNode right = call.getOperands().get(1); switch (right.getKind()) { case LITERAL: if (RexUtil.isReferenceOrAccess(left, true)) { return new Comparison(left, e.getKind(), (RexLiteral) right); } } switch (left.getKind()) { case LITERAL: if (RexUtil.isReferenceOrAccess(right, true)) { return new Comparison(right, e.getKind().reverse(), (RexLiteral) left); } } } return null; } }
/** Creates a comparison, or returns null. */ static Comparison of(RexNode e) { switch (e.getKind()) { case EQUALS: case NOT_EQUALS: case LESS_THAN: case GREATER_THAN: case LESS_THAN_OR_EQUAL: case GREATER_THAN_OR_EQUAL: final RexCall call = (RexCall) e; final RexNode left = call.getOperands().get(0); final RexNode right = call.getOperands().get(1); switch (right.getKind()) { case LITERAL: if (RexUtil.isReferenceOrAccess(left, true)) { return new Comparison(left, e.getKind(), (RexLiteral) right); } } switch (left.getKind()) { case LITERAL: if (RexUtil.isReferenceOrAccess(right, true)) { return new Comparison(right, e.getKind().reverse(), (RexLiteral) left); } } } return null; } }
return rexBuilder.makeLiteral(false); } else if (RexUtil.isReferenceOrAccess(left, true) && RexUtil.isReferenceOrAccess(right, true)) { equalityTerms.put(left, Pair.of(right, term));
return rexBuilder.makeLiteral(false); } else if (RexUtil.isReferenceOrAccess(left, true) && RexUtil.isReferenceOrAccess(right, true)) { equalityTerms.put(left.toString(), Pair.of(right.toString(), term));