本文整理汇总了Java中org.apache.calcite.plan.RelOptUtil.conjunctions方法的典型用法代码示例。如果您正苦于以下问题:Java RelOptUtil.conjunctions方法的具体用法?Java RelOptUtil.conjunctions怎么用?Java RelOptUtil.conjunctions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.plan.RelOptUtil
的用法示例。
在下文中一共展示了RelOptUtil.conjunctions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildJoinConditions
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
* Build the list of join conditions for this join.
* A join condition is built only for equality and IS NOT DISTINCT FROM comparisons. The difference is:
* null == null is FALSE whereas null IS NOT DISTINCT FROM null is TRUE
* For a use case of the IS NOT DISTINCT FROM comparison, see
* {@link org.apache.calcite.rel.rules.RemoveDistinctAggregateRule}
* @param conditions populated list of join conditions
* @param leftFields join fields from the left input
* @param rightFields join fields from the right input
*/
protected void buildJoinConditions(List<JoinCondition> conditions,
List<String> leftFields,
List<String> rightFields,
List<Integer> leftKeys,
List<Integer> rightKeys) {
List<RexNode> conjuncts = RelOptUtil.conjunctions(this.getCondition());
short i=0;
for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
final RexNode conditionExpr = conjuncts.get(i++);
final SqlKind kind = conditionExpr.getKind();
if (kind != SqlKind.EQUALS && kind != SqlKind.IS_NOT_DISTINCT_FROM) {
throw UserException.unsupportedError()
.message("Unsupported comparator in join condition %s", conditionExpr)
.build(logger);
}
conditions.add(new JoinCondition(kind.toString(),
FieldReference.getWithQuotedRef(leftFields.get(pair.left)),
FieldReference.getWithQuotedRef(rightFields.get(pair.right))));
}
}
示例2: populate
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
private static boolean populate(List<RelNode> nodes, List<int[][]> tempLinks,
RelNode rel) {
if (nodes.isEmpty() && rel instanceof LogicalProject) {
return populate(nodes, tempLinks, ((LogicalProject) rel).getInput());
}
if (rel instanceof TableScan) {
nodes.add(rel);
return true;
}
if (rel instanceof LogicalJoin) {
LogicalJoin join = (LogicalJoin) rel;
if (join.getJoinType() != JoinRelType.INNER) {
throw new RuntimeException("only inner join allowed, but got "
+ join.getJoinType());
}
populate(nodes, tempLinks, join.getLeft());
populate(nodes, tempLinks, join.getRight());
for (RexNode rex : RelOptUtil.conjunctions(join.getCondition())) {
tempLinks.add(grab(nodes, rex));
}
return true;
}
throw new RuntimeException("Invalid node type "
+ rel.getClass().getSimpleName() + " in lattice query");
}
示例3: createExpressions
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
private static void createExpressions(RexBuilder rexBuilder,
RexNode expr, ImmutableBitSet predFieldsUsed, Map<RexInputRef, Set<RexNode>> mapping,
Map<RexInputRef, RexNode> singleMapping, Set<RexNode> result) {
if (mapping.isEmpty()) {
final RexReplacer replacer = new RexReplacer(singleMapping);
final List<RexNode> updatedPreds = new ArrayList<>(
RelOptUtil.conjunctions(
rexBuilder.copy(expr)));
replacer.mutate(updatedPreds);
result.addAll(updatedPreds);
} else {
result.addAll(
createAllPossibleExpressions(
rexBuilder, expr, predFieldsUsed, mapping, singleMapping));
}
}
示例4: unionPreds
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的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);
}
示例5: minusPreds
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的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);
}
示例6: infer
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
private void infer(RexNode predicates, Set<String> allExprsDigests,
List<RexNode> inferedPredicates, boolean includeEqualityInference,
ImmutableBitSet inferringFields) {
for (RexNode r : RelOptUtil.conjunctions(predicates)) {
if (!includeEqualityInference
&& equalityPredicates.contains(r.toString())) {
continue;
}
for (Mapping m : mappings(r)) {
RexNode tr = r.accept(
new RexPermuteInputsShuttle(m, joinRel.getInput(0),
joinRel.getInput(1)));
if (inferringFields.contains(RelOptUtil.InputFinder.bits(tr))
&& !allExprsDigests.contains(tr.toString())
&& !isAlwaysTrue(tr)) {
inferedPredicates.add(tr);
allExprsDigests.add(tr.toString());
}
}
}
}
示例7: buildJoinConditions
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
* Build the list of join conditions for this join.
* A join condition is built only for equality and IS NOT DISTINCT FROM comparisons. The difference is:
* null == null is FALSE whereas null IS NOT DISTINCT FROM null is TRUE
* For a use case of the IS NOT DISTINCT FROM comparison, see
* {@link org.apache.calcite.rel.rules.RemoveDistinctAggregateRule}
* @param conditions populated list of join conditions
* @param leftFields join fields from the left input
* @param rightFields join fields from the right input
*/
protected void buildJoinConditions(List<JoinCondition> conditions,
List<String> leftFields,
List<String> rightFields,
List<Integer> leftKeys,
List<Integer> rightKeys) {
List<RexNode> conjuncts = RelOptUtil.conjunctions(this.getCondition());
short i=0;
RexNode comp1 = null, comp2 = null;
for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
if (comp1 == null) {
comp1 = conjuncts.get(i++);
if ( ! (comp1.getKind() == SqlKind.EQUALS || comp1.getKind() == SqlKind.IS_NOT_DISTINCT_FROM)) {
throw new IllegalArgumentException("This type of join only supports '=' and 'is not distinct from' comparators.");
}
} else {
comp2 = conjuncts.get(i++);
if (comp1.getKind() != comp2.getKind()) {
// it does not seem necessary at this time to support join conditions which have mixed comparators - e.g
// 'a1 = a2 AND b1 IS NOT DISTINCT FROM b2'
String msg = String.format("This type of join does not support mixed comparators: '%s' and '%s'.", comp1, comp2);
throw new IllegalArgumentException(msg);
}
}
conditions.add(new JoinCondition(comp1.getKind().toString(), FieldReference.getWithQuotedRef(leftFields.get(pair.left)),
FieldReference.getWithQuotedRef(rightFields.get(pair.right))));
}
}
示例8: filterAggregateTranspose
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
* Pushes a {@link org.apache.calcite.rel.core.Filter}
* past a {@link org.apache.calcite.rel.core.Aggregate}.
*/
RelNode filterAggregateTranspose(RelOptRuleCall call,
Filter filterRel,
Aggregate aggRel) {
final List<RexNode> conditions =
RelOptUtil.conjunctions(filterRel.getCondition());
final RexBuilder rexBuilder = filterRel.getCluster().getRexBuilder();
final List<RelDataTypeField> origFields =
aggRel.getRowType().getFieldList();
final int[] adjustments = new int[origFields.size()];
int i = 0;
for (int key : aggRel.getGroupSet()) {
adjustments[i] = key - i;
i++;
}
final List<RexNode> pushedConditions = Lists.newArrayList();
for (RexNode condition : conditions) {
ImmutableBitSet rCols = RelOptUtil.InputFinder.bits(condition);
if (canPush(aggRel, rCols)) {
pushedConditions.add(
condition.accept(
new RelOptUtil.RexInputConverter(rexBuilder, origFields,
aggRel.getInput(0).getRowType().getFieldList(),
adjustments)));
} else {
return null;
}
}
final RelBuilder builder = call.builder();
RelNode rel =
builder.push(aggRel.getInput()).filter(pushedConditions).build();
if (rel == aggRel.getInput(0)) {
return null;
}
rel = aggRel.copy(aggRel.getTraitSet(), ImmutableList.of(rel));
return rel;
}
示例9: split
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
* Splits a condition into conjunctions that do or do not intersect with
* a given bit set.
*/
static void split(RexNode condition, ImmutableBitSet bitSet, List<RexNode> intersecting, List<RexNode> nonIntersecting) {
for (RexNode node : RelOptUtil.conjunctions(condition)) {
ImmutableBitSet inputBitSet = RelOptUtil.InputFinder.bits(node);
if (bitSet.intersects(inputBitSet)) {
intersecting.add(node);
} else {
nonIntersecting.add(node);
}
}
}
示例10: translateAnd
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/** Translate a conjunctive predicate to a CQL string.
*
* @param condition A conjunctive predicate
* @return CQL string for the predicate
*/
private String translateAnd(RexNode condition) {
List<String> predicates = new ArrayList<String>();
for (RexNode node : RelOptUtil.conjunctions(condition)) {
predicates.add(translateMatch2(node));
}
return Util.toString(predicates, "", " AND ", "");
}
示例11: matches
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
@Override public boolean matches(RelOptRuleCall call) {
// Get the condition from the filter operation
LogicalFilter filter = call.rel(0);
RexNode condition = filter.getCondition();
// Get field names from the scan operation
CassandraTableScan scan = call.rel(1);
Pair<List<String>, List<String>> keyFields = scan.cassandraTable.getKeyFields();
Set<String> partitionKeys = new HashSet<String>(keyFields.left);
List<String> fieldNames = CassandraRules.cassandraFieldNames(filter.getInput().getRowType());
List<RexNode> disjunctions = RelOptUtil.disjunctions(condition);
if (disjunctions.size() != 1) {
return false;
} else {
// Check that all conjunctions are primary key equalities
condition = disjunctions.get(0);
for (RexNode predicate : RelOptUtil.conjunctions(condition)) {
if (!isEqualityOnKey(predicate, fieldNames, partitionKeys, keyFields.right)) {
return false;
}
}
}
// Either all of the partition keys must be specified or none
return partitionKeys.size() == keyFields.left.size() || partitionKeys.size() == 0;
}
示例12: getPigFilterStatement
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
* Generates Pig Latin filtering statements, for example
*
* <blockquote>
* <pre>table = FILTER table BY score > 2.0;</pre>
* </blockquote>
*/
private String getPigFilterStatement(Implementor implementor) {
Preconditions.checkState(containsOnlyConjunctions(condition));
String relationAlias = implementor.getPigRelationAlias(this);
List<String> filterConditionsConjunction = new ArrayList<>();
for (RexNode node : RelOptUtil.conjunctions(condition)) {
filterConditionsConjunction.add(getSingleFilterCondition(implementor, node));
}
String allFilterConditions = Joiner.on(" AND ").join(filterConditionsConjunction);
return relationAlias + " = FILTER " + relationAlias + " BY " + allFilterConditions + ';';
}
示例13: guessSelectivity
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
* Returns default estimates for selectivities, in the absence of stats.
*
* @param predicate predicate for which selectivity will be computed;
* null means true, so gives selectity of 1.0
* @param artificialOnly return only the selectivity contribution from
* artificial nodes
* @return estimated selectivity
*/
public static double guessSelectivity(
RexNode predicate,
boolean artificialOnly) {
double sel = 1.0;
if ((predicate == null) || predicate.isAlwaysTrue()) {
return sel;
}
double artificialSel = 1.0;
for (RexNode pred : RelOptUtil.conjunctions(predicate)) {
if (pred.getKind() == SqlKind.IS_NOT_NULL) {
sel *= .9;
} else if (
(pred instanceof RexCall)
&& (((RexCall) pred).getOperator()
== RelMdUtil.ARTIFICIAL_SELECTIVITY_FUNC)) {
artificialSel *= RelMdUtil.getSelectivityValue(pred);
} else if (pred.isA(SqlKind.EQUALS)) {
sel *= .15;
} else if (pred.isA(SqlKind.COMPARISON)) {
sel *= .5;
} else {
sel *= .25;
}
}
if (artificialOnly) {
return artificialSel;
} else {
return sel * artificialSel;
}
}
示例14: split
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
* Splits a condition into conjunctions that do or do not intersect with
* a given bit set.
*/
static void split(
RexNode condition,
ImmutableBitSet bitSet,
List<RexNode> intersecting,
List<RexNode> nonIntersecting) {
for (RexNode node : RelOptUtil.conjunctions(condition)) {
ImmutableBitSet inputBitSet = RelOptUtil.InputFinder.bits(node);
if (bitSet.intersects(inputBitSet)) {
intersecting.add(node);
} else {
nonIntersecting.add(node);
}
}
}
示例15: commonFactors
import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
private Map<String, RexNode> commonFactors(List<RexNode> nodes) {
final Map<String, RexNode> map = Maps.newHashMap();
int i = 0;
for (RexNode node : nodes) {
if (i++ == 0) {
for (RexNode conjunction : RelOptUtil.conjunctions(node)) {
map.put(conjunction.toString(), conjunction);
}
} else {
map.keySet().retainAll(strings(RelOptUtil.conjunctions(node)));
}
}
return map;
}