gpt4 book ai didi

com.facebook.presto.sql.tree.WindowFrame类的使用及代码示例

转载 作者:知者 更新时间:2024-03-22 02:25:05 25 4
gpt4 key购买 nike

本文整理了Java中com.facebook.presto.sql.tree.WindowFrame类的一些代码示例,展示了WindowFrame类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WindowFrame类的具体详情如下:
包路径:com.facebook.presto.sql.tree.WindowFrame
类名称:WindowFrame

WindowFrame介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

@Override
public String visitWindowFrame(WindowFrame node, Void context)
{
  StringBuilder builder = new StringBuilder();
  builder.append(node.getType().toString()).append(' ');
  if (node.getEnd().isPresent()) {
    builder.append("BETWEEN ")
        .append(process(node.getStart(), context))
        .append(" AND ")
        .append(process(node.getEnd().get(), context));
  }
  else {
    builder.append(process(node.getStart(), context));
  }
  return builder.toString();
}

代码示例来源:origin: prestodb/presto

@Override
public Node visitWindowFrame(SqlBaseParser.WindowFrameContext context)
{
  return new WindowFrame(
      getLocation(context),
      getFrameType(context.frameType),
      (FrameBound) visit(context.start),
      visitIfPresent(context.end, FrameBound.class));
}

代码示例来源:origin: prestodb/presto

@Override
public String toString()
{
  return format("%s%s (%s%s) %s",
      distinct ? "DISTINCT" : "",
      name,
      Joiner.on(", ").join(args),
      orderBy.isEmpty() ? "" : " ORDER BY " + Joiner.on(", ").join(orderBy),
      frame.isPresent() ? frame.get().toString() : "");
}

代码示例来源:origin: prestodb/presto

@Override
public R visitWindowFrame(WindowFrame node, C context)
{
  process(node.getStart(), context);
  if (node.getEnd().isPresent()) {
    process(node.getEnd().get(), context);
  }
  return null;
}

代码示例来源:origin: prestodb/presto

@Override
public Boolean visitWindowFrame(WindowFrame node, Void context)
{
  Optional<Expression> start = node.getStart().getValue();
  if (start.isPresent()) {
    if (!process(start.get(), context)) {
      throw new SemanticException(MUST_BE_AGGREGATE_OR_GROUP_BY, start.get(), "Window frame start must be an aggregate expression or appear in GROUP BY clause");
    }
  }
  if (node.getEnd().isPresent() && node.getEnd().get().getValue().isPresent()) {
    Expression endValue = node.getEnd().get().getValue().get();
    if (!process(endValue, context)) {
      throw new SemanticException(MUST_BE_AGGREGATE_OR_GROUP_BY, endValue, "Window frame end must be an aggregate expression or appear in GROUP BY clause");
    }
  }
  return true;
}

代码示例来源:origin: prestodb/presto

private void analyzeWindowFrame(WindowFrame frame)
{
  FrameBound.Type startType = frame.getStart().getType();
  FrameBound.Type endType = frame.getEnd().orElse(new FrameBound(CURRENT_ROW)).getType();
  if (startType == UNBOUNDED_FOLLOWING) {
    throw new SemanticException(INVALID_WINDOW_FRAME, frame, "Window frame start cannot be UNBOUNDED FOLLOWING");
  }
  if (endType == UNBOUNDED_PRECEDING) {
    throw new SemanticException(INVALID_WINDOW_FRAME, frame, "Window frame end cannot be UNBOUNDED PRECEDING");
  }
  if ((startType == CURRENT_ROW) && (endType == PRECEDING)) {
    throw new SemanticException(INVALID_WINDOW_FRAME, frame, "Window frame starting from CURRENT ROW cannot end with PRECEDING");
  }
  if ((startType == FOLLOWING) && (endType == PRECEDING)) {
    throw new SemanticException(INVALID_WINDOW_FRAME, frame, "Window frame starting from FOLLOWING cannot end with PRECEDING");
  }
  if ((startType == FOLLOWING) && (endType == CURRENT_ROW)) {
    throw new SemanticException(INVALID_WINDOW_FRAME, frame, "Window frame starting from FOLLOWING cannot end with CURRENT ROW");
  }
  if ((frame.getType() == RANGE) && ((startType == PRECEDING) || (endType == PRECEDING))) {
    throw new SemanticException(INVALID_WINDOW_FRAME, frame, "Window frame RANGE PRECEDING is only supported with UNBOUNDED");
  }
  if ((frame.getType() == RANGE) && ((startType == FOLLOWING) || (endType == FOLLOWING))) {
    throw new SemanticException(INVALID_WINDOW_FRAME, frame, "Window frame RANGE FOLLOWING is only supported with UNBOUNDED");
  }
}

代码示例来源:origin: prestodb/presto

