• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SqlWindow类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.calcite.sql.SqlWindow的典型用法代码示例。如果您正苦于以下问题:Java SqlWindow类的具体用法?Java SqlWindow怎么用?Java SqlWindow使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SqlWindow类属于org.apache.calcite.sql包,在下文中一共展示了SqlWindow类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: lookupWindow

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
public SqlWindow lookupWindow(String name) {
  final SqlNodeList windowList = select.getWindowList();
  for (int i = 0; i < windowList.size(); i++) {
    SqlWindow window = (SqlWindow) windowList.get(i);
    final SqlIdentifier declId = window.getDeclName();
    assert declId.isSimple();
    if (declId.names.get(0).equals(name)) {
      return window;
    }
  }

  // if not in the select scope, then check window scope
  if (windowParent != null) {
    return windowParent.lookupWindow(name);
  } else {
    return null;
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:SelectScope.java


示例2: makeOver

import org.apache.calcite.sql.SqlWindow; //导入依赖的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
	);
}
 
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:30,代码来源:JdbcRelBuilder.java


示例3: HistogramShuttle

import org.apache.calcite.sql.SqlWindow; //导入依赖的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;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:12,代码来源:SqlToRelConverter.java


示例4: HistogramShuttle

import org.apache.calcite.sql.SqlWindow; //导入依赖的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;
}
 
开发者ID:apache,项目名称:kylin,代码行数:14,代码来源:SqlToRelConverter.java


示例5: toSql

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
private SqlCall toSql(RexProgram program, RexOver rexOver) {
  final RexWindow rexWindow = rexOver.getWindow();
  final SqlNodeList partitionList = new SqlNodeList(
      toSql(program, rexWindow.partitionKeys), POS);

  ImmutableList.Builder<SqlNode> orderNodes = ImmutableList.builder();
  if (rexWindow.orderKeys != null) {
    for (RexFieldCollation rfc : rexWindow.orderKeys) {
      orderNodes.add(toSql(program, rfc));
    }
  }
  final SqlNodeList orderList =
      new SqlNodeList(orderNodes.build(), POS);

  final SqlLiteral isRows =
      SqlLiteral.createBoolean(rexWindow.isRows(), POS);

  final SqlNode lowerBound =
      createSqlWindowBound(rexWindow.getLowerBound());
  final SqlNode upperBound =
      createSqlWindowBound(rexWindow.getUpperBound());

  // null defaults to true.
  // During parsing the allowPartial == false (e.g. disallow partial)
  // is expand into CASE expression and is handled as a such.
  // Not sure if we can collapse this CASE expression back into
  // "disallow partial" and set the allowPartial = false.
  final SqlLiteral allowPartial = null;

  final SqlWindow sqlWindow = SqlWindow.create(null, null, partitionList,
      orderList, isRows, lowerBound, upperBound, allowPartial, POS);

  final List<SqlNode> nodeList = toSql(program, rexOver.getOperands());
  final SqlCall aggFunctionCall =
      rexOver.getAggOperator().createCall(POS, nodeList);

  return SqlStdOperatorTable.OVER.createCall(POS, aggFunctionCall,
      sqlWindow);
}
 
开发者ID:apache,项目名称:calcite,代码行数:40,代码来源:SqlImplementor.java


示例6: HistogramShuttle

import org.apache.calcite.sql.SqlWindow; //导入依赖的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;
}
 
开发者ID:apache,项目名称:calcite,代码行数:14,代码来源:SqlToRelConverter.java


