Search in sources :

Example 6 with WindowFunction

use of io.crate.expression.symbol.WindowFunction in project crate by crate.

the class MoveFilterBeneathWindowAggTest method test_filter_on_windows_function_partition_columns_is_moved.

@Test
public void test_filter_on_windows_function_partition_columns_is_moved() {
    var collect = e.logicalPlan("SELECT id FROM t1");
    WindowFunction windowFunction = (WindowFunction) e.asSymbol("ROW_NUMBER() OVER(PARTITION BY id)");
    WindowAgg windowAgg = (WindowAgg) WindowAgg.create(collect, List.of(windowFunction));
    Symbol query = e.asSymbol("id = 10");
    Filter filter = new Filter(windowAgg, query);
    var rule = new MoveFilterBeneathWindowAgg();
    Match<Filter> match = rule.pattern().accept(filter, Captures.empty());
    assertThat(match.isPresent(), is(true));
    assertThat(match.value(), Matchers.sameInstance(filter));
    LogicalPlan newPlan = rule.apply(match.value(), match.captures(), new TableStats(), CoordinatorTxnCtx.systemTransactionContext(), e.nodeCtx);
    var expectedPlan = "WindowAgg[id, row_number() OVER (PARTITION BY id)]\n" + "  └ Filter[(id = 10)]\n" + "    └ Collect[doc.t1 | [id] | true]";
    assertThat(newPlan, isPlan(expectedPlan));
}
Also used : WindowFunction(io.crate.expression.symbol.WindowFunction) WindowAgg(io.crate.planner.operators.WindowAgg) Filter(io.crate.planner.operators.Filter) Symbol(io.crate.expression.symbol.Symbol) LogicalPlan(io.crate.planner.operators.LogicalPlan) TableStats(io.crate.statistics.TableStats) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 7 with WindowFunction

use of io.crate.expression.symbol.WindowFunction in project crate by crate.

the class MoveFilterBeneathWindowAggTest method test_filters_combined_by_OR_cannot_be_moved.

@Test
public void test_filters_combined_by_OR_cannot_be_moved() {
    var collect = e.logicalPlan("SELECT id FROM t1");
    WindowFunction windowFunction = (WindowFunction) e.asSymbol("ROW_NUMBER() OVER(PARTITION BY id)");
    WindowAgg windowAgg = (WindowAgg) WindowAgg.create(collect, List.of(windowFunction));
    Symbol query = e.asSymbol("ROW_NUMBER() OVER(PARTITION BY id) = 1 OR id = 10");
    Filter filter = new Filter(windowAgg, query);
    var rule = new MoveFilterBeneathWindowAgg();
    Match<Filter> match = rule.pattern().accept(filter, Captures.empty());
    assertThat(match.isPresent(), is(true));
    assertThat(match.value(), Matchers.sameInstance(filter));
    LogicalPlan newPlan = rule.apply(match.value(), match.captures(), new TableStats(), CoordinatorTxnCtx.systemTransactionContext(), e.nodeCtx);
    assertThat(newPlan, nullValue());
}
Also used : WindowFunction(io.crate.expression.symbol.WindowFunction) WindowAgg(io.crate.planner.operators.WindowAgg) Filter(io.crate.planner.operators.Filter) Symbol(io.crate.expression.symbol.Symbol) LogicalPlan(io.crate.planner.operators.LogicalPlan) TableStats(io.crate.statistics.TableStats) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 8 with WindowFunction

use of io.crate.expression.symbol.WindowFunction in project crate by crate.

the class MoveFilterBeneathWindowAggTest method test_filter_containing_columns_not_part_of_the_window_partition_cannot_be_moved.

@Test
public void test_filter_containing_columns_not_part_of_the_window_partition_cannot_be_moved() {
    var collect = e.logicalPlan("SELECT id, x FROM t1");
    WindowFunction windowFunction = (WindowFunction) e.asSymbol("ROW_NUMBER() OVER(PARTITION by id)");
    WindowAgg windowAgg = (WindowAgg) WindowAgg.create(collect, List.of(windowFunction));
    Symbol query = e.asSymbol("x = 1");
    Filter filter = new Filter(windowAgg, query);
    var rule = new MoveFilterBeneathWindowAgg();
    Match<Filter> match = rule.pattern().accept(filter, Captures.empty());
    assertThat(match.isPresent(), is(true));
    assertThat(match.value(), Matchers.sameInstance(filter));
    LogicalPlan newPlan = rule.apply(match.value(), match.captures(), new TableStats(), CoordinatorTxnCtx.systemTransactionContext(), e.nodeCtx);
    assertThat(newPlan, nullValue());
}
Also used : WindowFunction(io.crate.expression.symbol.WindowFunction) WindowAgg(io.crate.planner.operators.WindowAgg) Filter(io.crate.planner.operators.Filter) Symbol(io.crate.expression.symbol.Symbol) LogicalPlan(io.crate.planner.operators.LogicalPlan) TableStats(io.crate.statistics.TableStats) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 9 with WindowFunction

use of io.crate.expression.symbol.WindowFunction in project crate by crate.

the class WindowAggTest method wd.

private WindowDefinition wd(String expression) {
    Symbol symbol = e.asSymbol(expression);
    assertThat(symbol, instanceOf(WindowFunction.class));
    return ((WindowFunction) symbol).windowDefinition();
}
Also used : WindowFunction(io.crate.expression.symbol.WindowFunction) Symbol(io.crate.expression.symbol.Symbol)

Example 10 with WindowFunction

use of io.crate.expression.symbol.WindowFunction in project crate by crate.

the class SelectWindowFunctionAnalyzerTest method testOverWithOrderByClause.

@Test
public void testOverWithOrderByClause() {
    QueriedSelectRelation analysis = e.analyze("select avg(x) OVER (ORDER BY x) from t");
    List<Symbol> outputSymbols = analysis.outputs();
    assertThat(outputSymbols.size(), is(1));
    assertThat(outputSymbols.get(0), instanceOf(WindowFunction.class));
    WindowFunction windowFunction = (WindowFunction) outputSymbols.get(0);
    assertThat(windowFunction.arguments().size(), is(1));
    WindowDefinition windowDefinition = windowFunction.windowDefinition();
    assertThat(windowDefinition.orderBy().orderBySymbols().size(), is(1));
}
Also used : WindowFunction(io.crate.expression.symbol.WindowFunction) Symbol(io.crate.expression.symbol.Symbol) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Aggregations

WindowFunction (io.crate.expression.symbol.WindowFunction)24 Symbol (io.crate.expression.symbol.Symbol)21 Test (org.junit.Test)16 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)14 Filter (io.crate.planner.operators.Filter)6 LogicalPlan (io.crate.planner.operators.LogicalPlan)6 WindowAgg (io.crate.planner.operators.WindowAgg)6 TableStats (io.crate.statistics.TableStats)6 ArrayList (java.util.ArrayList)5 WindowDefinition (io.crate.analyze.WindowDefinition)4 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)3 Function (io.crate.expression.symbol.Function)3 FunctionImplementation (io.crate.metadata.FunctionImplementation)3 List (java.util.List)3 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)2 OrderBy (io.crate.analyze.OrderBy)2 Projection (io.crate.execution.dsl.projection.Projection)2 WindowAggProjection (io.crate.execution.dsl.projection.WindowAggProjection)2 ScopedSymbol (io.crate.expression.symbol.ScopedSymbol)2 SelectSymbol (io.crate.expression.symbol.SelectSymbol)2