Skip to content

Commit

Permalink
Remove TableLayout objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Praveen2112 committed Jan 13, 2022
1 parent 220261a commit efc87b0
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 555 deletions.
6 changes: 0 additions & 6 deletions core/trino-main/src/main/java/io/trino/metadata/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ Optional<TableExecuteHandle> getTableHandleForExecute(

void finishTableExecute(Session session, TableExecuteHandle handle, Collection<Slice> fragments, List<Object> tableExecuteState);

@Deprecated
Optional<TableLayoutResult> getLayout(Session session, TableHandle tableHandle, Constraint constraint, Optional<Set<ColumnHandle>> desiredColumns);

TableProperties getTableProperties(Session session, TableHandle handle);

/**
Expand Down Expand Up @@ -449,9 +446,6 @@ default boolean isView(Session session, QualifiedObjectName viewName)
*/
Optional<ResolvedIndex> resolveIndex(Session session, TableHandle tableHandle, Set<ColumnHandle> indexableColumns, Set<ColumnHandle> outputColumns, TupleDomain<ColumnHandle> tupleDomain);

@Deprecated
boolean usesLegacyTableLayouts(Session session, TableHandle table);

Optional<LimitApplicationResult<TableHandle>> applyLimit(Session session, TableHandle table, long limit);

Optional<ConstraintApplicationResult<TableHandle>> applyFilter(Session session, TableHandle table, Constraint constraint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.connector.ConnectorTableExecuteHandle;
import io.trino.spi.connector.ConnectorTableHandle;
import io.trino.spi.connector.ConnectorTableLayout;
import io.trino.spi.connector.ConnectorTableLayoutResult;
import io.trino.spi.connector.ConnectorTableMetadata;
import io.trino.spi.connector.ConnectorTableProperties;
import io.trino.spi.connector.ConnectorTableSchema;
import io.trino.spi.connector.ConnectorTableVersion;
import io.trino.spi.connector.ConnectorTransactionHandle;
Expand Down Expand Up @@ -442,39 +439,6 @@ public Optional<SystemTable> getSystemTable(Session session, QualifiedObjectName
return Optional.empty();
}

@Override
public Optional<TableLayoutResult> getLayout(Session session, TableHandle table, Constraint constraint, Optional<Set<ColumnHandle>> desiredColumns)
{
if (constraint.getSummary().isNone()) {
return Optional.empty();
}

CatalogName catalogName = table.getCatalogName();
ConnectorTableHandle connectorTable = table.getConnectorHandle();

CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogName);
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(catalogName);

checkState(metadata.usesLegacyTableLayouts(), "getLayout() was called even though connector doesn't support legacy Table Layout");

ConnectorTransactionHandle transaction = catalogMetadata.getTransactionHandleFor(catalogName);
ConnectorSession connectorSession = session.toConnectorSession(catalogName);
List<ConnectorTableLayoutResult> layouts = metadata.getTableLayouts(connectorSession, connectorTable, constraint, desiredColumns);
if (layouts.isEmpty()) {
return Optional.empty();
}

if (layouts.size() > 1) {
throw new TrinoException(NOT_SUPPORTED, format("Connector returned multiple layouts for table %s", table));
}

ConnectorTableLayout tableLayout = layouts.get(0).getTableLayout();
return Optional.of(new TableLayoutResult(
new TableHandle(catalogName, connectorTable, transaction, Optional.of(tableLayout.getHandle())),
new TableProperties(catalogName, transaction, new ConnectorTableProperties(tableLayout)),
layouts.get(0).getUnenforcedConstraint()));
}

@Override
public TableProperties getTableProperties(Session session, TableHandle handle)
{
Expand Down Expand Up @@ -1608,12 +1572,6 @@ public Optional<ResolvedIndex> resolveIndex(Session session, TableHandle tableHa
return resolvedIndex.map(resolved -> new ResolvedIndex(tableHandle.getCatalogName(), transaction, resolved));
}

@Override
public boolean usesLegacyTableLayouts(Session session, TableHandle table)
{
return getMetadata(session, table.getCatalogName()).usesLegacyTableLayouts();
}

@Override
public Optional<LimitApplicationResult<TableHandle>> applyLimit(Session session, TableHandle table, long limit)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.trino.matching.Pattern;
import io.trino.metadata.Metadata;
import io.trino.metadata.TableHandle;
import io.trino.metadata.TableLayoutResult;
import io.trino.metadata.TableProperties;
import io.trino.metadata.TableProperties.TablePartitioning;
import io.trino.spi.connector.ColumnHandle;
Expand All @@ -50,7 +49,6 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Verify.verify;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static io.trino.SystemSessionProperties.isAllowPushdownIntoConnectors;
import static io.trino.matching.Capture.newCapture;
import static io.trino.sql.ExpressionUtils.combineConjuncts;
Expand Down Expand Up @@ -196,72 +194,48 @@ public static Optional<PlanNode> pushFilterIntoTableScan(
constraint = new Constraint(newDomain);
}

TableHandle newTable;
Optional<TablePartitioning> newTablePartitioning;
TupleDomain<ColumnHandle> remainingFilter;
boolean precalculateStatistics;
if (!plannerContext.getMetadata().usesLegacyTableLayouts(session, node.getTable())) {
// check if new domain is wider than domain already provided by table scan
if (constraint.predicate().isEmpty() && newDomain.contains(node.getEnforcedConstraint())) {
Expression resultingPredicate = createResultingPredicate(
plannerContext,
session,
symbolAllocator,
typeAnalyzer,
TRUE_LITERAL,
nonDeterministicPredicate,
decomposedPredicate.getRemainingExpression());

if (!TRUE_LITERAL.equals(resultingPredicate)) {
return Optional.of(new FilterNode(filterNode.getId(), node, resultingPredicate));
}

return Optional.of(node);
}
// check if new domain is wider than domain already provided by table scan
if (constraint.predicate().isEmpty() && newDomain.contains(node.getEnforcedConstraint())) {
Expression resultingPredicate = createResultingPredicate(
plannerContext,
session,
symbolAllocator,
typeAnalyzer,
TRUE_LITERAL,
nonDeterministicPredicate,
decomposedPredicate.getRemainingExpression());

if (newDomain.isNone()) {
// TODO: DomainTranslator.fromPredicate can infer that the expression is "false" in some cases (TupleDomain.none()).
// This should move to another rule that simplifies the filter using that logic and then rely on RemoveTrivialFilters
// to turn the subtree into a Values node
return Optional.of(new ValuesNode(node.getId(), node.getOutputSymbols(), ImmutableList.of()));
if (!TRUE_LITERAL.equals(resultingPredicate)) {
return Optional.of(new FilterNode(filterNode.getId(), node, resultingPredicate));
}

Optional<ConstraintApplicationResult<TableHandle>> result = plannerContext.getMetadata().applyFilter(session, node.getTable(), constraint);

if (result.isEmpty()) {
return Optional.empty();
}
return Optional.of(node);
}

newTable = result.get().getHandle();
if (newDomain.isNone()) {
// TODO: DomainTranslator.fromPredicate can infer that the expression is "false" in some cases (TupleDomain.none()).
// This should move to another rule that simplifies the filter using that logic and then rely on RemoveTrivialFilters
// to turn the subtree into a Values node
return Optional.of(new ValuesNode(node.getId(), node.getOutputSymbols(), ImmutableList.of()));
}

TableProperties newTableProperties = plannerContext.getMetadata().getTableProperties(session, newTable);
newTablePartitioning = newTableProperties.getTablePartitioning();
if (newTableProperties.getPredicate().isNone()) {
return Optional.of(new ValuesNode(node.getId(), node.getOutputSymbols(), ImmutableList.of()));
}
Optional<ConstraintApplicationResult<TableHandle>> result = plannerContext.getMetadata().applyFilter(session, node.getTable(), constraint);

remainingFilter = result.get().getRemainingFilter();
precalculateStatistics = result.get().isPrecalculateStatistics();
if (result.isEmpty()) {
return Optional.empty();
}
else {
Optional<TableLayoutResult> layout = plannerContext.getMetadata().getLayout(
session,
node.getTable(),
constraint,
Optional.of(node.getOutputSymbols().stream()
.map(node.getAssignments()::get)
.collect(toImmutableSet())));

if (layout.isEmpty() || layout.get().getTableProperties().getPredicate().isNone()) {
return Optional.of(new ValuesNode(node.getId(), node.getOutputSymbols(), ImmutableList.of()));
}

newTable = layout.get().getNewTableHandle();
newTablePartitioning = layout.get().getTableProperties().getTablePartitioning();
remainingFilter = layout.get().getUnenforcedConstraint();
precalculateStatistics = false;
TableHandle newTable = result.get().getHandle();

TableProperties newTableProperties = plannerContext.getMetadata().getTableProperties(session, newTable);
Optional<TablePartitioning> newTablePartitioning = newTableProperties.getTablePartitioning();
if (newTableProperties.getPredicate().isNone()) {
return Optional.of(new ValuesNode(node.getId(), node.getOutputSymbols(), ImmutableList.of()));
}

TupleDomain<ColumnHandle> remainingFilter = result.get().getRemainingFilter();
boolean precalculateStatistics = result.get().isPrecalculateStatistics();

verifyTablePartitioning(session, plannerContext.getMetadata(), node, newTablePartitioning);

TableScanNode tableScan = new TableScanNode(
Expand Down Expand Up @@ -337,24 +311,7 @@ static Expression createResultingPredicate(

public static TupleDomain<ColumnHandle> computeEnforced(TupleDomain<ColumnHandle> predicate, TupleDomain<ColumnHandle> unenforced)
{
if (predicate.isNone()) {
// If the engine requests that the connector provides a layout with a domain of "none". The connector can have two possible reactions, either:
// 1. The connector can provide an empty table layout.
// * There would be no unenforced predicate, i.e., unenforced predicate is TupleDomain.all().
// * The predicate was successfully enforced. Enforced predicate would be same as predicate: TupleDomain.none().
// 2. The connector can't/won't.
// * The connector would tell the engine to put a filter on top of the scan, i.e., unenforced predicate is TupleDomain.none().
// * The connector didn't successfully enforce anything. Therefore, enforced predicate would be TupleDomain.all().
if (unenforced.isNone()) {
return TupleDomain.all();
}
if (unenforced.isAll()) {
return TupleDomain.none();
}
throw new IllegalArgumentException();
}

// The engine requested the connector provides a layout with a non-none TupleDomain.
// The engine requested the connector to apply a filter with a non-none TupleDomain.
// A TupleDomain is effectively a list of column-Domain pairs.
// The connector is expected enforce the respective domain entirely on none, some, or all of the columns.
// 1. When the connector could enforce none of the domains, the unenforced would be equal to predicate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ public Optional<SystemTable> getSystemTable(Session session, QualifiedObjectName
throw new UnsupportedOperationException();
}

@Override
public Optional<TableLayoutResult> getLayout(Session session, TableHandle tableHandle, Constraint constraint, Optional<Set<ColumnHandle>> desiredColumns)
{
throw new UnsupportedOperationException();
}

@Override
public TableProperties getTableProperties(Session session, TableHandle handle)
{
Expand Down Expand Up @@ -548,12 +542,6 @@ public Optional<ResolvedIndex> resolveIndex(Session session, TableHandle tableHa
throw new UnsupportedOperationException();
}

@Override
public boolean usesLegacyTableLayouts(Session session, TableHandle table)
{
throw new UnsupportedOperationException();
}

@Override
public Optional<LimitApplicationResult<TableHandle>> applyLimit(Session session, TableHandle table, long limit)
{
Expand Down
Loading

0 comments on commit efc87b0

Please sign in to comment.