Search in sources :

Example 11 with TableScanNode

use of io.trino.sql.planner.plan.TableScanNode in project trino by trinodb.

the class TestSchedulingOrderVisitor method testIndexJoinOrder.

@Test
public void testIndexJoinOrder() {
    PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata(), TEST_SESSION);
    TableScanNode a = planBuilder.tableScan(emptyList(), emptyMap());
    TableScanNode b = planBuilder.tableScan(emptyList(), emptyMap());
    List<PlanNodeId> order = scheduleOrder(planBuilder.indexJoin(IndexJoinNode.Type.INNER, a, b));
    assertEquals(order, ImmutableList.of(b.getId(), a.getId()));
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TableScanNode(io.trino.sql.planner.plan.TableScanNode) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 12 with TableScanNode

use of io.trino.sql.planner.plan.TableScanNode in project trino by trinodb.

the class ColumnReference method getAssignedSymbol.

@Override
public Optional<Symbol> getAssignedSymbol(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    TableHandle tableHandle;
    Map<Symbol, ColumnHandle> assignments;
    if (node instanceof TableScanNode) {
        TableScanNode tableScanNode = (TableScanNode) node;
        tableHandle = tableScanNode.getTable();
        assignments = tableScanNode.getAssignments();
    } else if (node instanceof IndexSourceNode) {
        IndexSourceNode indexSourceNode = (IndexSourceNode) node;
        tableHandle = indexSourceNode.getTableHandle();
        assignments = indexSourceNode.getAssignments();
    } else {
        return Optional.empty();
    }
    TableMetadata tableMetadata = metadata.getTableMetadata(session, tableHandle);
    String actualTableName = tableMetadata.getTable().getTableName();
    // Wrong table -> doesn't match.
    if (!tableName.equalsIgnoreCase(actualTableName)) {
        return Optional.empty();
    }
    Optional<ColumnHandle> columnHandle = getColumnHandle(tableHandle, session, metadata);
    checkState(columnHandle.isPresent(), "Table %s doesn't have column %s. Typo in test?", tableName, columnName);
    return getAssignedSymbol(assignments, columnHandle.get());
}
Also used : TableMetadata(io.trino.metadata.TableMetadata) ColumnHandle(io.trino.spi.connector.ColumnHandle) TableScanNode(io.trino.sql.planner.plan.TableScanNode) Symbol(io.trino.sql.planner.Symbol) IndexSourceNode(io.trino.sql.planner.plan.IndexSourceNode) TableHandle(io.trino.metadata.TableHandle)

Example 13 with TableScanNode

use of io.trino.sql.planner.plan.TableScanNode in project trino by trinodb.

the class TestPushJoinIntoTableScan method testPushJoinIntoTableRequiresFullColumnHandleMappingInResult.

@Test
public void testPushJoinIntoTableRequiresFullColumnHandleMappingInResult() {
    try (RuleTester ruleTester = defaultRuleTester()) {
        MockConnectorFactory connectorFactory = createMockConnectorFactory((session, applyJoinType, left, right, joinConditions, leftAssignments, rightAssignments) -> Optional.of(new JoinApplicationResult<>(JOIN_CONNECTOR_TABLE_HANDLE, ImmutableMap.of(COLUMN_A1_HANDLE, JOIN_COLUMN_A1_HANDLE, COLUMN_A2_HANDLE, JOIN_COLUMN_A2_HANDLE), // mapping for COLUMN_B1_HANDLE is missing
        ImmutableMap.of(), false)));
        ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, connectorFactory, ImmutableMap.of());
        assertThatThrownBy(() -> {
            ruleTester.assertThat(new PushJoinIntoTableScan(ruleTester.getMetadata())).on(p -> {
                Symbol columnA1Symbol = p.symbol(COLUMN_A1);
                Symbol columnA2Symbol = p.symbol(COLUMN_A2);
                Symbol columnB1Symbol = p.symbol(COLUMN_B1);
                TupleDomain<ColumnHandle> leftContraint = TupleDomain.fromFixedValues(ImmutableMap.of(COLUMN_A2_HANDLE, NullableValue.of(BIGINT, 44L)));
                TupleDomain<ColumnHandle> rightConstraint = TupleDomain.fromFixedValues(ImmutableMap.of(COLUMN_B1_HANDLE, NullableValue.of(BIGINT, 45L)));
                TableScanNode left = p.tableScan(TABLE_A_HANDLE, ImmutableList.of(columnA1Symbol, columnA2Symbol), ImmutableMap.of(columnA1Symbol, COLUMN_A1_HANDLE, columnA2Symbol, COLUMN_A2_HANDLE), leftContraint);
                TableScanNode right = p.tableScan(TABLE_B_HANDLE, ImmutableList.of(columnB1Symbol), ImmutableMap.of(columnB1Symbol, COLUMN_B1_HANDLE), rightConstraint);
                return p.join(INNER, left, right, new JoinNode.EquiJoinClause(columnA1Symbol, columnB1Symbol));
            }).withSession(MOCK_SESSION).matches(anyTree());
        }).isInstanceOf(IllegalStateException.class).hasMessageContaining("Column handle mappings do not match old column handles");
    }
}
Also used : MockConnectorFactory(io.trino.connector.MockConnectorFactory) ColumnHandle(io.trino.spi.connector.ColumnHandle) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) TableScanNode(io.trino.sql.planner.plan.TableScanNode) 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) JoinNode(io.trino.sql.planner.plan.JoinNode) JoinApplicationResult(io.trino.spi.connector.JoinApplicationResult) Test(org.testng.annotations.Test)

Example 14 with TableScanNode

use of io.trino.sql.planner.plan.TableScanNode in project trino by trinodb.

the class TestPushJoinIntoTableScan method testPushJoinIntoTableScanDoesNotTriggerWithUnsupportedFilter.

