private List<RexNode> rewriteInClauseChildren(SqlOperator op, List<RexNode> childRexNodeLst) throws SemanticException { assert op.getKind() == SqlKind.IN; RexNode firstPred = childRexNodeLst.get(0); List<RexNode> newChildRexNodeLst = new ArrayList<RexNode>(); for (int i = 1; i < childRexNodeLst.size(); i++) { newChildRexNodeLst.add( cluster.getRexBuilder().makeCall( SqlStdOperatorTable.EQUALS, firstPred, childRexNodeLst.get(i))); } return newChildRexNodeLst; }
@Override public Void visitCall(RexCall call) { if (call.getOperator().getKind() == SqlKind.EQUALS) { int lPos = pos(call.getOperands().get(0)); int rPos = pos(call.getOperands().get(1)); if (lPos != -1 && rPos != -1) { JoinConditionBasedPredicateInference.this.equivalent(lPos, rPos); JoinConditionBasedPredicateInference.this.equalityPredicates .add(call.toString()); } } return null; } }
private boolean isRexLiteral(final RexNode rexNode) { if(rexNode instanceof RexLiteral) { return true; } else if(rexNode instanceof RexCall && ((RexCall)rexNode).getOperator().getKind() == SqlKind.CAST){ return isRexLiteral(((RexCall)(rexNode)).getOperands().get(0)); } else { return false; } }
@Override public Void visitCall(RexCall call) { if (call.getOperator().getKind() == SqlKind.EQUALS) { int lPos = pos(call.getOperands().get(0)); int rPos = pos(call.getOperands().get(1)); if (lPos != -1 && rPos != -1) { JoinConditionBasedPredicateInference.this.equivalent(lPos, rPos); JoinConditionBasedPredicateInference.this.equalityPredicates .add(call.toString()); } } return null; } }
private boolean isAlwaysTrue(RexNode predicate) { if (predicate instanceof RexCall) { RexCall c = (RexCall) predicate; if (c.getOperator().getKind() == SqlKind.EQUALS) { int lPos = pos(c.getOperands().get(0)); int rPos = pos(c.getOperands().get(1)); return lPos != -1 && lPos == rPos; } } return predicate.isAlwaysTrue(); } }
private boolean hasCastExpression(RexNode condition) { if (condition instanceof RexCall) { if (((RexCall) condition).getOperator().getKind() == SqlKind.CAST) { return true; } for (RexNode op : ((RexCall) condition).getOperands()) { if (hasCastExpression(op)) { return true; } } } return false; } /*
public AliasedOperatorConversion(final SqlOperatorConversion baseConversion, final String name) { if (!SqlKind.FUNCTION.contains(baseConversion.calciteOperator().getKind())) { throw new IAE("Base operator must be a function but was[%s]", baseConversion.calciteOperator().getKind()); } final SqlFunction baseFunction = (SqlFunction) baseConversion.calciteOperator(); this.baseConversion = baseConversion; this.name = name; this.operator = new SqlFunction( name, baseFunction.getKind(), baseFunction.getReturnTypeInference(), baseFunction.getOperandTypeInference(), baseFunction.getOperandTypeChecker(), baseFunction.getFunctionType() ); }
if (condition instanceof RexCall) { RexCall call = (RexCall) condition; if (call.getOperator().getKind() == SqlKind.AND) { for (RexNode operand : call.getOperands()) { splitCorrelatedFilterCondition( if (call.getOperator().getKind() == SqlKind.EQUALS) { final List<RexNode> operands = call.getOperands(); RexNode op0 = operands.get(0);
private boolean isAlwaysTrue(RexNode predicate) { if (predicate instanceof RexCall) { RexCall c = (RexCall) predicate; if (c.getOperator().getKind() == SqlKind.EQUALS) { int lPos = pos(c.getOperands().get(0)); int rPos = pos(c.getOperands().get(1)); return lPos != -1 && lPos == rPos; } } return predicate.isAlwaysTrue(); } }
Preconditions.checkNotNull(right); switch (call.op.getKind()) { case PLUS: return new ConstantTupleFilter(left.add(right).toString());
switch (conjCall.getOperator().getKind()) { case EQUALS: if (!(RexUtil.isConstant(conjCall.operands.get(0))) &&
void translateJoinColumn(RexCall condition, Map<TblColRef, TblColRef> joinColumns) { SqlKind kind = condition.getOperator().getKind(); if (kind == SqlKind.AND) { for (RexNode operand : condition.getOperands()) { RexCall subCond = (RexCall) operand; translateJoinColumn(subCond, joinColumns); } } else if (kind == SqlKind.EQUALS) { List<RexNode> operands = condition.getOperands(); RexInputRef op0 = (RexInputRef) operands.get(0); TblColRef col0 = columnRowType.getColumnByIndex(op0.getIndex()); RexInputRef op1 = (RexInputRef) operands.get(1); TblColRef col1 = columnRowType.getColumnByIndex(op1.getIndex()); // map left => right if (op0.getIndex() < columnRowTypeLeftRightCut) joinColumns.put(col0, col1); else joinColumns.put(col1, col0); } }
private SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope) { if (node instanceof SqlIdentifier && scope instanceof DelegatingScope) { final SqlIdentifier id = (SqlIdentifier) node; final DelegatingScope idScope = (DelegatingScope) ((DelegatingScope) scope).getParent(); return getNamespace(id, idScope); } else if (node instanceof SqlCall) { // Handle extended identifiers. final SqlCall call = (SqlCall) node; switch (call.getOperator().getKind()) { case EXTEND: final SqlIdentifier id = (SqlIdentifier) call.getOperandList().get(0); final DelegatingScope idScope = (DelegatingScope) scope; return getNamespace(id, idScope); case AS: final SqlNode nested = call.getOperandList().get(0); switch (nested.getKind()) { case EXTEND: return getNamespace(nested, scope); } break; } } return getNamespace(node); }
if (hiveUdf == null) { throw new RuntimeException("Cannot find UDF for " + call.getType() + " " + call.getOperator() + "[" + call.getOperator().getKind() + "]/" + args.size());
/** * Interprets argument as a constraint; if not possible returns null. */ public static Constraint of(RexNode n) { if (!(n instanceof RexCall)) { return null; } RexCall call = (RexCall) n; if (call.getOperator().getKind() != SqlKind.EQUALS) { return null; } RexNode opA = call.operands.get(0); RexNode opB = call.operands.get(1); if (RexUtil.isNull(opA) || RexUtil.isNull(opB)) { // dont try to compare nulls return null; } if (isConstExpr(opA) && isColumnExpr(opB)) { return new Constraint(opB, opA); } if (isColumnExpr(opA) && isConstExpr(opB)) { return new Constraint(opA, opB); } return null; }
private RexNode convertToStatsCondition(RexNode condition, IndexDescriptor index, IndexCallContext context, RelNode scanRel, List<SqlKind>typesToProcess) { RexBuilder builder = scanRel.getCluster().getRexBuilder(); if (condition.getKind() == SqlKind.AND) { final List<RexNode> conditions = Lists.newArrayList(); for(RexNode pred : RelOptUtil.conjunctions(condition)) { conditions.add(convertToStatsCondition(pred, index, context, scanRel, typesToProcess)); } return RexUtil.composeConjunction(builder, conditions, false); } else if (condition.getKind() == SqlKind.OR) { final List<RexNode> conditions = Lists.newArrayList(); for(RexNode pred : RelOptUtil.disjunctions(condition)) { conditions.add(convertToStatsCondition(pred, index, context, scanRel, typesToProcess)); } return RexUtil.composeDisjunction(builder, conditions, false); } else if (condition instanceof RexCall) { // LIKE operator - convert to a RANGE predicate, if possible if (typesToProcess.contains(SqlKind.LIKE) && ((RexCall) condition).getOperator().getKind() == SqlKind.LIKE) { return convertLikeToRange((RexCall)condition, builder); } else if (typesToProcess.contains(SqlKind.CAST) && hasCastExpression(condition)) { return convertCastForFIdx(((RexCall) condition), index, context, scanRel); } else { return condition; } } return condition; }
switch (op.getKind()) { case PLUS: tupleExpression = getBinaryTupleExpression(call, TupleExpression.ExpressionOperatorEnum.PLUS);
switch (conjCall.getOperator().getKind()) { case EQUALS: if (!(RexUtil.isConstant(conjCall.operands.get(0))) &&