Search in sources :

Example 11 with LongLiteral

use of io.trino.sql.tree.LongLiteral in project trino by trinodb.

the class TestPushPredicateIntoTableScan method doesNotFireOnNonDeterministicPredicate.

@Test
public void doesNotFireOnNonDeterministicPredicate() {
    ColumnHandle columnHandle = new TpchColumnHandle("nationkey", BIGINT);
    tester().assertThat(pushPredicateIntoTableScan).on(p -> p.filter(new ComparisonExpression(EQUAL, functionResolution.functionCallBuilder(QualifiedName.of("rand")).build(), new LongLiteral("42")), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), columnHandle), TupleDomain.all()))).doesNotFire();
}
Also used : AND(io.trino.sql.tree.LogicalExpression.Operator.AND) TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) Test(org.testng.annotations.Test) CatalogName(io.trino.connector.CatalogName) MockConnectorFactory(io.trino.connector.MockConnectorFactory) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) LongLiteral(io.trino.sql.tree.LongLiteral) Slices(io.airlift.slice.Slices) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ImmutableMap(com.google.common.collect.ImmutableMap) Domain(io.trino.spi.predicate.Domain) BeforeClass(org.testng.annotations.BeforeClass) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) MODULUS(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.MODULUS) SchemaTableName(io.trino.spi.connector.SchemaTableName) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) GenericLiteral(io.trino.sql.tree.GenericLiteral) EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.EQUAL) PlanMatchPattern.anyTree(io.trino.sql.planner.assertions.PlanMatchPattern.anyTree) BIGINT(io.trino.spi.type.BigintType.BIGINT) ConnectorPartitioningHandle(io.trino.spi.connector.ConnectorPartitioningHandle) SymbolReference(io.trino.sql.tree.SymbolReference) Domain.singleValue(io.trino.spi.predicate.Domain.singleValue) PlanMatchPattern.constrainedTableScanWithTableLayout(io.trino.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) Optional(java.util.Optional) ConnectorTablePartitioning(io.trino.spi.connector.ConnectorTablePartitioning) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) Session(io.trino.Session) TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) NullableValue(io.trino.spi.predicate.NullableValue) Type(io.trino.spi.type.Type) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ColumnHandle(io.trino.spi.connector.ColumnHandle) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) ConstraintApplicationResult(io.trino.spi.connector.ConstraintApplicationResult) StringLiteral(io.trino.sql.tree.StringLiteral) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) TestingTransactionHandle(io.trino.testing.TestingTransactionHandle) TupleDomain(io.trino.spi.predicate.TupleDomain) TpchTransactionHandle(io.trino.plugin.tpch.TpchTransactionHandle) QualifiedName(io.trino.sql.tree.QualifiedName) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TableHandle(io.trino.metadata.TableHandle) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) LogicalExpression(io.trino.sql.tree.LogicalExpression) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) LongLiteral(io.trino.sql.tree.LongLiteral) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 12 with LongLiteral

use of io.trino.sql.tree.LongLiteral in project trino by trinodb.

the class TestPushProjectionIntoTableScan method testDoesNotFire.

@Test
public void testDoesNotFire() {
    try (RuleTester ruleTester = defaultRuleTester()) {
        String columnName = "input_column";
        Type columnType = ROW_TYPE;
        ColumnHandle inputColumnHandle = column(columnName, columnType);
        MockConnectorFactory factory = createMockFactory(ImmutableMap.of(columnName, inputColumnHandle), Optional.empty());
        ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, factory, ImmutableMap.of());
        PushProjectionIntoTableScan optimizer = createRule(ruleTester);
        ruleTester.assertThat(optimizer).on(p -> {
            Symbol symbol = p.symbol(columnName, columnType);
            return p.project(Assignments.of(p.symbol("symbol_dereference", BIGINT), new SubscriptExpression(symbol.toSymbolReference(), new LongLiteral("1"))), p.tableScan(TEST_TABLE_HANDLE, ImmutableList.of(symbol), ImmutableMap.of(symbol, inputColumnHandle)));
        }).withSession(MOCK_SESSION).doesNotFire();
    }
}
Also used : TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) MockConnectorFactory(io.trino.connector.MockConnectorFactory) RowType(io.trino.spi.type.RowType) Type(io.trino.spi.type.Type) LongLiteral(io.trino.sql.tree.LongLiteral) RuleTester.defaultRuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester) RuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester) Symbol(io.trino.sql.planner.Symbol) SubscriptExpression(io.trino.sql.tree.SubscriptExpression) Test(org.testng.annotations.Test)

Example 13 with LongLiteral

use of io.trino.sql.tree.LongLiteral in project trino by trinodb.

