Search in sources :

Example 46 with BIGINT

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);
}
Also used : AggregateFunction(io.trino.spi.connector.AggregateFunction) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) PlanMatchPattern.limit(io.trino.sql.planner.assertions.PlanMatchPattern.limit) CatalogName(io.trino.connector.CatalogName) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Map(java.util.Map) ColumnHandle(io.trino.spi.connector.ColumnHandle) Symbol(io.trino.sql.planner.Symbol) ApplyAggregation(io.trino.connector.MockConnectorFactory.ApplyAggregation) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) SchemaTableName(io.trino.spi.connector.SchemaTableName) AggregationApplicationResult(io.trino.spi.connector.AggregationApplicationResult) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) MockConnectorTransactionHandle(io.trino.connector.MockConnectorTransactionHandle) List(java.util.List) TableHandle(io.trino.metadata.TableHandle) BIGINT(io.trino.spi.type.BigintType.BIGINT) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) TestingSession(io.trino.testing.TestingSession) Optional(java.util.Optional) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) Session(io.trino.Session) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Symbol(io.trino.sql.planner.Symbol) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 47 with BIGINT

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")))));
}
Also used : CURRENT_ROW(io.trino.sql.tree.FrameBound.Type.CURRENT_ROW) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) Test(org.testng.annotations.Test) PlanMatchPattern.patternRecognition(io.trino.sql.planner.assertions.PlanMatchPattern.patternRecognition) FOLLOWING(io.trino.sql.tree.FrameBound.Type.FOLLOWING) PlanMatchPattern.specification(io.trino.sql.planner.assertions.PlanMatchPattern.specification) ALL_WITH_UNMATCHED(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch.ALL_WITH_UNMATCHED) ALL_SHOW_EMPTY(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch.ALL_SHOW_EMPTY) ImmutableList(com.google.common.collect.ImmutableList) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) GREATER_THAN(io.trino.sql.tree.ComparisonExpression.Operator.GREATER_THAN) WINDOW(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch.WINDOW) NEXT(io.trino.sql.tree.SkipTo.Position.NEXT) FunctionCall(io.trino.sql.tree.FunctionCall) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) ResolvedFunction(io.trino.metadata.ResolvedFunction) Assignments(io.trino.sql.planner.plan.Assignments) PAST_LAST(io.trino.sql.tree.SkipTo.Position.PAST_LAST) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) OrderingScheme(io.trino.sql.planner.OrderingScheme) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) DEFAULT_FRAME(io.trino.sql.planner.plan.WindowNode.Frame.DEFAULT_FRAME) PlanMatchPattern.functionCall(io.trino.sql.planner.assertions.PlanMatchPattern.functionCall) PlanMatchPattern.windowFrame(io.trino.sql.planner.assertions.PlanMatchPattern.windowFrame) QualifiedName(io.trino.sql.tree.QualifiedName) ASC_NULLS_LAST(io.trino.spi.connector.SortOrder.ASC_NULLS_LAST) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) BIGINT(io.trino.spi.type.BigintType.BIGINT) MetadataManager.createTestMetadataManager(io.trino.metadata.MetadataManager.createTestMetadataManager) Optional(java.util.Optional) ROWS(io.trino.sql.tree.WindowFrame.Type.ROWS) WindowNode(io.trino.sql.planner.plan.WindowNode) UNBOUNDED_FOLLOWING(io.trino.sql.tree.FrameBound.Type.UNBOUNDED_FOLLOWING) IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) ResolvedFunction(io.trino.metadata.ResolvedFunction) WindowNode(io.trino.sql.planner.plan.WindowNode) ResolvedFunction(io.trino.metadata.ResolvedFunction) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 48 with BIGINT

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")))));
}
Also used : CURRENT_ROW(io.trino.sql.tree.FrameBound.Type.CURRENT_ROW) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) Test(org.testng.annotations.Test) PlanMatchPattern.patternRecognition(io.trino.sql.planner.assertions.PlanMatchPattern.patternRecognition) FOLLOWING(io.trino.sql.tree.FrameBound.Type.FOLLOWING) PlanMatchPattern.specification(io.trino.sql.planner.assertions.PlanMatchPattern.specification) ALL_WITH_UNMATCHED(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch.ALL_WITH_UNMATCHED) ALL_SHOW_EMPTY(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch.ALL_SHOW_EMPTY) ImmutableList(com.google.common.collect.ImmutableList) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) GREATER_THAN(io.trino.sql.tree.ComparisonExpression.Operator.GREATER_THAN) WINDOW(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch.WINDOW) NEXT(io.trino.sql.tree.SkipTo.Position.NEXT) FunctionCall(io.trino.sql.tree.FunctionCall) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) ResolvedFunction(io.trino.metadata.ResolvedFunction) Assignments(io.trino.sql.planner.plan.Assignments) PAST_LAST(io.trino.sql.tree.SkipTo.Position.PAST_LAST) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) OrderingScheme(io.trino.sql.planner.OrderingScheme) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) DEFAULT_FRAME(io.trino.sql.planner.plan.WindowNode.Frame.DEFAULT_FRAME) PlanMatchPattern.functionCall(io.trino.sql.planner.assertions.PlanMatchPattern.functionCall) PlanMatchPattern.windowFrame(io.trino.sql.planner.assertions.PlanMatchPattern.windowFrame) QualifiedName(io.trino.sql.tree.QualifiedName) ASC_NULLS_LAST(io.trino.spi.connector.SortOrder.ASC_NULLS_LAST) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) BIGINT(io.trino.spi.type.BigintType.BIGINT) MetadataManager.createTestMetadataManager(io.trino.metadata.MetadataManager.createTestMetadataManager) Optional(java.util.Optional) ROWS(io.trino.sql.tree.WindowFrame.Type.ROWS) WindowNode(io.trino.sql.planner.plan.WindowNode) UNBOUNDED_FOLLOWING(io.trino.sql.tree.FrameBound.Type.UNBOUNDED_FOLLOWING) IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) QualifiedName(io.trino.sql.tree.QualifiedName) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 49 with BIGINT

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")))));
}
Also used : CURRENT_ROW(io.trino.sql.tree.FrameBound.Type.CURRENT_ROW) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) Test(org.testng.annotations.Test) PlanMatchPattern.patternRecognition(io.trino.sql.planner.assertions.PlanMatchPattern.patternRecognition) FOLLOWING(io.trino.sql.tree.FrameBound.Type.FOLLOWING) PlanMatchPattern.specification(io.trino.sql.planner.assertions.PlanMatchPattern.specification) ALL_WITH_UNMATCHED(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch.ALL_WITH_UNMATCHED) ALL_SHOW_EMPTY(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch.ALL_SHOW_EMPTY) ImmutableList(com.google.common.collect.ImmutableList) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) GREATER_THAN(io.trino.sql.tree.ComparisonExpression.Operator.GREATER_THAN) WINDOW(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch.WINDOW) NEXT(io.trino.sql.tree.SkipTo.Position.NEXT) FunctionCall(io.trino.sql.tree.FunctionCall) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) ResolvedFunction(io.trino.metadata.ResolvedFunction) Assignments(io.trino.sql.planner.plan.Assignments) PAST_LAST(io.trino.sql.tree.SkipTo.Position.PAST_LAST) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) OrderingScheme(io.trino.sql.planner.OrderingScheme) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) DEFAULT_FRAME(io.trino.sql.planner.plan.WindowNode.Frame.DEFAULT_FRAME) PlanMatchPattern.functionCall(io.trino.sql.planner.assertions.PlanMatchPattern.functionCall) PlanMatchPattern.windowFrame(io.trino.sql.planner.assertions.PlanMatchPattern.windowFrame) QualifiedName(io.trino.sql.tree.QualifiedName) ASC_NULLS_LAST(io.trino.spi.connector.SortOrder.ASC_NULLS_LAST) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) BIGINT(io.trino.spi.type.BigintType.BIGINT) MetadataManager.createTestMetadataManager(io.trino.metadata.MetadataManager.createTestMetadataManager) Optional(java.util.Optional) ROWS(io.trino.sql.tree.WindowFrame.Type.ROWS) WindowNode(io.trino.sql.planner.plan.WindowNode) UNBOUNDED_FOLLOWING(io.trino.sql.tree.FrameBound.Type.UNBOUNDED_FOLLOWING) IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) ResolvedFunction(io.trino.metadata.ResolvedFunction) WindowNode(io.trino.sql.planner.plan.WindowNode) ResolvedFunction(io.trino.metadata.ResolvedFunction) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 50 with BIGINT

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)))))));
}
Also used : TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) SINGLE(io.trino.sql.planner.plan.AggregationNode.Step.SINGLE) Test(org.testng.annotations.Test) Function(java.util.function.Function) PlanNode(io.trino.sql.planner.plan.PlanNode) TpchTransactionHandle(io.trino.plugin.tpch.TpchTransactionHandle) CatalogName(io.trino.connector.CatalogName) TableHandle(io.trino.metadata.TableHandle) TypeAnalyzer(io.trino.sql.planner.TypeAnalyzer) ImmutableList(com.google.common.collect.ImmutableList) BIGINT(io.trino.spi.type.BigintType.BIGINT) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) WarningCollector(io.trino.execution.warnings.WarningCollector) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) TypeProvider(io.trino.sql.planner.TypeProvider) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) PlannerContext(io.trino.sql.PlannerContext) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Aggregations

BIGINT (io.trino.spi.type.BigintType.BIGINT)106 ImmutableList (com.google.common.collect.ImmutableList)99 Optional (java.util.Optional)87 Test (org.testng.annotations.Test)86 ImmutableMap (com.google.common.collect.ImmutableMap)84 VARCHAR (io.trino.spi.type.VarcharType.VARCHAR)44 List (java.util.List)44 Map (java.util.Map)44 ColumnHandle (io.trino.spi.connector.ColumnHandle)38 Type (io.trino.spi.type.Type)38 Symbol (io.trino.sql.planner.Symbol)38 QualifiedName (io.trino.sql.tree.QualifiedName)38 ImmutableSet (com.google.common.collect.ImmutableSet)37 TupleDomain (io.trino.spi.predicate.TupleDomain)36 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)36 TableHandle (io.trino.metadata.TableHandle)35 BaseRuleTest (io.trino.sql.planner.iterative.rule.test.BaseRuleTest)35 Session (io.trino.Session)34 PlanMatchPattern.filter (io.trino.sql.planner.assertions.PlanMatchPattern.filter)33 PlanBuilder.expression (io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression)32