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));
}
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());
}
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));
}
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));
}
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());
}
Aggregations