当前位置: 首页>>代码示例>>Java>>正文


Java RelCollation.getFieldCollations方法代码示例

本文整理汇总了Java中org.apache.calcite.rel.RelCollation.getFieldCollations方法的典型用法代码示例。如果您正苦于以下问题:Java RelCollation.getFieldCollations方法的具体用法?Java RelCollation.getFieldCollations怎么用?Java RelCollation.getFieldCollations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.rel.RelCollation的用法示例。


在下文中一共展示了RelCollation.getFieldCollations方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: planSort

import org.apache.calcite.rel.RelCollation; //导入方法依赖的package包/类
private PlannerOp planSort(EnumerableSort op, RelDataType rowType) {
    PlannerOp input = convertRelNode(op.getInput(), rowType, false);
    RelCollation collation = op.getCollation();
    List<RelFieldCollation> fieldCollations = collation.getFieldCollations();
    boolean[] directions = new boolean[fieldCollations.size()];
    int[] fields = new int[fieldCollations.size()];
    int i = 0;
    for (RelFieldCollation col : fieldCollations) {
        RelFieldCollation.Direction direction = col.getDirection();
        int index = col.getFieldIndex();
        directions[i] = direction == RelFieldCollation.Direction.ASCENDING
            || direction == RelFieldCollation.Direction.STRICTLY_ASCENDING;
        fields[i++] = index;
    }
    return new SortOp(input, directions, fields);

}
 
开发者ID:diennea,项目名称:herddb,代码行数:18,代码来源:CalcitePlanner.java

示例2: rewriteRel

import org.apache.calcite.rel.RelCollation; //导入方法依赖的package包/类
public void rewriteRel(Sort rel) {
  RelCollation oldCollation = rel.getCollation();
  final RelNode oldChild = rel.getInput();
  final RelNode newChild = getNewForOldRel(oldChild);
  final Mappings.TargetMapping mapping =
      getNewForOldInputMapping(oldChild);

  // validate
  for (RelFieldCollation field : oldCollation.getFieldCollations()) {
    int oldInput = field.getFieldIndex();
    RelDataType sortFieldType =
        oldChild.getRowType().getFieldList().get(oldInput).getType();
    if (sortFieldType.isStruct()) {
      // TODO jvs 10-Feb-2005
      throw Util.needToImplement("sorting on structured types");
    }
  }
  RelCollation newCollation = RexUtil.apply(mapping, oldCollation);
  Sort newRel =
      LogicalSort.create(newChild, newCollation, rel.offset, rel.fetch);
  setNewForOldRel(rel, newRel);
}
 
开发者ID:apache,项目名称:calcite,代码行数:23,代码来源:RelStructuredTypeFlattener.java

示例3: fields

import org.apache.calcite.rel.RelCollation; //导入方法依赖的package包/类
/** Returns references to fields for a given collation. */
public ImmutableList<RexNode> fields(RelCollation collation) {
  final ImmutableList.Builder<RexNode> nodes = ImmutableList.builder();
  for (RelFieldCollation fieldCollation : collation.getFieldCollations()) {
    RexNode node = field(fieldCollation.getFieldIndex());
    switch (fieldCollation.direction) {
    case DESCENDING:
      node = desc(node);
    }
    switch (fieldCollation.nullDirection) {
    case FIRST:
      node = nullsFirst(node);
      break;
    case LAST:
      node = nullsLast(node);
      break;
    }
    nodes.add(node);
  }
  return nodes.build();
}
 
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:RelBuilder.java

示例4: getOperandMonotonicity

