Search in sources :

Example 91 with ColumnHandle

use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.

the class TestPruneTableScanColumns method mockApplyProjection.

private Optional<ProjectionApplicationResult<ConnectorTableHandle>> mockApplyProjection(ConnectorSession session, ConnectorTableHandle tableHandle, List<ConnectorExpression> projections, Map<String, ColumnHandle> assignments) {
    MockConnectorTableHandle handle = (MockConnectorTableHandle) tableHandle;
    List<Variable> variables = projections.stream().map(Variable.class::cast).collect(toImmutableList());
    List<ColumnHandle> newColumns = variables.stream().map(variable -> assignments.get(variable.getName())).collect(toImmutableList());
    if (handle.getColumns().isPresent() && newColumns.equals(handle.getColumns().get())) {
        return Optional.empty();
    }
    return Optional.of(new ProjectionApplicationResult<>(new MockConnectorTableHandle(handle.getTableName(), handle.getConstraint(), Optional.of(newColumns)), projections, variables.stream().map(variable -> new Assignment(variable.getName(), assignments.get(variable.getName()), ((MockConnectorColumnHandle) assignments.get(variable.getName())).getType())).collect(toImmutableList()), false));
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) Variable(io.trino.spi.expression.Variable) CatalogName(io.trino.connector.CatalogName) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) ColumnHandle(io.trino.spi.connector.ColumnHandle) ProjectionApplicationResult(io.trino.spi.connector.ProjectionApplicationResult) Symbol(io.trino.sql.planner.Symbol) TINY_SCHEMA_NAME(io.trino.plugin.tpch.TpchMetadata.TINY_SCHEMA_NAME) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) RuleTester.defaultRuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) TINY_SCALE_FACTOR(io.trino.plugin.tpch.TpchMetadata.TINY_SCALE_FACTOR) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) Domain(io.trino.spi.predicate.Domain) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assignments(io.trino.sql.planner.plan.Assignments) ConnectorSession(io.trino.spi.connector.ConnectorSession) RuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester) TupleDomain(io.trino.spi.predicate.TupleDomain) SchemaTableName(io.trino.spi.connector.SchemaTableName) TpchTransactionHandle(io.trino.plugin.tpch.TpchTransactionHandle) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) MockConnectorTransactionHandle(io.trino.connector.MockConnectorTransactionHandle) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) TableHandle(io.trino.metadata.TableHandle) ConnectorExpression(io.trino.spi.expression.ConnectorExpression) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) Assignment(io.trino.spi.connector.Assignment) PlanMatchPattern.strictConstrainedTableScan(io.trino.sql.planner.assertions.PlanMatchPattern.strictConstrainedTableScan) Optional(java.util.Optional) TestingColumnHandle(io.trino.testing.TestingMetadata.TestingColumnHandle) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) DATE(io.trino.spi.type.DateType.DATE) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) PlanMatchPattern.strictTableScan(io.trino.sql.planner.assertions.PlanMatchPattern.strictTableScan) Assignment(io.trino.spi.connector.Assignment) ColumnHandle(io.trino.spi.connector.ColumnHandle) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) TestingColumnHandle(io.trino.testing.TestingMetadata.TestingColumnHandle) Variable(io.trino.spi.expression.Variable) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle)

Example 92 with ColumnHandle

use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.

the class AtopPageSourceProvider method createPageSource.

@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, ConnectorTableHandle table, List<ColumnHandle> columns, DynamicFilter dynamicFilter) {
    AtopTableHandle tableHandle = (AtopTableHandle) table;
    AtopSplit atopSplit = (AtopSplit) split;
    ImmutableList.Builder<Type> types = ImmutableList.builder();
    ImmutableList.Builder<AtopColumn> atopColumns = ImmutableList.builder();
    for (ColumnHandle column : columns) {
        AtopColumnHandle atopColumnHandle = (AtopColumnHandle) column;
        AtopColumn atopColumn = tableHandle.getTable().getColumn(atopColumnHandle.getName());
        atopColumns.add(atopColumn);
        types.add(typeManager.getType(atopColumn.getType()));
    }
    ZonedDateTime date = atopSplit.getDate();
    checkArgument(date.equals(date.withHour(0).withMinute(0).withSecond(0).withNano(0)), "Expected date to be at beginning of day");
    return new AtopPageSource(readerPermits, atopFactory, session, utf8Slice(atopSplit.getHost().getHostText()), tableHandle.getTable(), date, atopColumns.build(), types.build());
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) Type(io.trino.spi.type.Type) AtopColumn(io.trino.plugin.atop.AtopTable.AtopColumn) ZonedDateTime(java.time.ZonedDateTime) ImmutableList(com.google.common.collect.ImmutableList)