the class TestPushProjectionThroughExchange method testSkipIdentityProjectionIfOutputPresent.

@Test
public void testSkipIdentityProjectionIfOutputPresent() {
    // In the following example, the Projection over Exchange has got an identity assignment (a -> a).
    // The Projection is pushed down to Exchange's source, and the identity assignment is translated into
    // a0 -> a. The assignment is added to the pushed-down Projection because the input symbol 'a' is
    // required by the Exchange as a partitioning symbol.
    // When all the assignments from the parent Projection are added to the pushed-down Projection,
    // this assignment is omitted. Otherwise the doubled assignment would cause an error.
    tester().assertThat(new PushProjectionThroughExchange()).on(p -> {
        Symbol a = p.symbol("a");
        Symbol aTimes5 = p.symbol("a_times_5");
        return p.project(Assignments.of(aTimes5, new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.MULTIPLY, new SymbolReference("a"), new LongLiteral("5")), a, a.toSymbolReference()), p.exchange(e -> e.addSource(p.values(a)).addInputsSet(a).fixedHashDistributionParitioningScheme(ImmutableList.of(a), ImmutableList.of(a))));
    }).matches(exchange(strictProject(ImmutableMap.of("a_0", expression("a"), "a_times_5", expression("a * 5")), values(ImmutableList.of("a")))));
    // In the following example, the Projection over Exchange has got an identity assignment (b -> b).
    // The Projection is pushed down to Exchange's source, and the identity assignment is translated into
    // a0 -> a. The assignment is added to the pushed-down Projection because the input symbol 'a' is
    // required by the Exchange as a partitioning symbol.
    // When all the assignments from the parent Projection are added to the pushed-down Projection,
    // this assignment is omitted. Otherwise the doubled assignment would cause an error.
    tester().assertThat(new PushProjectionThroughExchange()).on(p -> {
        Symbol a = p.symbol("a");
        Symbol bTimes5 = p.symbol("b_times_5");
        Symbol b = p.symbol("b");
        return p.project(Assignments.of(bTimes5, new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.MULTIPLY, new SymbolReference("b"), new LongLiteral("5")), b, b.toSymbolReference()), p.exchange(e -> e.addSource(p.values(a)).addInputsSet(a).fixedHashDistributionParitioningScheme(ImmutableList.of(b), ImmutableList.of(b))));
    }).matches(exchange(strictProject(ImmutableMap.of("a_0", expression("a"), "a_times_5", expression("a * 5")), values(ImmutableList.of("a")))));
}
Also used : Symbol(io.trino.sql.planner.Symbol) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Assignments(io.trino.sql.planner.plan.Assignments) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) OrderingScheme(io.trino.sql.planner.OrderingScheme) FIRST(io.trino.sql.tree.SortItem.NullOrdering.FIRST) SortOrder(io.trino.spi.connector.SortOrder) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) GATHER(io.trino.sql.planner.plan.ExchangeNode.Type.GATHER) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) SymbolReference(io.trino.sql.tree.SymbolReference) LongLiteral(io.trino.sql.tree.LongLiteral) PlanMatchPattern.exchange(io.trino.sql.planner.assertions.PlanMatchPattern.exchange) PlanMatchPattern.sort(io.trino.sql.planner.assertions.PlanMatchPattern.sort) REMOTE(io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) ASCENDING(io.trino.sql.tree.SortItem.Ordering.ASCENDING) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) LongLiteral(io.trino.sql.tree.LongLiteral) Symbol(io.trino.sql.planner.Symbol) SymbolReference(io.trino.sql.tree.SymbolReference) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Example 14 with LongLiteral

use of io.trino.sql.tree.LongLiteral in project trino by trinodb.

the class TestPushLimitThroughProject method testPushDownLimitThroughOverlappingDereferences.

