Skip to content

Commit

Permalink
Print column constraints based on layout predicate
Browse files Browse the repository at this point in the history
The layout predicate is the one that reflects the guarantees provided
by the TableScan node, not the "current constraint", which is just a
holder for temporary state during optimization.
  • Loading branch information
martint committed Apr 15, 2015
1 parent d46c657 commit 9dcdb7e
Showing 1 changed file with 11 additions and 6 deletions.
Expand Up @@ -16,6 +16,7 @@
import com.facebook.presto.metadata.Metadata; import com.facebook.presto.metadata.Metadata;
import com.facebook.presto.metadata.OperatorNotFoundException; import com.facebook.presto.metadata.OperatorNotFoundException;
import com.facebook.presto.metadata.TableHandle; import com.facebook.presto.metadata.TableHandle;
import com.facebook.presto.metadata.TableLayout;
import com.facebook.presto.spi.ColumnHandle; import com.facebook.presto.spi.ColumnHandle;
import com.facebook.presto.spi.ColumnMetadata; import com.facebook.presto.spi.ColumnMetadata;
import com.facebook.presto.spi.Domain; import com.facebook.presto.spi.Domain;
Expand Down Expand Up @@ -381,29 +382,33 @@ public Void visitTableScan(TableScanNode node, Integer indent)
TableHandle table = node.getTable(); TableHandle table = node.getTable();
print(indent, "- TableScan[%s, original constraint=%s] => [%s]", table, node.getOriginalConstraint(), formatOutputs(node.getOutputSymbols())); print(indent, "- TableScan[%s, original constraint=%s] => [%s]", table, node.getOriginalConstraint(), formatOutputs(node.getOutputSymbols()));


TupleDomain<ColumnHandle> constraint = node.getCurrentConstraint(); TupleDomain<ColumnHandle> predicate = node.getLayout()
if (constraint.isNone()) { .map(metadata::getLayout)
.map(TableLayout::getPredicate)
.orElse(TupleDomain.<ColumnHandle>all());

if (predicate.isNone()) {
print(indent + 2, ":: NONE"); print(indent + 2, ":: NONE");
} }
else { else {
// first, print output columns and their constraints // first, print output columns and their constraints
for (Map.Entry<Symbol, ColumnHandle> assignment : node.getAssignments().entrySet()) { for (Map.Entry<Symbol, ColumnHandle> assignment : node.getAssignments().entrySet()) {
ColumnHandle column = assignment.getValue(); ColumnHandle column = assignment.getValue();
print(indent + 2, "%s := %s", assignment.getKey(), column); print(indent + 2, "%s := %s", assignment.getKey(), column);
printConstraint(indent + 3, table, column, constraint); printConstraint(indent + 3, table, column, predicate);
} }


// then, print constraints for columns that are not in the output // then, print constraints for columns that are not in the output
if (!constraint.isAll()) { if (!predicate.isAll()) {
Set<ColumnHandle> outputs = ImmutableSet.copyOf(node.getAssignments().values()); Set<ColumnHandle> outputs = ImmutableSet.copyOf(node.getAssignments().values());


constraint.getDomains() predicate.getDomains()
.entrySet().stream() .entrySet().stream()
.filter(entry -> !outputs.contains(entry.getKey())) .filter(entry -> !outputs.contains(entry.getKey()))
.forEach(entry -> { .forEach(entry -> {
ColumnHandle column = entry.getKey(); ColumnHandle column = entry.getKey();
print(indent + 2, "%s", column); print(indent + 2, "%s", column);
printConstraint(indent + 3, table, column, constraint); printConstraint(indent + 3, table, column, predicate);
}); });
} }
} }
Expand Down

0 comments on commit 9dcdb7e

Please sign in to comment.