本文整理汇总了Java中org.apache.calcite.rex.RexWindowBound类的典型用法代码示例。如果您正苦于以下问题:Java RexWindowBound类的具体用法?Java RexWindowBound怎么用?Java RexWindowBound使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RexWindowBound类属于org.apache.calcite.rex包,在下文中一共展示了RexWindowBound类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Group
import org.apache.calcite.rex.RexWindowBound; //导入依赖的package包/类
public Group(
ImmutableBitSet keys,
boolean isRows,
RexWindowBound lowerBound,
RexWindowBound upperBound,
RelCollation orderKeys,
List<RexWinAggCall> aggCalls) {
assert orderKeys != null : "precondition: ordinals != null";
assert keys != null;
this.keys = keys;
this.isRows = isRows;
this.lowerBound = lowerBound;
this.upperBound = upperBound;
this.orderKeys = orderKeys;
this.aggCalls = ImmutableList.copyOf(aggCalls);
this.digest = computeString();
}
示例2: isAlwaysNonEmpty
import org.apache.calcite.rex.RexWindowBound; //导入依赖的package包/类
/**
* Returns if the window is guaranteed to have rows.
* This is useful to refine data type of window aggregates.
* For instance sum(non-nullable) over (empty window) is NULL.
*
* @return true when the window is non-empty
*
* @see org.apache.calcite.rel.core.Window.Group#isAlwaysNonEmpty()
* @see SqlOperatorBinding#getGroupCount()
* @see org.apache.calcite.sql.validate.SqlValidatorImpl#resolveWindow(SqlNode, org.apache.calcite.sql.validate.SqlValidatorScope, boolean)
*/
public boolean isAlwaysNonEmpty() {
final SqlWindow tmp;
if (lowerBound == null || upperBound == null) {
// Keep the current window unmodified
tmp = new SqlWindow(getParserPosition(), null, null, partitionList,
orderList, isRows, lowerBound, upperBound, allowPartial);
tmp.populateBounds();
} else {
tmp = this;
}
if (tmp.lowerBound instanceof SqlLiteral
&& tmp.upperBound instanceof SqlLiteral) {
int lowerKey = RexWindowBound.create(tmp.lowerBound, null).getOrderKey();
int upperKey = RexWindowBound.create(tmp.upperBound, null).getOrderKey();
return lowerKey > -1 && lowerKey <= upperKey;
}
return false;
}
示例3: makeOver
import org.apache.calcite.rex.RexWindowBound; //导入依赖的package包/类
public RexNode makeOver(
SqlAggFunction operator,
List<RexNode> expressions,
List<RexNode> partitionKeys
) {
final Set<SqlKind> flags = EnumSet.noneOf(SqlKind.class);
// TODO
// This is a temporal fix to make HAWQ work with OVER + UNLIMITED BOUNDS
// HAWQ requires ORDER BY if andy BOUNDS are set even unlimited upper and lower BOUNDS (which is equal to
// the entire partition - e.g. not setting BOUNDs at all --
// Note that the unnecessary ORDER BY have negative performance impact and has to be remove once either HAWQ
// start supporting unbounded bounds without order by or Calcite can generate shorthand OVER PARTITION BY
// syntax.
List<RexFieldCollation> orderKeys = expressions.stream().map(
rexNode -> new RexFieldCollation(rexNode, flags)).collect(Collectors.toList());
return makeOver(
operator,
expressions,
partitionKeys,
ImmutableList.copyOf(orderKeys),
RexWindowBound.create(SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO), null),
RexWindowBound.create(SqlWindow.createUnboundedFollowing(SqlParserPos.ZERO), null),
true,
true,
false
);
}
示例4: HistogramShuttle
import org.apache.calcite.rex.RexWindowBound; //导入依赖的package包/类
HistogramShuttle(
List<RexNode> partitionKeys,
ImmutableList<RexFieldCollation> orderKeys,
RexWindowBound lowerBound, RexWindowBound upperBound,
SqlWindow window) {
this.partitionKeys = partitionKeys;
this.orderKeys = orderKeys;
this.lowerBound = lowerBound;
this.upperBound = upperBound;
this.window = window;
}
示例5: HistogramShuttle
import org.apache.calcite.rex.RexWindowBound; //导入依赖的package包/类
HistogramShuttle(
List<RexNode> partitionKeys,
ImmutableList<RexFieldCollation> orderKeys,
RexWindowBound lowerBound, RexWindowBound upperBound,
SqlWindow window,
boolean distinct) {
this.partitionKeys = partitionKeys;
this.orderKeys = orderKeys;
this.lowerBound = lowerBound;
this.upperBound = upperBound;
this.window = window;
this.distinct = distinct;
}
示例6: WindowKey
import org.apache.calcite.rex.RexWindowBound; //导入依赖的package包/类
WindowKey(
ImmutableBitSet groupSet,
RelCollation orderKeys,
boolean isRows,
RexWindowBound lowerBound,
RexWindowBound upperBound) {
this.groupSet = groupSet;
this.orderKeys = orderKeys;
this.isRows = isRows;
this.lowerBound = lowerBound;
this.upperBound = upperBound;
}
示例7: HistogramShuttle
import org.apache.calcite.rex.RexWindowBound; //导入依赖的package包/类
HistogramShuttle(
List<RexNode> partitionKeys,
ImmutableList<RexFieldCollation> orderKeys,
RexWindowBound lowerBound, RexWindowBound upperBound,
SqlWindow window,
boolean distinct) {
this.partitionKeys = partitionKeys;
this.orderKeys = orderKeys;
this.lowerBound = lowerBound;
this.upperBound = upperBound;
this.window = window;
this.distinct = distinct;
}
示例8: newBound
import org.apache.calcite.rex.RexWindowBound; //导入依赖的package包/类
public static Bound newBound(RexWindowBound windowBound) {
return new Bound(windowBound.isUnbounded(), windowBound.isCurrentRow() ? 0 : Long.MIN_VALUE); //TODO: Get offset to work
}
示例9: convertOver
import org.apache.calcite.rex.RexWindowBound; //导入依赖的package包/类
private RexNode convertOver(Blackboard bb, SqlNode node) {
SqlCall call = (SqlCall) node;
SqlCall aggCall = call.operand(0);
SqlNode windowOrRef = call.operand(1);
final SqlWindow window =
validator.resolveWindow(windowOrRef, bb.scope, true);
// ROW_NUMBER() expects specific kind of framing.
if (aggCall.getKind() == SqlKind.ROW_NUMBER) {
window.setLowerBound(SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO));
window.setUpperBound(SqlWindow.createCurrentRow(SqlParserPos.ZERO));
window.setRows(SqlLiteral.createBoolean(true, SqlParserPos.ZERO));
}
final SqlNodeList partitionList = window.getPartitionList();
final ImmutableList.Builder<RexNode> partitionKeys =
ImmutableList.builder();
for (SqlNode partition : partitionList) {
partitionKeys.add(bb.convertExpression(partition));
}
RexNode lowerBound = bb.convertExpression(window.getLowerBound());
RexNode upperBound = bb.convertExpression(window.getUpperBound());
SqlNodeList orderList = window.getOrderList();
if ((orderList.size() == 0) && !window.isRows()) {
// A logical range requires an ORDER BY clause. Use the implicit
// ordering of this relation. There must be one, otherwise it would
// have failed validation.
orderList = bb.scope.getOrderList();
if (orderList == null) {
throw new AssertionError(
"Relation should have sort key for implicit ORDER BY");
}
}
final ImmutableList.Builder<RexFieldCollation> orderKeys =
ImmutableList.builder();
final Set<SqlKind> flags = EnumSet.noneOf(SqlKind.class);
for (SqlNode order : orderList) {
flags.clear();
RexNode e = bb.convertSortExpression(order, flags);
orderKeys.add(new RexFieldCollation(e, flags));
}
try {
Preconditions.checkArgument(bb.window == null,
"already in window agg mode");
bb.window = window;
RexNode rexAgg = exprConverter.convertCall(bb, aggCall);
rexAgg =
rexBuilder.ensureType(
validator.getValidatedNodeType(call), rexAgg, false);
// Walk over the tree and apply 'over' to all agg functions. This is
// necessary because the returned expression is not necessarily a call
// to an agg function. For example, AVG(x) becomes SUM(x) / COUNT(x).
final RexShuttle visitor =
new HistogramShuttle(
partitionKeys.build(), orderKeys.build(),
RexWindowBound.create(window.getLowerBound(), lowerBound),
RexWindowBound.create(window.getUpperBound(), upperBound),
window);
return rexAgg.accept(visitor);
} finally {
bb.window = null;
}
}
示例10: convertOver
import org.apache.calcite.rex.RexWindowBound; //导入依赖的package包/类
private RexNode convertOver(Blackboard bb, SqlNode node) {
SqlCall call = (SqlCall) node;
SqlCall aggCall = call.operand(0);
SqlNode windowOrRef = call.operand(1);
final SqlWindow window =
validator.resolveWindow(windowOrRef, bb.scope, true);
// ROW_NUMBER() expects specific kind of framing.
if (aggCall.getKind() == SqlKind.ROW_NUMBER) {
window.setLowerBound(SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO));
window.setUpperBound(SqlWindow.createCurrentRow(SqlParserPos.ZERO));
window.setRows(SqlLiteral.createBoolean(true, SqlParserPos.ZERO));
}
final SqlNodeList partitionList = window.getPartitionList();
final ImmutableList.Builder<RexNode> partitionKeys =
ImmutableList.builder();
for (SqlNode partition : partitionList) {
partitionKeys.add(bb.convertExpression(partition));
}
RexNode lowerBound = bb.convertExpression(window.getLowerBound());
RexNode upperBound = bb.convertExpression(window.getUpperBound());
SqlNodeList orderList = window.getOrderList();
if ((orderList.size() == 0) && !window.isRows()) {
// A logical range requires an ORDER BY clause. Use the implicit
// ordering of this relation. There must be one, otherwise it would
// have failed validation.
orderList = bb.scope.getOrderList();
if (orderList == null) {
throw new AssertionError(
"Relation should have sort key for implicit ORDER BY");
}
}
final ImmutableList.Builder<RexFieldCollation> orderKeys =
ImmutableList.builder();
final Set<SqlKind> flags = EnumSet.noneOf(SqlKind.class);
for (SqlNode order : orderList) {
flags.clear();
RexNode e = bb.convertSortExpression(order, flags);
orderKeys.add(new RexFieldCollation(e, flags));
}
try {
Preconditions.checkArgument(bb.window == null,
"already in window agg mode");
bb.window = window;
RexNode rexAgg = exprConverter.convertCall(bb, aggCall);
rexAgg =
rexBuilder.ensureType(
validator.getValidatedNodeType(call), rexAgg, false);
// Walk over the tree and apply 'over' to all agg functions. This is
// necessary because the returned expression is not necessarily a call
// to an agg function. For example, AVG(x) becomes SUM(x) / COUNT(x).
boolean isDistinct = false;
if (aggCall.getFunctionQuantifier() != null
&& aggCall.getFunctionQuantifier().getValue().equals(SqlSelectKeyword.DISTINCT)) {
isDistinct = true;
}
final RexShuttle visitor =
new HistogramShuttle(
partitionKeys.build(), orderKeys.build(),
RexWindowBound.create(window.getLowerBound(), lowerBound),
RexWindowBound.create(window.getUpperBound(), upperBound),
window,
isDistinct);
RexNode overNode = rexAgg.accept(visitor);
return overNode;
} finally {
bb.window = null;
}
}
示例11: convertOver
import org.apache.calcite.rex.RexWindowBound; //导入依赖的package包/类
private RexNode convertOver(Blackboard bb, SqlNode node) {
SqlCall call = (SqlCall) node;
SqlCall aggCall = call.operand(0);
SqlNode windowOrRef = call.operand(1);
final SqlWindow window =
validator.resolveWindow(windowOrRef, bb.scope, true);
// ROW_NUMBER() expects specific kind of framing.
if (aggCall.getKind() == SqlKind.ROW_NUMBER) {
window.setLowerBound(SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO));
window.setUpperBound(SqlWindow.createCurrentRow(SqlParserPos.ZERO));
window.setRows(SqlLiteral.createBoolean(true, SqlParserPos.ZERO));
}
final SqlNodeList partitionList = window.getPartitionList();
final ImmutableList.Builder<RexNode> partitionKeys =
ImmutableList.builder();
for (SqlNode partition : partitionList) {
partitionKeys.add(bb.convertExpression(partition));
}
RexNode lowerBound = bb.convertExpression(window.getLowerBound());
RexNode upperBound = bb.convertExpression(window.getUpperBound());
SqlNodeList orderList = window.getOrderList();
if ((orderList.size() == 0) && !window.isRows()) {
// A logical range requires an ORDER BY clause. Use the implicit
// ordering of this relation. There must be one, otherwise it would
// have failed validation.
orderList = bb.scope.getOrderList();
if (orderList == null) {
throw new AssertionError(
"Relation should have sort key for implicit ORDER BY");
}
}
final ImmutableList.Builder<RexFieldCollation> orderKeys =
ImmutableList.builder();
final Set<SqlKind> flags = EnumSet.noneOf(SqlKind.class);
for (SqlNode order : orderList) {
flags.clear();
RexNode e = bb.convertSortExpression(order, flags);
orderKeys.add(new RexFieldCollation(e, flags));
}
try {
Preconditions.checkArgument(bb.window == null,
"already in window agg mode");
bb.window = window;
RexNode rexAgg = exprConverter.convertCall(bb, aggCall);
rexAgg =
rexBuilder.ensureType(
validator.getValidatedNodeType(call), rexAgg, false);
// Walk over the tree and apply 'over' to all agg functions. This is
// necessary because the returned expression is not necessarily a call
// to an agg function. For example, AVG(x) becomes SUM(x) / COUNT(x).
final SqlLiteral q = aggCall.getFunctionQuantifier();
final boolean isDistinct = q != null
&& q.getValue() == SqlSelectKeyword.DISTINCT;
final RexShuttle visitor =
new HistogramShuttle(
partitionKeys.build(), orderKeys.build(),
RexWindowBound.create(window.getLowerBound(), lowerBound),
RexWindowBound.create(window.getUpperBound(), upperBound),
window,
isDistinct);
RexNode overNode = rexAgg.accept(visitor);
return overNode;
} finally {
bb.window = null;
}
}