@Test
public void testPushDownLimitThroughOverlappingDereferences() {
    RowType rowType = RowType.from(ImmutableList.of(new RowType.Field(Optional.of("x"), BIGINT), new RowType.Field(Optional.of("y"), BIGINT)));
    tester().assertThat(new PushLimitThroughProject(tester().getTypeAnalyzer())).on(p -> {
        Symbol a = p.symbol("a", rowType);
        return p.limit(1, p.project(Assignments.of(p.symbol("b"), new SubscriptExpression(a.toSymbolReference(), new LongLiteral("1")), p.symbol("c", rowType), a.toSymbolReference()), p.values(a)));
    }).matches(project(ImmutableMap.of("b", expression("a[1]"), "c", expression("a")), limit(1, values("a"))));
}
Also used : ExpressionMatcher(io.trino.sql.planner.assertions.ExpressionMatcher) Symbol(io.trino.sql.planner.Symbol) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) RowType(io.trino.spi.type.RowType) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Assignments(io.trino.sql.planner.plan.Assignments) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) TRUE_LITERAL(io.trino.sql.tree.BooleanLiteral.TRUE_LITERAL) FIRST(io.trino.sql.tree.SortItem.NullOrdering.FIRST) SubscriptExpression(io.trino.sql.tree.SubscriptExpression) PlanMatchPattern.limit(io.trino.sql.planner.assertions.PlanMatchPattern.limit) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) ADD(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.ADD) ImmutableList(com.google.common.collect.ImmutableList) BIGINT(io.trino.spi.type.BigintType.BIGINT) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) SymbolReference(io.trino.sql.tree.SymbolReference) LongLiteral(io.trino.sql.tree.LongLiteral) PlanMatchPattern.sort(io.trino.sql.planner.assertions.PlanMatchPattern.sort) Optional(java.util.Optional) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) ASCENDING(io.trino.sql.tree.SortItem.Ordering.ASCENDING) LongLiteral(io.trino.sql.tree.LongLiteral) Symbol(io.trino.sql.planner.Symbol) RowType(io.trino.spi.type.RowType) SubscriptExpression(io.trino.sql.tree.SubscriptExpression) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Example 15 with LongLiteral

use of io.trino.sql.tree.LongLiteral in project trino by trinodb.

the class TestRemoveUnreferencedScalarSubqueries method testDoNotRemoveInputOfLeftOrFullJoinWhenSubqueryPotentiallyEmpty.

@Test
public void testDoNotRemoveInputOfLeftOrFullJoinWhenSubqueryPotentiallyEmpty() {
    tester().assertThat(new RemoveUnreferencedScalarSubqueries()).on(p -> {
        Symbol b = p.symbol("b");
        return p.correlatedJoin(emptyList(), p.values(emptyList(), ImmutableList.of(emptyList())), LEFT, TRUE_LITERAL, p.filter(new ComparisonExpression(LESS_THAN, b.toSymbolReference(), new LongLiteral("3")), p.values(2, b)));
    }).doesNotFire();
    tester().assertThat(new RemoveUnreferencedScalarSubqueries()).on(p -> {
        Symbol b = p.symbol("b");
        return p.correlatedJoin(emptyList(), p.values(emptyList(), ImmutableList.of(emptyList())), FULL, TRUE_LITERAL, p.filter(new ComparisonExpression(LESS_THAN, b.toSymbolReference(), new LongLiteral("3")), p.values(2, b)));
    }).doesNotFire();
}
Also used : Symbol(io.trino.sql.planner.Symbol) LEFT(io.trino.sql.planner.plan.CorrelatedJoinNode.Type.LEFT) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) RIGHT(io.trino.sql.planner.plan.CorrelatedJoinNode.Type.RIGHT) Collections.emptyList(java.util.Collections.emptyList) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) TRUE_LITERAL(io.trino.sql.tree.BooleanLiteral.TRUE_LITERAL) LESS_THAN(io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) BigintType(io.trino.spi.type.BigintType) FULL(io.trino.sql.planner.plan.CorrelatedJoinNode.Type.FULL) ImmutableList(com.google.common.collect.ImmutableList) LongLiteral(io.trino.sql.tree.LongLiteral) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) LongLiteral(io.trino.sql.tree.LongLiteral) Symbol(io.trino.sql.planner.Symbol) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Aggregations

LongLiteral (io.trino.sql.tree.LongLiteral)78 Test (org.testng.annotations.Test)34 Test (org.junit.jupiter.api.Test)32 StringLiteral (io.trino.sql.tree.StringLiteral)27 ImmutableList (com.google.common.collect.ImmutableList)24 FunctionCall (io.trino.sql.tree.FunctionCall)22 Symbol (io.trino.sql.planner.Symbol)21 Identifier (io.trino.sql.tree.Identifier)18 SymbolReference (io.trino.sql.tree.SymbolReference)18 ImmutableMap (com.google.common.collect.ImmutableMap)17 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)17 ArithmeticBinaryExpression (io.trino.sql.tree.ArithmeticBinaryExpression)17 QualifiedName (io.trino.sql.tree.QualifiedName)16 Optional (java.util.Optional)16 BaseRuleTest (io.trino.sql.planner.iterative.rule.test.BaseRuleTest)15 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)15 Expression (io.trino.sql.tree.Expression)15 BIGINT (io.trino.spi.type.BigintType.BIGINT)12 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)12 SubscriptExpression (io.trino.sql.tree.SubscriptExpression)12