use of io.trino.spi.type.BigintType.BIGINT in project trino by trinodb.
the class TestPushDistinctLimitIntoTableScan method testNoEffect.
@Test
public void testNoEffect() {
AtomicInteger applyCallCounter = new AtomicInteger();
testApplyAggregation = (session, handle, aggregates, assignments, groupingSets) -> {
applyCallCounter.incrementAndGet();
return Optional.empty();
};
tester().assertThat(rule).on(p -> {
Symbol regionkey = p.symbol("regionkey");
return p.distinctLimit(10, List.of(regionkey), p.tableScan(tableHandle, ImmutableList.of(regionkey), ImmutableMap.of(regionkey, new MockConnectorColumnHandle("regionkey", BIGINT))));
}).doesNotFire();
assertThat(applyCallCounter).as("applyCallCounter").hasValue(1);
}
use of io.trino.spi.type.BigintType.BIGINT in project trino by trinodb.
the class TestPrunePattenRecognitionColumns method testPruneUnreferencedWindowFunctionAndSources.
@Test
public void testPruneUnreferencedWindowFunctionAndSources() {
ResolvedFunction lag = createTestMetadataManager().resolveFunction(tester().getSession(), QualifiedName.of("lag"), fromTypes(BIGINT));
// remove window function "lag" and input symbol "b" used only by that function
tester().assertThat(new PrunePattenRecognitionColumns()).on(p -> p.project(Assignments.identity(p.symbol("measure")), p.patternRecognition(builder -> builder.addWindowFunction(p.symbol("lag"), new WindowNode.Function(lag, ImmutableList.of(p.symbol("b").toSymbolReference()), DEFAULT_FRAME, false)).addMeasure(p.symbol("measure"), "LAST(X.a)", BIGINT).rowsPerMatch(WINDOW).frame(new WindowNode.Frame(ROWS, CURRENT_ROW, Optional.empty(), Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty())).skipTo(NEXT).pattern(new IrLabel("X")).addVariableDefinition(new IrLabel("X"), "true").source(p.values(p.symbol("a"), p.symbol("b")))))).matches(strictProject(ImmutableMap.of("measure", expression("measure")), patternRecognition(builder -> builder.addMeasure("measure", "LAST(X.a)", BIGINT).rowsPerMatch(WINDOW).frame(windowFrame(ROWS, CURRENT_ROW, Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty())).skipTo(NEXT).pattern(new IrLabel("X")).addVariableDefinition(new IrLabel("X"), "true"), strictProject(ImmutableMap.of("a", expression("a")), values("a", "b")))));
}
use of io.trino.spi.type.BigintType.BIGINT in project trino by trinodb.
the class TestPrunePattenRecognitionColumns method testDoNotPruneVariableDefinitionSources.
@Test
public void testDoNotPruneVariableDefinitionSources() {
// input symbol "a" is used only by the variable definition
tester().assertThat(new PrunePattenRecognitionColumns()).on(p -> p.project(Assignments.of(), p.patternRecognition(builder -> builder.addMeasure(p.symbol("measure"), "1", BIGINT).pattern(new IrLabel("X")).addVariableDefinition(new IrLabel("X"), "LAST(X.a) > 0").source(p.values(p.symbol("a"), p.symbol("b")))))).matches(strictProject(ImmutableMap.of(), patternRecognition(builder -> builder.pattern(new IrLabel("X")).addVariableDefinition(new IrLabel("X"), "LAST(X.a) > 0"), strictProject(ImmutableMap.of("a", expression("a")), values("a", "b")))));
// inputs "a", "b" are used as aggregation arguments
QualifiedName maxBy = tester().getMetadata().resolveFunction(tester().getSession(), QualifiedName.of("max_by"), fromTypes(BIGINT, BIGINT)).toQualifiedName();
tester().assertThat(new PrunePattenRecognitionColumns()).on(p -> p.project(Assignments.of(), p.patternRecognition(builder -> builder.addMeasure(p.symbol("measure"), "1", BIGINT).pattern(new IrLabel("X")).addVariableDefinition(new IrLabel("X"), new ComparisonExpression(GREATER_THAN, new FunctionCall(maxBy, ImmutableList.of(PlanBuilder.expression("a"), PlanBuilder.expression("b"))), PlanBuilder.expression("5"))).source(p.values(p.symbol("a"), p.symbol("b"), p.symbol("c")))))).matches(strictProject(ImmutableMap.of(), patternRecognition(builder -> builder.pattern(new IrLabel("X")).addVariableDefinition(new IrLabel("X"), new ComparisonExpression(GREATER_THAN, new FunctionCall(maxBy, ImmutableList.of(PlanBuilder.expression("a"), PlanBuilder.expression("b"))), PlanBuilder.expression("5"))), strictProject(ImmutableMap.of("a", expression("a"), "b", expression("b")), values("a", "b", "c")))));
}
use of io.trino.spi.type.BigintType.BIGINT in project trino by trinodb.
the class TestPrunePattenRecognitionColumns method testPruneUnreferencedMeasureAndSources.
@Test
public void testPruneUnreferencedMeasureAndSources() {
ResolvedFunction lag = createTestMetadataManager().resolveFunction(tester().getSession(), QualifiedName.of("lag"), fromTypes(BIGINT));
// remove row pattern measure "measure" and input symbol "a" used only by that measure
tester().assertThat(new PrunePattenRecognitionColumns()).on(p -> p.project(Assignments.identity(p.symbol("lag")), p.patternRecognition(builder -> builder.addWindowFunction(p.symbol("lag"), new WindowNode.Function(lag, ImmutableList.of(p.symbol("b").toSymbolReference()), DEFAULT_FRAME, false)).addMeasure(p.symbol("measure"), "LAST(X.a)", BIGINT).rowsPerMatch(WINDOW).frame(new WindowNode.Frame(ROWS, CURRENT_ROW, Optional.empty(), Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty())).skipTo(NEXT).pattern(new IrLabel("X")).addVariableDefinition(new IrLabel("X"), "true").source(p.values(p.symbol("a"), p.symbol("b")))))).matches(strictProject(ImmutableMap.of("lag", expression("lag")), patternRecognition(builder -> builder.addFunction("lag", functionCall("lag", ImmutableList.of("b"))).rowsPerMatch(WINDOW).frame(windowFrame(ROWS, CURRENT_ROW, Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty())).skipTo(NEXT).pattern(new IrLabel("X")).addVariableDefinition(new IrLabel("X"), "true"), strictProject(ImmutableMap.of("b", expression("b")), values("a", "b")))));
}
use of io.trino.spi.type.BigintType.BIGINT in project trino by trinodb.
the class TestValidateStreamingAggregations method testValidateSuccessful.
@Test
public void testValidateSuccessful() {
validatePlan(p -> p.aggregation(a -> a.step(SINGLE).singleGroupingSet(p.symbol("nationkey")).source(p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT))))));
validatePlan(p -> p.aggregation(a -> a.step(SINGLE).singleGroupingSet(p.symbol("unique"), p.symbol("nationkey")).preGroupedSymbols(p.symbol("unique"), p.symbol("nationkey")).source(p.assignUniqueId(p.symbol("unique"), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT)))))));
}
Aggregations