WindowFrame frame = node.getWindow().get().getFrame().get();
if (frame.getStart().getValue().isPresent()) {
  Type type = process(frame.getStart().getValue().get(), context);
  if (!type.equals(INTEGER) && !type.equals(BIGINT)) {
    throw new SemanticException(TYPE_MISMATCH, node, "Window frame start value type must be INTEGER or BIGINT(actual %s)", type);
if (frame.getEnd().isPresent() && frame.getEnd().get().getValue().isPresent()) {
  Type type = process(frame.getEnd().get().getValue().get(), context);
  if (!type.equals(INTEGER) && !type.equals(BIGINT)) {
    throw new SemanticException(TYPE_MISMATCH, node, "Window frame end value type must be INTEGER or BIGINT (actual %s)", type);

代码示例来源:origin: prestodb/presto

@Test
public void testMergeDifferentFrames()
{
  Optional<WindowFrame> frameC = Optional.of(new WindowFrame(
      WindowFrame.Type.ROWS,
      new FrameBound(FrameBound.Type.UNBOUNDED_PRECEDING),
      Optional.of(new FrameBound(FrameBound.Type.CURRENT_ROW))));
  ExpectedValueProvider<WindowNode.Specification> specificationC = specification(
      ImmutableList.of(SUPPKEY_ALIAS),
      ImmutableList.of(ORDERKEY_ALIAS),
      ImmutableMap.of(ORDERKEY_ALIAS, SortOrder.ASC_NULLS_LAST));
  Optional<WindowFrame> frameD = Optional.of(new WindowFrame(
      WindowFrame.Type.ROWS,
      new FrameBound(FrameBound.Type.CURRENT_ROW),
      Optional.of(new FrameBound(FrameBound.Type.UNBOUNDED_FOLLOWING))));
  @Language("SQL") String sql = "SELECT " +
      "SUM(quantity) OVER (PARTITION BY suppkey ORDER BY orderkey ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) sum_quantity_C, " +
      "AVG(quantity) OVER (PARTITION BY suppkey ORDER BY orderkey ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) avg_quantity_D, " +
      "SUM(discount) OVER (PARTITION BY suppkey ORDER BY orderkey ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) sum_discount_C " +
      "FROM lineitem";
  assertUnitPlan(sql,
      anyTree(
          window(windowMatcherBuilder -> windowMatcherBuilder
                  .specification(specificationC)
                  .addFunction(functionCall("avg", frameD, ImmutableList.of(QUANTITY_ALIAS)))
                  .addFunction(functionCall("sum", frameC, ImmutableList.of(DISCOUNT_ALIAS)))
                  .addFunction(functionCall("sum", frameC, ImmutableList.of(QUANTITY_ALIAS))),
              LINEITEM_TABLESCAN_DOQS)));
}

代码示例来源:origin: prestodb/presto

frameType = frame.getType();
frameStartType = frame.getStart().getType();
frameStart = frame.getStart().getValue().orElse(null);
if (frame.getEnd().isPresent()) {
  frameEndType = frame.getEnd().get().getType();
  frameEnd = frame.getEnd().get().getValue().orElse(null);

代码示例来源:origin: uk.co.nichesolutions.presto/presto-parser

@Override
public R visitWindowFrame(WindowFrame node, C context)
{
  process(node.getStart(), context);
  if (node.getEnd().isPresent()) {
    process(node.getEnd().get(), context);
  }
  return null;
}

代码示例来源:origin: prestodb/presto

@Test
public void testMergeDifferentFramesWithDefault()
{
  Optional<WindowFrame> frameD = Optional.of(new WindowFrame(
      WindowFrame.Type.ROWS,
      new FrameBound(FrameBound.Type.CURRENT_ROW),
      Optional.of(new FrameBound(FrameBound.Type.UNBOUNDED_FOLLOWING))));
  ExpectedValueProvider<WindowNode.Specification> specificationD = specification(
      ImmutableList.of(SUPPKEY_ALIAS),
      ImmutableList.of(ORDERKEY_ALIAS),
      ImmutableMap.of(ORDERKEY_ALIAS, SortOrder.ASC_NULLS_LAST));
  @Language("SQL") String sql = "SELECT " +
      "SUM(quantity) OVER (PARTITION BY suppkey ORDER BY orderkey) sum_quantity_C, " +
      "AVG(quantity) OVER (PARTITION BY suppkey ORDER BY orderkey ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) avg_quantity_D, " +
      "SUM(discount) OVER (PARTITION BY suppkey ORDER BY orderkey) sum_discount_C " +
      "FROM lineitem";
  assertUnitPlan(sql,
      anyTree(
          window(windowMatcherBuilder -> windowMatcherBuilder
                  .specification(specificationD)
                  .addFunction(functionCall("avg", frameD, ImmutableList.of(QUANTITY_ALIAS)))
                  .addFunction(functionCall("sum", UNSPECIFIED_FRAME, ImmutableList.of(DISCOUNT_ALIAS)))
                  .addFunction(functionCall("sum", UNSPECIFIED_FRAME, ImmutableList.of(QUANTITY_ALIAS))),
              LINEITEM_TABLESCAN_DOQS)));
}

代码示例来源:origin: rakam-io/rakam

@Override
public String visitWindowFrame(WindowFrame node, Void context) {
  StringBuilder builder = new StringBuilder();
  builder.append(node.getType().toString()).append(' ');
  if (node.getEnd().isPresent()) {
    builder.append("BETWEEN ")
        .append(process(node.getStart(), context))
        .append(" AND ")
        .append(process(node.getEnd().get(), context));
  } else {
    builder.append(process(node.getStart(), context));
  }
  return builder.toString();
}

代码示例来源:origin: com.facebook.presto/presto-parser

@Override
public R visitWindowFrame(WindowFrame node, C context)
{
  process(node.getStart(), context);
  if (node.getEnd().isPresent()) {
    process(node.getEnd().get(), context);
  }
  return null;
}

代码示例来源:origin: com.facebook.presto/presto-parser

@Override
public Node visitWindowFrame(SqlBaseParser.WindowFrameContext context)
{
  return new WindowFrame(
      getLocation(context),
      getFrameType(context.frameType),
      (FrameBound) visit(context.start),
      visitIfPresent(context.end, FrameBound.class));
}

代码示例来源:origin: com.facebook.presto/presto-parser

@Override
public String visitWindowFrame(WindowFrame node, Void context)
{
  StringBuilder builder = new StringBuilder();
  builder.append(node.getType().toString()).append(' ');
  if (node.getEnd().isPresent()) {
    builder.append("BETWEEN ")
        .append(process(node.getStart(), context))
        .append(" AND ")
        .append(process(node.getEnd().get(), context));
  }
  else {
    builder.append(process(node.getStart(), context));
  }
  return builder.toString();
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

@Override
public Boolean visitWindowFrame(WindowFrame node, Void context)
{
  Optional<Expression> start = node.getStart().getValue();
  if (start.isPresent()) {
    if (!process(start.get(), context)) {
      throw new SemanticException(MUST_BE_AGGREGATE_OR_GROUP_BY, start.get(), "Window frame start must be an aggregate expression or appear in GROUP BY clause");
    }
  }
  if (node.getEnd().isPresent() && node.getEnd().get().getValue().isPresent()) {
    Expression endValue = node.getEnd().get().getValue().get();
    if (!process(endValue, context)) {
      throw new SemanticException(MUST_BE_AGGREGATE_OR_GROUP_BY, endValue, "Window frame end must be an aggregate expression or appear in GROUP BY clause");
    }
  }
  return true;
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-parser

@Override
public Node visitWindowFrame(SqlBaseParser.WindowFrameContext context)
{
  return new WindowFrame(
      getLocation(context),
      getFrameType(context.frameType),
      (FrameBound) visit(context.start),
      visitIfPresent(context.end, FrameBound.class));
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-parser

@Override
public String visitWindowFrame(WindowFrame node, Boolean unmangleNames)
{
  StringBuilder builder = new StringBuilder();
  builder.append(node.getType().toString()).append(' ');
  if (node.getEnd().isPresent()) {
    builder.append("BETWEEN ")
        .append(process(node.getStart(), unmangleNames))
        .append(" AND ")
        .append(process(node.getEnd().get(), unmangleNames));
  }
  else {
    builder.append(process(node.getStart(), unmangleNames));
  }
  return builder.toString();
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

WindowFrame frame = node.getWindow().get().getFrame().get();
if (frame.getStart().getValue().isPresent()) {
  Type type = process(frame.getStart().getValue().get(), context);
  if (!type.equals(BIGINT)) {
    throw new SemanticException(TYPE_MISMATCH, node, "Window frame start value type must be BIGINT (actual %s)", type);
if (frame.getEnd().isPresent() && frame.getEnd().get().getValue().isPresent()) {
  Type type = process(frame.getEnd().get().getValue().get(), context);
  if (!type.equals(BIGINT)) {
    throw new SemanticException(TYPE_MISMATCH, node, "Window frame end value type must be BIGINT (actual %s)", type);

代码示例来源:origin: vqtran/EchoQuery

@Override
public String visitWindowFrame(WindowFrame node, Boolean unmangleNames)
{
  StringBuilder builder = new StringBuilder();
  builder.append(node.getType().toString()).append(' ');
  if (node.getEnd().isPresent()) {
    builder.append("BETWEEN ")
        .append(process(node.getStart(), unmangleNames))
        .append(" AND ")
        .append(process(node.getEnd().get(), unmangleNames));
  }
  else {
    builder.append(process(node.getStart(), unmangleNames));
  }
  return builder.toString();
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com