Search in sources :

Example 1 with FrameBound

use of io.prestosql.sql.tree.FrameBound in project hetu-core by openlookeng.

the class TestMergeWindows method testMergeDifferentFramesWithDefault.

@Test
public void testMergeDifferentFramesWithDefault() {
    Optional<WindowFrame> frameD = Optional.of(new WindowFrame(WindowFrameType.ROWS, new FrameBound(FrameBoundType.CURRENT_ROW), Optional.of(new FrameBound(FrameBoundType.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)));
}
Also used : WindowFrame(io.prestosql.sql.tree.WindowFrame) Language(org.intellij.lang.annotations.Language) FrameBound(io.prestosql.sql.tree.FrameBound) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Example 2 with FrameBound

use of io.prestosql.sql.tree.FrameBound in project hetu-core by openlookeng.

the class TestMergeWindows method testMergeDifferentFrames.

@Test
public void testMergeDifferentFrames() {
    Optional<WindowFrame> frameC = Optional.of(new WindowFrame(WindowFrameType.ROWS, new FrameBound(FrameBoundType.UNBOUNDED_PRECEDING), Optional.of(new FrameBound(FrameBoundType.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(WindowFrameType.ROWS, new FrameBound(FrameBoundType.CURRENT_ROW), Optional.of(new FrameBound(FrameBoundType.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)));
}
Also used : WindowFrame(io.prestosql.sql.tree.WindowFrame) Language(org.intellij.lang.annotations.Language) FrameBound(io.prestosql.sql.tree.FrameBound) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Aggregations

BasePlanTest (io.prestosql.sql.planner.assertions.BasePlanTest)2 FrameBound (io.prestosql.sql.tree.FrameBound)2 WindowFrame (io.prestosql.sql.tree.WindowFrame)2 Language (org.intellij.lang.annotations.Language)2 Test (org.testng.annotations.Test)2