本文整理汇总了Java中org.apache.calcite.rex.RexUtil类的典型用法代码示例。如果您正苦于以下问题:Java RexUtil类的具体用法?Java RexUtil怎么用?Java RexUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RexUtil类属于org.apache.calcite.rex包,在下文中一共展示了RexUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertCall
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/** Converts a {@link SqlCall} to a {@link RexCall} with a perhaps different
* operator. */
private RexNode convertCall(
SqlRexContext cx,
SqlCall call,
SqlOperator op) {
final List<SqlNode> operands = call.getOperandList();
final RexBuilder rexBuilder = cx.getRexBuilder();
final SqlOperandTypeChecker.Consistency consistency =
op.getOperandTypeChecker() == null
? SqlOperandTypeChecker.Consistency.NONE
: op.getOperandTypeChecker().getConsistency();
final List<RexNode> exprs =
convertExpressionList(cx, operands, consistency);
RelDataType type = rexBuilder.deriveReturnType(op, exprs);
return rexBuilder.makeCall(type, op, RexUtil.flatten(exprs, op));
}
示例2: convert
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
public static DrillJoinRel convert(Join join, ConversionContext context) throws InvalidRelException{
RelNode left = context.toRel(join.getLeft());
RelNode right = context.toRel(join.getRight());
List<RexNode> joinConditions = new ArrayList<RexNode>();
// right fields appear after the LHS fields.
final int rightInputOffset = left.getRowType().getFieldCount();
for (JoinCondition condition : join.getConditions()) {
RelDataTypeField leftField = left.getRowType().getField(ExprHelper.getFieldName(condition.getLeft()), true, false);
RelDataTypeField rightField = right.getRowType().getField(ExprHelper.getFieldName(condition.getRight()), true, false);
joinConditions.add(
context.getRexBuilder().makeCall(
SqlStdOperatorTable.EQUALS,
context.getRexBuilder().makeInputRef(leftField.getType(), leftField.getIndex()),
context.getRexBuilder().makeInputRef(rightField.getType(), rightInputOffset + rightField.getIndex())
)
);
}
RexNode rexCondition = RexUtil.composeConjunction(context.getRexBuilder(), joinConditions, false);
DrillJoinRel joinRel = new DrillJoinRel(context.getCluster(), context.getLogicalTraits(), left, right, rexCondition, join.getJoinType());
return joinRel;
}
示例3: addRenamedProject
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
protected DrillRel addRenamedProject(DrillRel rel, RelDataType validatedRowType) {
RelDataType t = rel.getRowType();
RexBuilder b = rel.getCluster().getRexBuilder();
List<RexNode> projections = Lists.newArrayList();
int projectCount = t.getFieldList().size();
for (int i =0; i < projectCount; i++) {
projections.add(b.makeInputRef(rel, i));
}
final List<String> fieldNames2 = SqlValidatorUtil.uniquify(validatedRowType.getFieldNames(), SqlValidatorUtil.F_SUGGESTER2);
RelDataType newRowType = RexUtil.createStructType(rel.getCluster().getTypeFactory(), projections, fieldNames2);
DrillProjectRel topProj = DrillProjectRel.create(rel.getCluster(), rel.getTraitSet(), rel, projections, newRowType);
// Add a final non-trivial Project to get the validatedRowType, if child is not project.
if (rel instanceof Project && DrillRelOptUtil.isTrivialProject(topProj, true)) {
return rel;
} else{
return topProj;
}
}
示例4: buildJoinCondition
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
private RexNode buildJoinCondition(RelNode convertedLeft, RelNode convertedRight, List<Integer> leftKeys,
List<Integer> rightKeys, List<Boolean> filterNulls, RexBuilder builder) {
List<RexNode> equijoinList = Lists.newArrayList();
final int numLeftFields = convertedLeft.getRowType().getFieldCount();
List<RelDataTypeField> leftTypes = convertedLeft.getRowType().getFieldList();
List<RelDataTypeField> rightTypes = convertedRight.getRowType().getFieldList();
for (int i=0; i < leftKeys.size(); i++) {
int leftKeyOrdinal = leftKeys.get(i).intValue();
int rightKeyOrdinal = rightKeys.get(i).intValue();
equijoinList.add(builder.makeCall(
filterNulls.get(i) ? SqlStdOperatorTable.EQUALS : SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
builder.makeInputRef(leftTypes.get(leftKeyOrdinal).getType(), leftKeyOrdinal),
builder.makeInputRef(rightTypes.get(rightKeyOrdinal).getType(), rightKeyOrdinal + numLeftFields)
));
}
return RexUtil.composeConjunction(builder, equijoinList, false);
}
示例5: convert
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
public static JoinRel convert(Join join, ConversionContext context) throws InvalidRelException{
RelNode left = context.toRel(join.getLeft());
RelNode right = context.toRel(join.getRight());
List<RexNode> joinConditions = new ArrayList<RexNode>();
// right fields appear after the LHS fields.
final int rightInputOffset = left.getRowType().getFieldCount();
for (JoinCondition condition : join.getConditions()) {
RelDataTypeField leftField = left.getRowType().getField(ExprHelper.getFieldName(condition.getLeft()), true, false);
RelDataTypeField rightField = right.getRowType().getField(ExprHelper.getFieldName(condition.getRight()), true, false);
joinConditions.add(
context.getRexBuilder().makeCall(
SqlStdOperatorTable.EQUALS,
context.getRexBuilder().makeInputRef(leftField.getType(), leftField.getIndex()),
context.getRexBuilder().makeInputRef(rightField.getType(), rightInputOffset + rightField.getIndex())
)
);
}
RexNode rexCondition = RexUtil.composeConjunction(context.getRexBuilder(), joinConditions, false);
JoinRel joinRel = new JoinRel(context.getCluster(), context.getLogicalTraits(), left, right, rexCondition, join.getJoinType());
return joinRel;
}
示例6: visit
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
private Prel visit(ExchangePrel hashPrel, List<DistributionTrait.DistributionField> fields, Prel child) {
final List<String> childFields = child.getRowType().getFieldNames();
// Insert Project SqlOperatorImpl with new column that will be a hash for HashToRandomExchange fields
final ProjectPrel addColumnprojectPrel = HashPrelUtil.addHashProject(fields, child, null);
final Prel newPrel = (Prel) hashPrel.copy(addColumnprojectPrel.getTraitSet(), Collections.<RelNode>singletonList(addColumnprojectPrel));
int validRows = newPrel.getRowType().getFieldCount() - 1;
final List<RelDataTypeField> all = newPrel.getRowType().getFieldList();
final List<RexNode> keptExprs = new ArrayList<>(validRows);
final RexBuilder rexBuilder = newPrel.getCluster().getRexBuilder();
for(int i = 0; i < validRows; i++){
RexNode rex = rexBuilder.makeInputRef(all.get(i).getType(), i);
keptExprs.add(rex);
}
// remove earlier inserted Project SqlOperatorImpl - since it creates issues down the road in HashJoin
RelDataType removeRowType = RexUtil.createStructType(newPrel.getCluster().getTypeFactory(), keptExprs, childFields);
return new ProjectPrel(newPrel.getCluster(), newPrel.getTraitSet(), newPrel, keptExprs, removeRowType);
}
示例7: insertProjUnderScreenOrWriter
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
private Prel insertProjUnderScreenOrWriter(Prel prel, RelDataType origRowType, Prel child) {
ProjectPrel proj = null;
List<RelNode> children = Lists.newArrayList();
List<RexNode> exprs = Lists.newArrayList();
for (int i = 0; i < origRowType.getFieldCount(); i++) {
RexNode expr = child.getCluster().getRexBuilder().makeInputRef(origRowType.getFieldList().get(i).getType(), i);
exprs.add(expr);
}
RelDataType newRowType = RexUtil.createStructType(child.getCluster().getTypeFactory(), exprs, origRowType.getFieldNames());
int fieldCount = prel.getRowType().isStruct()? prel.getRowType().getFieldCount():1;
// Insert PUS/PUW : remove the prefix and keep the original field name.
if (fieldCount > 1) { // // no point in allowing duplicates if we only have one column
proj = new ProjectAllowDupPrel(child.getCluster(), child.getTraitSet(), child, exprs, newRowType);
} else {
proj = new ProjectPrel(child.getCluster(), child.getTraitSet(), child, exprs, newRowType);
}
children.add(proj);
return (Prel) prel.copy(prel.getTraitSet(), children);
}
示例8: convertExpressionList
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
private static List<RexNode> convertExpressionList(SqlRexContext cx,
List<SqlNode> nodes, SqlOperandTypeChecker.Consistency consistency) {
final List<RexNode> exprs = Lists.newArrayList();
for (SqlNode node : nodes) {
exprs.add(cx.convertExpression(node));
}
if (exprs.size() > 1) {
final RelDataType type =
consistentType(cx, consistency, RexUtil.types(exprs));
if (type != null) {
final List<RexNode> oldExprs = Lists.newArrayList(exprs);
exprs.clear();
for (RexNode expr : oldExprs) {
exprs.add(cx.getRexBuilder().ensureType(type, expr, true));
}
}
}
return exprs;
}
示例9: convertUsing
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/**
* Returns an expression for matching columns of a USING clause or inferred
* from NATURAL JOIN. "a JOIN b USING (x, y)" becomes "a.x = b.x AND a.y =
* b.y". Returns null if the column list is empty.
*
* @param leftNamespace Namespace of left input to join
* @param rightNamespace Namespace of right input to join
* @param nameList List of column names to join on
* @return Expression to match columns from name list, or true if name list
* is empty
*/
private RexNode convertUsing(SqlValidatorNamespace leftNamespace,
SqlValidatorNamespace rightNamespace,
List<String> nameList) {
final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
final List<RexNode> list = Lists.newArrayList();
for (String name : nameList) {
List<RexNode> operands = new ArrayList<>();
int offset = 0;
for (SqlValidatorNamespace n : ImmutableList.of(leftNamespace,
rightNamespace)) {
final RelDataType rowType = n.getRowType();
final RelDataTypeField field = nameMatcher.field(rowType, name);
operands.add(
rexBuilder.makeInputRef(field.getType(),
offset + field.getIndex()));
offset += rowType.getFieldList().size();
}
list.add(rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, operands));
}
return RexUtil.composeConjunction(rexBuilder, list, false);
}
示例10: buildJoinCondition
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
private RexNode buildJoinCondition(RelNode convertedLeft, RelNode convertedRight, List<Integer> leftKeys,
List<Integer> rightKeys, List<Boolean> filterNulls, RexBuilder builder) {
List<RexNode> equijoinList = Lists.newArrayList();
final int numLeftFields = convertedLeft.getRowType().getFieldCount();
List<RelDataTypeField> leftTypes = convertedLeft.getRowType().getFieldList();
List<RelDataTypeField> rightTypes = convertedRight.getRowType().getFieldList();
for (int i=0; i < leftKeys.size(); i++) {
int leftKeyOrdinal = leftKeys.get(i).intValue();
int rightKeyOrdinal = rightKeys.get(i).intValue();
equijoinList.add(builder.makeCall(
filterNulls.get(i) ? SqlStdOperatorTable.EQUALS : SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
builder.makeInputRef(leftTypes.get(leftKeyOrdinal).getType(), leftKeyOrdinal),
builder.makeInputRef(rightTypes.get(rightKeyOrdinal).getType(), rightKeyOrdinal + numLeftFields)
));
}
return RexUtil.composeConjunction(builder, equijoinList, false);
}
示例11: convertUsing
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/**
* Returns an expression for matching columns of a USING clause or inferred
* from NATURAL JOIN. "a JOIN b USING (x, y)" becomes "a.x = b.x AND a.y =
* b.y". Returns null if the column list is empty.
*
* @param leftNamespace Namespace of left input to join
* @param rightNamespace Namespace of right input to join
* @param nameList List of column names to join on
* @return Expression to match columns from name list, or true if name list
* is empty
*/
private RexNode convertUsing(SqlValidatorNamespace leftNamespace,
SqlValidatorNamespace rightNamespace,
List<String> nameList) {
final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
final List<RexNode> list = Lists.newArrayList();
for (String name : nameList) {
List<RexNode> operands = new ArrayList<>();
int offset = 0;
for (SqlValidatorNamespace n : ImmutableList.of(leftNamespace,
rightNamespace)) {
final RelDataType rowType = n.getRowType();
final RelDataTypeField field = nameMatcher.field(rowType, name);
operands.add(
rexBuilder.makeInputRef(field.getType(),
offset + field.getIndex()));
offset += rowType.getFieldList().size();
}
list.add(rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, operands));
}
return RexUtil.composeConjunction(rexBuilder, list, false);
}
示例12: unionPreds
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/**
* AND's two predicates together, either of which may be null, removing
* redundant filters.
*
* @param rexBuilder rexBuilder used to construct AND'd RexNode
* @param pred1 first predicate
* @param pred2 second predicate
* @return AND'd predicate or individual predicates if one is null
*/
public static RexNode unionPreds(
RexBuilder rexBuilder,
RexNode pred1,
RexNode pred2) {
final List<RexNode> unionList = new ArrayList<>();
final Set<String> strings = new HashSet<>();
for (RexNode rex : RelOptUtil.conjunctions(pred1)) {
if (strings.add(rex.toString())) {
unionList.add(rex);
}
}
for (RexNode rex2 : RelOptUtil.conjunctions(pred2)) {
if (strings.add(rex2.toString())) {
unionList.add(rex2);
}
}
return RexUtil.composeConjunction(rexBuilder, unionList, true);
}
示例13: minusPreds
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/**
* Takes the difference between two predicates, removing from the first any
* predicates also in the second
*
* @param rexBuilder rexBuilder used to construct AND'd RexNode
* @param pred1 first predicate
* @param pred2 second predicate
* @return MINUS'd predicate list
*/
public static RexNode minusPreds(
RexBuilder rexBuilder,
RexNode pred1,
RexNode pred2) {
final List<RexNode> list1 = RelOptUtil.conjunctions(pred1);
final List<RexNode> list2 = RelOptUtil.conjunctions(pred2);
final List<RexNode> minusList = new ArrayList<>();
for (RexNode rex1 : list1) {
boolean add = true;
for (RexNode rex2 : list2) {
if (rex2.toString().compareTo(rex1.toString()) == 0) {
add = false;
break;
}
}
if (add) {
minusList.add(rex1);
}
}
return RexUtil.composeConjunction(rexBuilder, minusList, true);
}
示例14: getSelectivity
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
public Double getSelectivity(Aggregate rel, RelMetadataQuery mq,
RexNode predicate) {
final List<RexNode> notPushable = new ArrayList<>();
final List<RexNode> pushable = new ArrayList<>();
RelOptUtil.splitFilters(
rel.getGroupSet(),
predicate,
pushable,
notPushable);
final RexBuilder rexBuilder = rel.getCluster().getRexBuilder();
RexNode childPred =
RexUtil.composeConjunction(rexBuilder, pushable, true);
Double selectivity = mq.getSelectivity(rel.getInput(), childPred);
if (selectivity == null) {
return null;
} else {
RexNode pred =
RexUtil.composeConjunction(rexBuilder, notPushable, true);
return selectivity * RelMdUtil.guessSelectivity(pred);
}
}
示例15: getPredicates
import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/** Infers predicates for a {@link org.apache.calcite.rel.core.SemiJoin}. */
public RelOptPredicateList getPredicates(SemiJoin semiJoin,
RelMetadataQuery mq) {
RexBuilder rB = semiJoin.getCluster().getRexBuilder();
final RelNode left = semiJoin.getInput(0);
final RelNode right = semiJoin.getInput(1);
final RelOptPredicateList leftInfo = mq.getPulledUpPredicates(left);
final RelOptPredicateList rightInfo = mq.getPulledUpPredicates(right);
JoinConditionBasedPredicateInference jI =
new JoinConditionBasedPredicateInference(semiJoin,
RexUtil.composeConjunction(rB, leftInfo.pulledUpPredicates, false),
RexUtil.composeConjunction(rB, rightInfo.pulledUpPredicates, false));
return jI.inferPredicates(false);
}