@Test
public void testPushJoinIntoTableScanDoesNotTriggerWithUnsupportedFilter() {
    try (RuleTester ruleTester = defaultRuleTester()) {
        MockConnectorFactory connectorFactory = createMockConnectorFactory((session, applyJoinType, left, right, joinConditions, leftAssignments, rightAssignments) -> {
            throw new IllegalStateException("applyJoin should not be called!");
        });
        ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, connectorFactory, ImmutableMap.of());
        ruleTester.assertThat(new PushJoinIntoTableScan(ruleTester.getMetadata())).on(p -> {
            Symbol columnA1Symbol = p.symbol(COLUMN_A1);
            Symbol columnA2Symbol = p.symbol(COLUMN_A2);
            Symbol columnB1Symbol = p.symbol(COLUMN_B1);
            TableScanNode left = p.tableScan(TABLE_A_HANDLE, ImmutableList.of(columnA1Symbol, columnA2Symbol), ImmutableMap.of(columnA1Symbol, COLUMN_A1_HANDLE, columnA2Symbol, COLUMN_A2_HANDLE));
            TableScanNode right = p.tableScan(TABLE_B_HANDLE, ImmutableList.of(columnB1Symbol), ImmutableMap.of(columnB1Symbol, COLUMN_B1_HANDLE));
            return p.join(INNER, left, right, new ComparisonExpression(ComparisonExpression.Operator.GREATER_THAN, new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.MULTIPLY, new GenericLiteral("BIGINT", "44"), columnA1Symbol.toSymbolReference()), columnB1Symbol.toSymbolReference()));
        }).withSession(MOCK_SESSION).doesNotFire();
    }
}
Also used : ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) MockConnectorFactory(io.trino.connector.MockConnectorFactory) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) TableScanNode(io.trino.sql.planner.plan.TableScanNode) 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) GenericLiteral(io.trino.sql.tree.GenericLiteral) Test(org.testng.annotations.Test)

Example 15 with TableScanNode

use of io.trino.sql.planner.plan.TableScanNode in project trino by trinodb.

the class TestPushJoinIntoTableScan method testPushJoinIntoTableScanPreservesEnforcedConstraint.

@Test(dataProvider = "testPushJoinIntoTableScanPreservesEnforcedConstraintParams")
public void testPushJoinIntoTableScanPreservesEnforcedConstraint(JoinNode.Type joinType, TupleDomain<ColumnHandle> leftConstraint, TupleDomain<ColumnHandle> rightConstraint, TupleDomain<Predicate<ColumnHandle>> expectedConstraint) {
    try (RuleTester ruleTester = defaultRuleTester()) {
        MockConnectorFactory connectorFactory = createMockConnectorFactory((session, applyJoinType, left, right, joinConditions, leftAssignments, rightAssignments) -> Optional.of(new JoinApplicationResult<>(JOIN_CONNECTOR_TABLE_HANDLE, JOIN_TABLE_A_COLUMN_MAPPING, JOIN_TABLE_B_COLUMN_MAPPING, false)));
        ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, connectorFactory, ImmutableMap.of());
        ruleTester.assertThat(new PushJoinIntoTableScan(ruleTester.getMetadata())).on(p -> {
            Symbol columnA1Symbol = p.symbol(COLUMN_A1);
            Symbol columnA2Symbol = p.symbol(COLUMN_A2);
            Symbol columnB1Symbol = p.symbol(COLUMN_B1);
            TableScanNode left = p.tableScan(TABLE_A_HANDLE, ImmutableList.of(columnA1Symbol, columnA2Symbol), ImmutableMap.of(columnA1Symbol, COLUMN_A1_HANDLE, columnA2Symbol, COLUMN_A2_HANDLE), leftConstraint);
            TableScanNode right = p.tableScan(TABLE_B_HANDLE, ImmutableList.of(columnB1Symbol), ImmutableMap.of(columnB1Symbol, COLUMN_B1_HANDLE), rightConstraint);
            return p.join(joinType, left, right, new JoinNode.EquiJoinClause(columnA1Symbol, columnB1Symbol));
        }).withSession(MOCK_SESSION).matches(project(tableScan(tableHandle -> JOIN_PUSHDOWN_SCHEMA_TABLE_NAME.equals(((MockConnectorTableHandle) tableHandle).getTableName()), expectedConstraint, ImmutableMap.of())));
    }
}
Also used : MockConnectorFactory(io.trino.connector.MockConnectorFactory) TableScanNode(io.trino.sql.planner.plan.TableScanNode) 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) JoinNode(io.trino.sql.planner.plan.JoinNode) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) JoinApplicationResult(io.trino.spi.connector.JoinApplicationResult) Test(org.testng.annotations.Test)

Aggregations

TableScanNode (io.trino.sql.planner.plan.TableScanNode)58 Test (org.testng.annotations.Test)34 Symbol (io.trino.sql.planner.Symbol)30 JoinNode (io.trino.sql.planner.plan.JoinNode)26 ColumnHandle (io.trino.spi.connector.ColumnHandle)24 PlanNode (io.trino.sql.planner.plan.PlanNode)21 Type (io.trino.spi.type.Type)18 FilterNode (io.trino.sql.planner.plan.FilterNode)17 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)17 Expression (io.trino.sql.tree.Expression)17 ImmutableList (com.google.common.collect.ImmutableList)14 TableHandle (io.trino.metadata.TableHandle)14 Session (io.trino.Session)13 TypeSignatureTranslator.toSqlType (io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType)13 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 TestingColumnHandle (io.trino.testing.TestingMetadata.TestingColumnHandle)12 Optional (java.util.Optional)11 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)10 TupleDomain (io.trino.spi.predicate.TupleDomain)10