Example 93 with ColumnHandle

use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.

the class DefaultJdbcMetadata method applyFilter.

@Override
public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(ConnectorSession session, ConnectorTableHandle table, Constraint constraint) {
    JdbcTableHandle handle = (JdbcTableHandle) table;
    if (handle.getSortOrder().isPresent() && handle.getLimit().isPresent()) {
        handle = flushAttributesAsQuery(session, handle);
    }
    TupleDomain<ColumnHandle> oldDomain = handle.getConstraint();
    TupleDomain<ColumnHandle> newDomain = oldDomain.intersect(constraint.getSummary());
    List<String> newConstraintExpressions;
    TupleDomain<ColumnHandle> remainingFilter;
    Optional<ConnectorExpression> remainingExpression;
    if (newDomain.isNone()) {
        newConstraintExpressions = ImmutableList.of();
        remainingFilter = TupleDomain.all();
        remainingExpression = Optional.of(Constant.TRUE);
    } else {
        Map<ColumnHandle, Domain> domains = newDomain.getDomains().orElseThrow();
        List<JdbcColumnHandle> columnHandles = domains.keySet().stream().map(JdbcColumnHandle.class::cast).collect(toImmutableList());
        List<ColumnMapping> columnMappings = jdbcClient.toColumnMappings(session, columnHandles.stream().map(JdbcColumnHandle::getJdbcTypeHandle).collect(toImmutableList()));
        Map<ColumnHandle, Domain> supported = new HashMap<>();
        Map<ColumnHandle, Domain> unsupported = new HashMap<>();
        for (int i = 0; i < columnHandles.size(); i++) {
            JdbcColumnHandle column = columnHandles.get(i);
            ColumnMapping mapping = columnMappings.get(i);
            DomainPushdownResult pushdownResult = mapping.getPredicatePushdownController().apply(session, domains.get(column));
            supported.put(column, pushdownResult.getPushedDown());
            unsupported.put(column, pushdownResult.getRemainingFilter());
        }
        newDomain = TupleDomain.withColumnDomains(supported);
        remainingFilter = TupleDomain.withColumnDomains(unsupported);
        if (isComplexExpressionPushdown(session)) {
            List<String> newExpressions = new ArrayList<>();
            List<ConnectorExpression> remainingExpressions = new ArrayList<>();
            for (ConnectorExpression expression : extractConjuncts(constraint.getExpression())) {
                Optional<String> converted = jdbcClient.convertPredicate(session, expression, constraint.getAssignments());
                if (converted.isPresent()) {
                    newExpressions.add(converted.get());
                } else {
                    remainingExpressions.add(expression);
                }
            }
            newConstraintExpressions = ImmutableSet.<String>builder().addAll(handle.getConstraintExpressions()).addAll(newExpressions).build().asList();
            remainingExpression = Optional.of(and(remainingExpressions));
        } else {
            newConstraintExpressions = ImmutableList.of();
            remainingExpression = Optional.empty();
        }
    }
    if (oldDomain.equals(newDomain) && handle.getConstraintExpressions().equals(newConstraintExpressions)) {
        return Optional.empty();
    }
    handle = new JdbcTableHandle(handle.getRelationHandle(), newDomain, newConstraintExpressions, handle.getSortOrder(), handle.getLimit(), handle.getColumns(), handle.getOtherReferencedTables(), handle.getNextSyntheticColumnId());
    return Optional.of(remainingExpression.isPresent() ? new ConstraintApplicationResult<>(handle, remainingFilter, remainingExpression.get(), false) : new ConstraintApplicationResult<>(handle, remainingFilter, false));
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) HashMap(java.util.HashMap) ConnectorExpression(io.trino.spi.expression.ConnectorExpression) ArrayList(java.util.ArrayList) Constraint(io.trino.spi.connector.Constraint) ConstraintApplicationResult(io.trino.spi.connector.ConstraintApplicationResult) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) DomainPushdownResult(io.trino.plugin.jdbc.PredicatePushdownController.DomainPushdownResult)

