-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Validate no dangling columns in TableScanNode.enforcedConstraint #6963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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()) { | ||
| Map<ColumnHandle, Domain> domains = enforcedConstraint.getDomains().orElseThrow(); | ||
|
|
||
| Set<ColumnHandle> visibleColumns = outputs.stream() | ||
| .map(assignments::get) | ||
|
||
| .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") | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)