use of io.crate.expression.symbol.WindowFunction in project crate by crate.
the class SelectWindowFunctionAnalyzerTest method testOverWithPartitionByClause.
@Test
public void testOverWithPartitionByClause() {
QueriedSelectRelation analysis = e.analyze("select avg(x) OVER (PARTITION 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.partitions().size(), is(1));
}
use of io.crate.expression.symbol.WindowFunction in project crate by crate.
the class SelectWindowFunctionAnalyzerTest method testOverWithPartitionAndOrderByClauses.
@Test
public void testOverWithPartitionAndOrderByClauses() {
QueriedSelectRelation analysis = e.analyze("select avg(x) OVER (PARTITION BY x 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.partitions().size(), is(1));
assertThat(windowDefinition.orderBy().orderBySymbols().size(), is(1));
}
use of io.crate.expression.symbol.WindowFunction in project crate by crate.
the class SelectWindowFunctionAnalyzerTest method testOverWithFrameDefinition.
@Test
public void testOverWithFrameDefinition() {
QueriedSelectRelation analysis = e.analyze("select avg(x) OVER (PARTITION BY x ORDER BY x " + "RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) 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));
WindowFrameDefinition frameDefinition = windowFunction.windowDefinition().windowFrameDefinition();
assertThat(frameDefinition.mode(), is(WindowFrame.Mode.RANGE));
assertThat(frameDefinition.start().type(), is(FrameBound.Type.UNBOUNDED_PRECEDING));
assertThat(frameDefinition.end().type(), is(FrameBound.Type.UNBOUNDED_FOLLOWING));
}
use of io.crate.expression.symbol.WindowFunction in project crate by crate.
the class WindowAggProjectionSerialisationTest method testWindowAggProjectionSerialisation.
@Test
public void testWindowAggProjectionSerialisation() throws IOException {
FunctionImplementation sumFunctionImpl = getSumFunction();
WindowDefinition partitionByOneWindowDef = new WindowDefinition(singletonList(Literal.of(1L)), null, null);
WindowDefinition partitionByTwoWindowDef = new WindowDefinition(singletonList(Literal.of(2L)), null, null);
WindowFunction firstWindowFunction = new WindowFunction(sumFunctionImpl.signature(), singletonList(Literal.of(1L)), sumFunctionImpl.boundSignature().getReturnType().createType(), null, partitionByOneWindowDef, true);
WindowFunction secondWindowFunction = new WindowFunction(sumFunctionImpl.signature(), singletonList(Literal.of(2L)), sumFunctionImpl.boundSignature().getReturnType().createType(), null, partitionByTwoWindowDef, null);
Symbol standaloneInput = Literal.of(42L);
var expectedWindowAggProjection = new WindowAggProjection(partitionByOneWindowDef, List.of(firstWindowFunction, secondWindowFunction), List.of(standaloneInput));
var output = new BytesStreamOutput();
expectedWindowAggProjection.writeTo(output);
var in = output.bytes().streamInput();
var actualWindowAggProjection = new WindowAggProjection(in);
assertThat(actualWindowAggProjection.outputs(), contains(standaloneInput, firstWindowFunction, secondWindowFunction));
assertThat(actualWindowAggProjection, is(expectedWindowAggProjection));
}
use of io.crate.expression.symbol.WindowFunction in project crate by crate.
the class MoveFilterBeneathWindowAggTest method test_filter_part_on_windows_function_partition_columns_is_moved.
@Test
public void test_filter_part_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("ROW_NUMBER() OVER(PARTITION BY id) = 2 AND id = 10 AND 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);
var expectedPlan = "Filter[((row_number() OVER (PARTITION BY id) = 2) AND (x = 1))]\n" + " └ WindowAgg[id, row_number() OVER (PARTITION BY id)]\n" + " └ Filter[(id = 10)]\n" + " └ Collect[doc.t1 | [id] | true]";
assertThat(newPlan, isPlan(expectedPlan));
}
Aggregations