Skip to content
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

Add applyFilter equivalent to Constraint-based table layout selection #541

Merged
merged 3 commits into from Apr 1, 2019

Conversation

martint
Copy link
Member

@martint martint commented Mar 26, 2019

The ability to push down a Constraint (TupleDomain + opaque predicate evaluator) is the last piece needed to fully deprecate Table Layouts. The new applyFilter function introduces a specialized API that connectors can implement to obtain the same behavior without having to deal with Table Layouts, TableLayoutHandle, etc. It is meant as a transitional API until the fully-feature applyFilter with generalized predicates is implemented.

Copy link
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

Just skimmed. Generally it looks ok, I need to take another pass.

@@ -602,4 +602,23 @@ default ConnectorTableProperties getTableProperties(ConnectorSession session, Co
{
return Optional.empty();
}

/**
* Attempt to push down the provided constraint into the table. This method is provided as an alternative to
Copy link
Member

Choose a reason for hiding this comment

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

it is not alternative, but a replacement.

return Optional.of(new ValuesNode(idAllocator.getNextId(), node.getOutputSymbols(), ImmutableList.of()));
TableHandle newTable;
TupleDomain<ColumnHandle> remainingFilter;
if (metadata.usesLegacyTableLayouts(session, node.getTable())) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I would put legacy branch into the else branch.

* <p>
* <b>Note</b>: it's critical for connectors to return Optional.empty() if calling this method has no effect for that
* invocation, even if the connector generally supports pushdown. Doing otherwise can cause the optimizer
* to loop indefinitely.
Copy link
Member

Choose a reason for hiding this comment

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

We could also check if the were no change. For example:

  • checking if the remaining predicate is empty
  • seeing that remaining predicate is equal to constraint that we are trying to push down.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that is possible. The connector could be applying the constraint internally by updating its handle, but it may not be able to enforce the change completely. This means that there would be no external change visible, but big improvements should be happening internally.

@@ -265,7 +265,7 @@ public ConnectorTableLayout getTableLayout(ConnectorSession session, ConnectorTa
TpchTableLayoutHandle layout = (TpchTableLayoutHandle) handle;

// tables in this connector have a single layout
return getTableLayouts(session, layout.getTable(), Constraint.alwaysTrue(), Optional.empty())
return getTableLayouts(session, layout.getTable(), new Constraint<>(layout.getPredicate()), Optional.empty())
Copy link
Member

Choose a reason for hiding this comment

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

Commit message has a typo

* <p>
* <b>Note</b>: it's critical for connectors to return Optional.empty() if calling this method has no effect for that
* invocation, even if the connector generally supports pushdown. Doing otherwise can cause the optimizer
* to loop indefinitely.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that is possible. The connector could be applying the constraint internally by updating its handle, but it may not be able to enforce the change completely. This means that there would be no external change visible, but big improvements should be happening internally.

getLayout(LayoutHandle) was picking a new predicate and ignoring the
previously pushed-down predicate.
@martint martint force-pushed the pushdown-constraint branch 2 times, most recently from c7e6765 to 55824f4 Compare April 1, 2019 18:56
Current constraint is effectively a cache of the predicate that describes
the data the connector will produce. It is unnecessary, as the engine can
obtain it by calling getTableProperties and retrieving it directly.
The ability to push down a Constraint (TupleDomain + opaque predicate evaluator) is the last
piece needed to fully deprecate Table Layouts. The new applyFilter function introduces a
specialized API that connectors can implement to obtain the same behavior without having
to deal with Table Layouts, TableLayoutHandle, etc. It is meant as a transitional API
until the fully-feature applyFilter with generalized predicates is implemented.
@martint martint merged commit d79fbff into trinodb:master Apr 1, 2019
@martint martint mentioned this pull request Apr 1, 2019
6 tasks
@electrum electrum added this to the 307 milestone Apr 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

4 participants