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


Java RexWindowBound.create方法代码示例

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


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

示例1: 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;
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:64,代码来源:SqlToRelConverter.java

示例2: 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;
  }
}
 
开发者ID:apache,项目名称:kylin,代码行数:74,代码来源:SqlToRelConverter.java

示例3: 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;
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:72,代码来源:SqlToRelConverter.java


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