本文整理了Java中org.apache.calcite.rel.RelFieldCollation.getFieldIndex
方法的一些代码示例,展示了RelFieldCollation.getFieldIndex
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RelFieldCollation.getFieldIndex
方法的具体详情如下:
包路径:org.apache.calcite.rel.RelFieldCollation
类名称:RelFieldCollation
方法名:getFieldIndex
暂无
代码示例来源:origin: apache/hive
/** 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();
}
代码示例来源:origin: apache/hive
public RelNode align(Aggregate rel, List<RelFieldCollation> collations) {
// 1) We extract the group by positions that are part of the collations and
// sort them so they respect it
LinkedHashSet<Integer> aggregateColumnsOrder = new LinkedHashSet<>();
ImmutableList.Builder<RelFieldCollation> propagateCollations = ImmutableList.builder();
if (rel.getGroupType() == Group.SIMPLE && !collations.isEmpty()) {
for (RelFieldCollation c : collations) {
if (c.getFieldIndex() < rel.getGroupCount()) {
// Group column found
if (aggregateColumnsOrder.add(c.getFieldIndex())) {
propagateCollations.add(c.copy(rel.getGroupSet().nth(c.getFieldIndex())));
}
}
}
}
for (int i = 0; i < rel.getGroupCount(); i++) {
if (!aggregateColumnsOrder.contains(i)) {
// Not included in the input collations, but can be propagated as this Aggregate
// will enforce it
propagateCollations.add(new RelFieldCollation(rel.getGroupSet().nth(i)));
}
}
// 2) We propagate
final RelNode child = dispatchAlign(rel.getInput(), propagateCollations.build());
// 3) We annotate the Aggregate operator with this info
final HiveAggregate newAggregate = (HiveAggregate) rel.copy(rel.getTraitSet(),
ImmutableList.of(child));
newAggregate.setAggregateColumnsOrder(aggregateColumnsOrder);
return newAggregate;
}
代码示例来源:origin: apache/hive
public RelNode align(Project rel, List<RelFieldCollation> collations) {
// 1) We extract the collations indices
boolean containsWindowing = false;
for (RexNode childExp : rel.getChildExps()) {
if (childExp instanceof RexOver) {
// TODO: support propagation for partitioning/ordering in windowing
containsWindowing = true;
break;
}
}
ImmutableList.Builder<RelFieldCollation> propagateCollations = ImmutableList.builder();
if (!containsWindowing) {
for (RelFieldCollation c : collations) {
RexNode rexNode = rel.getChildExps().get(c.getFieldIndex());
if (rexNode instanceof RexInputRef) {
int newIdx = ((RexInputRef) rexNode).getIndex();
propagateCollations.add(c.copy((newIdx)));
}
}
}
// 2) We propagate
final RelNode child = dispatchAlign(rel.getInput(), propagateCollations.build());
// 3) Return new Project
return rel.copy(rel.getTraitSet(), ImmutableList.of(child));
}
代码示例来源:origin: apache/hive
RexNode equals = idxToConjuncts.get(c.getFieldIndex());
if (equals != null) {
conjuncts.add(equals);
idxToConjuncts.remove(c.getFieldIndex());
idxToConjuncts.remove(refToRef.get(c.getFieldIndex()));
if (c.getFieldIndex() < nLeftColumns) {
propagateCollationsLeft.add(c.copy(c.getFieldIndex()));
propagateCollationsRight.add(c.copy(refToRef.get(c.getFieldIndex()) - nLeftColumns));
} else {
propagateCollationsLeft.add(c.copy(refToRef.get(c.getFieldIndex())));
propagateCollationsRight.add(c.copy(c.getFieldIndex() - nLeftColumns));
代码示例来源:origin: apache/drill
RexNode equals = idxToConjuncts.get(c.getFieldIndex());
if (equals != null) {
conjuncts.add(equals);
idxToConjuncts.remove(c.getFieldIndex());
idxToConjuncts.remove(refToRef.get(c.getFieldIndex()));
if (c.getFieldIndex() < nLeftColumns) {
propagateCollationsLeft.add(c.copy(c.getFieldIndex()));
propagateCollationsRight.add(c.copy(refToRef.get(c.getFieldIndex()) - nLeftColumns));
} else {
propagateCollationsLeft.add(c.copy(refToRef.get(c.getFieldIndex())));
propagateCollationsRight.add(c.copy(c.getFieldIndex() - nLeftColumns));
代码示例来源:origin: apache/drill
public RelNode align(Aggregate rel, List<RelFieldCollation> collations) {
// 1) We extract the group by positions that are part of the collations and
// sort them so they respect it
LinkedHashSet<Integer> aggregateColumnsOrder = new LinkedHashSet<>();
ImmutableList.Builder<RelFieldCollation> propagateCollations = ImmutableList.builder();
if (!rel.indicator && !collations.isEmpty()) {
for (RelFieldCollation c : collations) {
if (c.getFieldIndex() < rel.getGroupCount()) {
// Group column found
if (aggregateColumnsOrder.add(c.getFieldIndex())) {
propagateCollations.add(c.copy(rel.getGroupSet().nth(c.getFieldIndex())));
}
}
}
}
for (int i = 0; i < rel.getGroupCount(); i++) {
if (!aggregateColumnsOrder.contains(i)) {
// Not included in the input collations, but can be propagated as this Aggregate
// will enforce it
propagateCollations.add(new RelFieldCollation(rel.getGroupSet().nth(i)));
}
}
// 2) We propagate
final RelNode child = dispatchAlign(rel.getInput(), propagateCollations.build());
// 3) We annotate the Aggregate operator with this info
final HiveAggregate newAggregate = (HiveAggregate) rel.copy(rel.getTraitSet(),
ImmutableList.of(child));
newAggregate.setAggregateColumnsOrder(aggregateColumnsOrder);
return newAggregate;
}
代码示例来源:origin: apache/hive
Set<Integer> needed = new HashSet<>();
for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) {
needed.add(fc.getFieldIndex());
final RexNode node = project.getProjects().get(map.getTarget(fc.getFieldIndex()));
if (node.isA(SqlKind.CAST)) {
fieldCollations.add(new RelFieldCollation(m.get(fc.getFieldIndex()), fc.direction,
fc.nullDirection));
代码示例来源:origin: apache/hive
StringBuilder nullOrder = new StringBuilder();
for (RelFieldCollation sortInfo : sortRel.getCollation().getFieldCollations()) {
int sortColumnPos = sortInfo.getFieldIndex();
ColumnInfo columnInfo = new ColumnInfo(inputOp.getSchema().getSignature()
.get(sortColumnPos));
代码示例来源:origin: apache/hive
List<RelFieldCollation> fieldCollations = new ArrayList<>();
for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) {
final int target = mapping.getTargetOpt(fc.getFieldIndex());
if (target < 0) {
代码示例来源:origin: apache/drill
StringBuilder nullOrder = new StringBuilder();
for (RelFieldCollation sortInfo : sortRel.getCollation().getFieldCollations()) {
int sortColumnPos = sortInfo.getFieldIndex();
ColumnInfo columnInfo = new ColumnInfo(inputOp.getSchema().getSignature()
.get(sortColumnPos));
代码示例来源:origin: apache/kylin
@Override
public void implementRewrite(RewriteImplementor implementor) {
implementor.visitChild(this, getInput());
// No need to rewrite "order by" applied on non-olap context.
// Occurs in sub-query like "select ... from (...) inner join (...) order by ..."
if (this.context.realization == null)
return;
for (RelFieldCollation fieldCollation : this.collation.getFieldCollations()) {
int index = fieldCollation.getFieldIndex();
SQLDigest.OrderEnum order = getOrderEnum(fieldCollation.getDirection());
OLAPRel olapChild = (OLAPRel) this.getInput();
TblColRef orderCol = olapChild.getColumnRowType().getAllColumns().get(index);
this.context.addSort(orderCol, order);
this.context.storageContext.markSort();
}
this.rowType = this.deriveRowType();
this.columnRowType = buildColumnRowType();
}
代码示例来源:origin: apache/drill
List<RelFieldCollation> fieldCollations = new ArrayList<>();
for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) {
final int target = mapping.getTargetOpt(fc.getFieldIndex());
if (target < 0) {
代码示例来源:origin: apache/drill
/** 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();
}
代码示例来源:origin: apache/drill
public RelNode align(Project rel, List<RelFieldCollation> collations) {
// 1) We extract the collations indices
boolean containsWindowing = false;
for (RexNode childExp : rel.getChildExps()) {
if (childExp instanceof RexOver) {
// TODO: support propagation for partitioning/ordering in windowing
containsWindowing = true;
break;
}
}
ImmutableList.Builder<RelFieldCollation> propagateCollations = ImmutableList.builder();
if (!containsWindowing) {
for (RelFieldCollation c : collations) {
RexNode rexNode = rel.getChildExps().get(c.getFieldIndex());
if (rexNode instanceof RexInputRef) {
int newIdx = ((RexInputRef) rexNode).getIndex();
propagateCollations.add(c.copy((newIdx)));
}
}
}
// 2) We propagate
final RelNode child = dispatchAlign(rel.getInput(), propagateCollations.build());
// 3) Return new Project
return rel.copy(rel.getTraitSet(), ImmutableList.of(child));
}
代码示例来源:origin: apache/hive
obExpr = obRefToCallMap.get(c.getFieldIndex());
ColumnInfo cI = schema.get(c.getFieldIndex());
代码示例来源:origin: apache/drill
obExpr = obRefToCallMap.get(c.getFieldIndex());
ColumnInfo cI = schema.get(c.getFieldIndex());
代码示例来源:origin: apache/hive
for (RelFieldCollation relFieldCollation
: sortLimit.getCollation().getFieldCollations()) {
if (relFieldCollation.getFieldIndex()
>= join.getLeft().getRowType().getFieldCount()) {
return false;
for (RelFieldCollation relFieldCollation
: sortLimit.getCollation().getFieldCollations()) {
if (relFieldCollation.getFieldIndex()
< join.getLeft().getRowType().getFieldCount()) {
return false;
代码示例来源:origin: apache/drill
for (RelFieldCollation relFieldCollation
: sortLimit.getCollation().getFieldCollations()) {
if (relFieldCollation.getFieldIndex()
>= join.getLeft().getRowType().getFieldCount()) {
return false;
for (RelFieldCollation relFieldCollation
: sortLimit.getCollation().getFieldCollations()) {
if (relFieldCollation.getFieldIndex()
< join.getLeft().getRowType().getFieldCount()) {
return false;
代码示例来源:origin: apache/drill
public void onMatch(RelOptRuleCall call) {
final HiveSortLimit sort = call.rel(0);
final HiveProject project = call.rel(1);
// Determine mapping between project input and output fields. If sort
// relies on non-trivial expressions, we can't push.
final Mappings.TargetMapping map =
RelOptUtil.permutation(
project.getProjects(), project.getInput().getRowType());
for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) {
if (map.getTargetOpt(fc.getFieldIndex()) < 0) {
return;
}
}
// Create new collation
final RelCollation newCollation =
RelCollationTraitDef.INSTANCE.canonize(
RexUtil.apply(map, sort.getCollation()));
// New operators
final HiveSortLimit newSort = sort.copy(sort.getTraitSet().replace(newCollation),
project.getInput(), newCollation, sort.offset, sort.fetch);
final RelNode newProject = project.copy(sort.getTraitSet(),
ImmutableList.<RelNode>of(newSort));
call.transformTo(newProject);
}
代码示例来源:origin: apache/drill
public void onMatch(RelOptRuleCall call) {
final HiveProject project = call.rel(0);
final HiveSortLimit sort = call.rel(1);
// Determine mapping between project input and output fields. If sort
// relies on non-trivial expressions, we can't push.
final Mappings.TargetMapping map =
RelOptUtil.permutation(
project.getProjects(), project.getInput().getRowType()).inverse();
for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) {
if (map.getTarget(fc.getFieldIndex()) < 0) {
return;
}
}
// Create new collation
final RelCollation newCollation =
RelCollationTraitDef.INSTANCE.canonize(
RexUtil.apply(map, sort.getCollation()));
// New operators
final RelNode newProject = project.copy(sort.getInput().getTraitSet(),
ImmutableList.<RelNode>of(sort.getInput()));
final HiveSortLimit newSort = sort.copy(newProject.getTraitSet(),
newProject, newCollation, sort.offset, sort.fetch);
call.transformTo(newSort);
}
内容来源于网络,如有侵权,请联系作者删除!