import org.apache.calcite.rel.RelCollation; //导入方法依赖的package包/类
@Override public SqlMonotonicity getOperandMonotonicity(int ordinal) {
  RexNode operand = operands.get(ordinal);

  if (operand instanceof RexInputRef) {
    for (RelCollation ic : inputCollations) {
      if (ic.getFieldCollations().isEmpty()) {
        continue;
      }

      for (RelFieldCollation rfc : ic.getFieldCollations()) {
        if (rfc.getFieldIndex() == ((RexInputRef) operand).getIndex()) {
          return rfc.direction.monotonicity();
          // TODO: Is it possible to have more than one RelFieldCollation for a RexInputRef?
        }
      }
    }
  } else if (operand instanceof RexCall) {
    final RexCallBinding binding =
        RexCallBinding.create(typeFactory, (RexCall) operand, inputCollations);
    return ((RexCall) operand).getOperator().getMonotonicity(binding);
  }

  return SqlMonotonicity.NOT_MONOTONIC;
}
 
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:RexCallBinding.java

示例5: convertRelCollation

import org.apache.calcite.rel.RelCollation; //导入方法依赖的package包/类
private RelCollation convertRelCollation(RelCollation src, Map<Integer, Integer> inToOut) {
  List<RelFieldCollation> newFields = Lists.newArrayList();

  for ( RelFieldCollation field : src.getFieldCollations()) {
    if (inToOut.containsKey(field.getFieldIndex())) {
      newFields.add(new RelFieldCollation(inToOut.get(field.getFieldIndex()), field.getDirection(), field.nullDirection));
    }
  }

  if (newFields.isEmpty()) {
    return RelCollationImpl.of();
  } else {
    return RelCollationImpl.of(newFields);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:16,代码来源:ProjectPrule.java

示例6: getOrdering

import org.apache.calcite.rel.RelCollation; //导入方法依赖的package包/类
public static List<Ordering> getOrdering(RelCollation collation, RelDataType rowType) {
  List<Ordering> orderExpr = Lists.newArrayList();

  final List<String> childFields = rowType.getFieldNames();

  for (RelFieldCollation fc: collation.getFieldCollations() ) {
    FieldReference fr = new FieldReference(childFields.get(fc.getFieldIndex()), ExpressionPosition.UNKNOWN, false);
    orderExpr.add(new Ordering(fc.getDirection(), fr, fc.nullDirection));
  }

  return orderExpr;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:13,代码来源:PrelUtil.java

示例7: getOrdering

import org.apache.calcite.rel.RelCollation; //导入方法依赖的package包/类
public static List<Ordering> getOrdering(RelCollation collation, RelDataType rowType) {
  List<Ordering> orderExpr = Lists.newArrayList();

  final List<String> childFields = rowType.getFieldNames();

  for (RelFieldCollation fc: collation.getFieldCollations() ) {
    FieldReference fr = new FieldReference(childFields.get(fc.getFieldIndex()), false);
    orderExpr.add(new Ordering(fc.getDirection(), fr, fc.nullDirection));
  }

  return orderExpr;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:13,代码来源:PrelUtil.java

示例8: collationsCompatible

import org.apache.calcite.rel.RelCollation; //导入方法依赖的package包/类
/** Check if it is possible to exploit native CQL sorting for a given collation.
 *
 * @return True if it is possible to achieve this sort in Cassandra
 */
private boolean collationsCompatible(RelCollation sortCollation,
    RelCollation implicitCollation) {
  List<RelFieldCollation> sortFieldCollations = sortCollation.getFieldCollations();
  List<RelFieldCollation> implicitFieldCollations = implicitCollation.getFieldCollations();

  if (sortFieldCollations.size() > implicitFieldCollations.size()) {
    return false;
  }
  if (sortFieldCollations.size() == 0) {
    return true;
  }

  // Check if we need to reverse the order of the implicit collation
  boolean reversed = reverseDirection(sortFieldCollations.get(0).getDirection())
      == implicitFieldCollations.get(0).getDirection();

  for (int i = 0; i < sortFieldCollations.size(); i++) {
    RelFieldCollation sorted = sortFieldCollations.get(i);
    RelFieldCollation implied = implicitFieldCollations.get(i);

    // Check that the fields being sorted match
    if (sorted.getFieldIndex() != implied.getFieldIndex()) {
      return false;
    }

    // Either all fields must be sorted in the same direction
    // or the opposite direction based on whether we decided
    // if the sort direction should be reversed above
    RelFieldCollation.Direction sortDirection = sorted.getDirection();
    RelFieldCollation.Direction implicitDirection = implied.getDirection();
    if ((!reversed && sortDirection != implicitDirection)
        || (reversed && reverseDirection(sortDirection) != implicitDirection)) {
      return false;
    }
  }

  return true;
}
 
开发者ID:apache,项目名称:calcite,代码行数:43,代码来源:CassandraRules.java

示例9: trimChild

import org.apache.calcite.rel.RelCollation; //导入方法依赖的package包/类
/**
 * Trims the fields of an input relational expression.
 *
 * @param rel        Relational expression
 * @param input      Input relational expression, whose fields to trim
 * @param fieldsUsed Bitmap of fields needed by the consumer
 * @return New relational expression and its field mapping
 */
protected TrimResult trimChild(
    RelNode rel,
    RelNode input,
    final ImmutableBitSet fieldsUsed,
    Set<RelDataTypeField> extraFields) {
  final ImmutableBitSet.Builder fieldsUsedBuilder = fieldsUsed.rebuild();

  // Fields that define the collation cannot be discarded.
  final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
  final ImmutableList<RelCollation> collations = mq.collations(input);
  for (RelCollation collation : collations) {
    for (RelFieldCollation fieldCollation : collation.getFieldCollations()) {
      fieldsUsedBuilder.set(fieldCollation.getFieldIndex());
    }
  }

  // Correlating variables are a means for other relational expressions to use
  // fields.
  for (final CorrelationId correlation : rel.getVariablesSet()) {
    rel.accept(
        new CorrelationReferenceFinder() {
          protected RexNode handle(RexFieldAccess fieldAccess) {
            final RexCorrelVariable v =
                (RexCorrelVariable) fieldAccess.getReferenceExpr();
            if (v.id.equals(correlation)) {
              fieldsUsedBuilder.set(fieldAccess.getField().getIndex());
            }
            return fieldAccess;
          }
        });
  }

  return dispatchTrimFields(input, fieldsUsedBuilder.build(), extraFields);
}
 
开发者ID:apache,项目名称:calcite,代码行数:43,代码来源:RelFieldTrimmer.java

示例10: apply

import org.apache.calcite.rel.RelCollation; //导入方法依赖的package包/类
/**
 * Applies a mapping to a collation list.
 *
 * @param mapping       Mapping
 * @param collationList Collation list
 * @return collation list with mapping applied to each field
 */
public static List<RelCollation> apply(
    Mappings.TargetMapping mapping,
    List<RelCollation> collationList) {
  final List<RelCollation> newCollationList = new ArrayList<>();
  for (RelCollation collation : collationList) {
    final List<RelFieldCollation> newFieldCollationList = new ArrayList<>();
    for (RelFieldCollation fieldCollation
        : collation.getFieldCollations()) {
      final RelFieldCollation newFieldCollation =
          apply(mapping, fieldCollation);
      if (newFieldCollation == null) {
        // This field is not mapped. Stop here. The leading edge
        // of the collation is still valid (although it's useless
        // if it's empty).
        break;
      }
      newFieldCollationList.add(newFieldCollation);
    }
    // Truncation to collations to their leading edge creates empty
    // and duplicate collations. Ignore these.
    if (!newFieldCollationList.isEmpty()) {
      final RelCollation newCollation =
          RelCollations.of(newFieldCollationList);
      if (!newCollationList.contains(newCollation)) {
        newCollationList.add(newCollation);
      }
    }
  }

  // REVIEW: There might be redundant collations in the list. For example,
  // in {(x), (x, y)}, (x) is redundant because it is a leading edge of
  // another collation in the list. Could remove redundant collations.

  return newCollationList;
}
 
开发者ID:apache,项目名称:calcite,代码行数:43,代码来源:RexUtil.java


注:本文中的org.apache.calcite.rel.RelCollation.getFieldCollations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。