Example 94 with ColumnHandle

use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.

the class BigQueryMetadata method applyProjection.

@Override
public Optional<ProjectionApplicationResult<ConnectorTableHandle>> applyProjection(ConnectorSession session, ConnectorTableHandle handle, List<ConnectorExpression> projections, Map<String, ColumnHandle> assignments) {
    log.debug("applyProjection(session=%s, handle=%s, projections=%s, assignments=%s)", session, handle, projections, assignments);
    BigQueryTableHandle bigQueryTableHandle = (BigQueryTableHandle) handle;
    List<ColumnHandle> newColumns = assignments.values().stream().collect(toImmutableList());
    if (bigQueryTableHandle.getProjectedColumns().isPresent() && containSameElements(newColumns, bigQueryTableHandle.getProjectedColumns().get())) {
        return Optional.empty();
    }
    ImmutableList.Builder<ColumnHandle> projectedColumns = ImmutableList.builder();
    ImmutableList.Builder<Assignment> assignmentList = ImmutableList.builder();
    assignments.forEach((name, column) -> {
        projectedColumns.add(column);
        assignmentList.add(new Assignment(name, column, ((BigQueryColumnHandle) column).getTrinoType()));
    });
    bigQueryTableHandle = bigQueryTableHandle.withProjectedColumns(projectedColumns.build());
    return Optional.of(new ProjectionApplicationResult<>(bigQueryTableHandle, projections, assignmentList.build(), false));
}
Also used : Assignment(io.trino.spi.connector.Assignment) ColumnHandle(io.trino.spi.connector.ColumnHandle) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList)

Example 95 with ColumnHandle

use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.

the class BlackHolePageSourceProvider method createPageSource.

@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, ConnectorTableHandle tableHandle, List<ColumnHandle> columns, DynamicFilter dynamicFilter) {
    BlackHoleTableHandle table = (BlackHoleTableHandle) tableHandle;
    ImmutableList.Builder<Type> builder = ImmutableList.builder();
    for (ColumnHandle column : columns) {
        builder.add(((BlackHoleColumnHandle) column).getColumnType());
    }
    List<Type> types = builder.build();
    Page page = generateZeroPage(types, table.getRowsPerPage(), table.getFieldsLength());
    return new BlackHolePageSource(page, table.getPagesPerSplit(), executorService, table.getPageProcessingDelay());
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) DoubleType(io.trino.spi.type.DoubleType) DateType(io.trino.spi.type.DateType) Type(io.trino.spi.type.Type) BooleanType(io.trino.spi.type.BooleanType) TimestampType(io.trino.spi.type.TimestampType) BigintType(io.trino.spi.type.BigintType) VarcharType(io.trino.spi.type.VarcharType) TinyintType(io.trino.spi.type.TinyintType) SmallintType(io.trino.spi.type.SmallintType) IntegerType(io.trino.spi.type.IntegerType) VarbinaryType(io.trino.spi.type.VarbinaryType) FixedWidthType(io.trino.spi.type.FixedWidthType) RealType(io.trino.spi.type.RealType) DecimalType(io.trino.spi.type.DecimalType) ImmutableList(com.google.common.collect.ImmutableList) Page(io.trino.spi.Page)

Aggregations

ColumnHandle (io.trino.spi.connector.ColumnHandle)268 Test (org.testng.annotations.Test)121 ImmutableList (com.google.common.collect.ImmutableList)106 TupleDomain (io.trino.spi.predicate.TupleDomain)104 ImmutableMap (com.google.common.collect.ImmutableMap)93 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)86 Domain (io.trino.spi.predicate.Domain)86 Map (java.util.Map)78 ConnectorSession (io.trino.spi.connector.ConnectorSession)76 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)71 Optional (java.util.Optional)70 List (java.util.List)69 SchemaTableName (io.trino.spi.connector.SchemaTableName)66 Constraint (io.trino.spi.connector.Constraint)61 Objects.requireNonNull (java.util.Objects.requireNonNull)53 ImmutableSet (com.google.common.collect.ImmutableSet)51 NullableValue (io.trino.spi.predicate.NullableValue)50 Type (io.trino.spi.type.Type)48 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)45 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)45