示例7: getWindowInOver

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
private SqlWindow getWindowInOver(SqlNode over) {
  if (over.getKind() == SqlKind.OVER) {
    SqlNode window = ((SqlCall) over).getOperandList().get(1);
    if (window instanceof SqlWindow) {
      return (SqlWindow) window;
    }
    // SqlIdentifier, gets validated elsewhere
    return null;
  }
  return null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:SqlValidatorImpl.java


示例8: getWindowByName

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
protected SqlWindow getWindowByName(
    SqlIdentifier id,
    SqlValidatorScope scope) {
  SqlWindow window = null;
  if (id.isSimple()) {
    final String name = id.getSimple();
    window = scope.lookupWindow(name);
  }
  if (window == null) {
    throw newValidationError(id, RESOURCE.windowNotFound(id.toString()));
  }
  return window;
}
 
开发者ID:apache,项目名称:calcite,代码行数:14,代码来源:SqlValidatorImpl.java


示例9: lookupWindow

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
public SqlWindow lookupWindow(String name) {
  // Lookup window in enclosing select.
  if (usingScope != null) {
    return usingScope.lookupWindow(name);
  } else {
    return null;
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:9,代码来源:JoinScope.java


示例10: create

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
/**
 * Creates window bound.
 * @param node SqlNode of the bound
 * @param rexNode offset value when bound is not UNBOUNDED/CURRENT ROW
 * @return window bound
 */
public static RexWindowBound create(SqlNode node, RexNode rexNode) {
  if (SqlWindow.isUnboundedPreceding(node)
      || SqlWindow.isUnboundedFollowing(node)) {
    return new RexWindowBoundUnbounded(node);
  }
  if (SqlWindow.isCurrentRow(node)) {
    return new RexWindowBoundCurrentRow();
  }
  return new RexWindowBoundBounded(rexNode);
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:RexWindowBound.java


示例11: convertOver

import org.apache.calcite.sql.SqlWindow; //导入依赖的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


示例12: convertOver

import org.apache.calcite.sql.SqlWindow; //导入依赖的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


示例13: convertOver

import org.apache.calcite.sql.SqlWindow; //导入依赖的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


示例14: checkRollUpInWindowDecl

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
private void checkRollUpInWindowDecl(SqlSelect select) {
  for (SqlNode decl : select.getWindowList()) {
    checkRollUpInWindow((SqlWindow) decl, getSelectScope(select));
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:6,代码来源:SqlValidatorImpl.java


示例15: lookupWindow

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
public SqlWindow lookupWindow(String name) {
  return parent.lookupWindow(name);
}
 
开发者ID:apache,项目名称:calcite,代码行数:4,代码来源:DelegatingScope.java


示例16: lookupWindow

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
public SqlWindow lookupWindow(String name) {
  // No windows defined in this scope.
  return null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:5,代码来源:EmptyScope.java


示例17: isPreceding

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
@Override public boolean isPreceding() {
  return SqlWindow.isUnboundedPreceding(node);
}
 
开发者ID:apache,项目名称:calcite,代码行数:4,代码来源:RexWindowBound.java


示例18: isFollowing

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
@Override public boolean isFollowing() {
  return SqlWindow.isUnboundedFollowing(node);
}
 
开发者ID:apache,项目名称:calcite,代码行数:4,代码来源:RexWindowBound.java


示例19: lookupWindow

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
/**
 * Finds a window with a given name. Returns null if not found.
 */
SqlWindow lookupWindow(String name);
 
开发者ID:apache,项目名称:calcite,代码行数:5,代码来源:SqlValidatorScope.java


示例20: resolveWindow

import org.apache.calcite.sql.SqlWindow; //导入依赖的package包/类
/**
 * Converts a window specification or window name into a fully-resolved
 * window specification. For example, in <code>SELECT sum(x) OVER (PARTITION
 * BY x ORDER BY y), sum(y) OVER w1, sum(z) OVER (w ORDER BY y) FROM t
 * WINDOW w AS (PARTITION BY x)</code> all aggregations have the same
 * resolved window specification <code>(PARTITION BY x ORDER BY y)</code>.
 *
 * @param windowOrRef    Either the name of a window (a {@link SqlIdentifier})
 *                       or a window specification (a {@link SqlWindow}).
 * @param scope          Scope in which to resolve window names
 * @param populateBounds Whether to populate bounds. Doing so may alter the
 *                       definition of the window. It is recommended that
 *                       populate bounds when translating to physical algebra,
 *                       but not when validating.
 * @return A window
 * @throws RuntimeException Validation exception if window does not exist
 */
SqlWindow resolveWindow(
    SqlNode windowOrRef,
    SqlValidatorScope scope,
    boolean populateBounds);
 
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:SqlValidator.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StreamingMessages类代码示例发布时间:2022-05-23
下一篇:
Java GeoEventDefinitionManager类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap