Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@
import com.google.common.collect.ImmutableMap;
import io.trino.metadata.TableHandle;
import io.trino.spi.connector.ColumnHandle;
import io.trino.spi.predicate.Domain;
import io.trino.spi.predicate.TupleDomain;
import io.trino.sql.planner.Symbol;

import javax.annotation.concurrent.Immutable;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

@Immutable
Expand Down Expand Up @@ -93,6 +98,26 @@ public TableScanNode(
checkArgument(assignments.keySet().containsAll(outputs), "assignments does not cover all of outputs");
this.enforcedConstraint = requireNonNull(enforcedConstraint, "enforcedConstraint is null");
this.forDelete = forDelete;

if (!enforcedConstraint.isAll() && !enforcedConstraint.isNone()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we move this to a checkNoDanglingColumns function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i prefer not to call functions within constructor (in general at least), so if there isn't a compelling reason to do so, would prefer to keep it here

Copy link
Copy Markdown
Contributor

@erichwang erichwang Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean to make it a static function. We call plenty of those here (like checkArg, checkState, etc). The reason is that (A) conveniently gives a name to the operation for documentation purposes (B) limits the scope of what this block of code is doing so that it doesn't have creep in the future.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, i can do this, if you feel strongly about it.
i'd prefer to keep as is, though

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea let's do it. I usually prefer that than having to leave more comments, which this would need without that function context)

Map<ColumnHandle, Domain> domains = enforcedConstraint.getDomains().orElseThrow();

Set<ColumnHandle> visibleColumns = outputs.stream()
.map(assignments::get)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also add a comment here that assignments can contain dangling columns (for now)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? Also, is it related to checkArgument(assignments.keySet().containsAll(outputs), "assignments does not cover all of outputs"); check above?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That check verifies that assignments contains outputs, but assignments can still have more symbols in it than what output produces. So in that sense assignments can have symbol to column handle mappings that are no longer referenced. But as I mentioned in a comment above, this is needed for some obscure reasons in the EffectivePredicateExtractor.

.map(Objects::requireNonNull)
.collect(toImmutableSet());

domains.keySet().stream()
.filter(column -> !visibleColumns.contains(column))
.findAny()
.ifPresent(column -> {
throw new IllegalArgumentException(format(
"enforcedConstraint references a column that is not part of the plan. " +
"enforcedConstraint keys: %s, visibleColumns: %s",
domains.keySet(),
visibleColumns));
});
}
}

@JsonProperty("table")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void testApplyTableScanRedirectionWithFilter()
createTableHandle(new MockConnectorTableHandle(SOURCE_TABLE, constraint, Optional.empty())),
ImmutableList.of(column),
ImmutableMap.of(column, SOURCE_COLUMN_HANDLE_B), // predicate on non-projected column
constraint);
TupleDomain.all());
})
.withSession(MOCK_SESSION)
.matches(
Expand Down