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

JDBC function predicate pushdown with PostgreSQL LIKE pushdown #11045

Merged
merged 4 commits into from
Mar 4, 2022

Conversation

findepi
Copy link
Member

@findepi findepi commented Feb 15, 2022

Add support for complex function pushdown in JDBC connectors. This comes
with example implementation for LIKE pushdown in PostgreSQL.

Relates to #18

@findepi
Copy link
Member Author

findepi commented Feb 15, 2022

Marking as draft as it's currently based on #7994.

@findepi findepi added enhancement New feature or request performance labels Feb 15, 2022
@findepi findepi force-pushed the findepi/sql-function-pushdown branch from 9b35035 to 8ac5c33 Compare February 15, 2022 15:45
@cla-bot cla-bot bot added the cla-signed label Feb 15, 2022
@findepi findepi force-pushed the findepi/sql-function-pushdown branch 2 times, most recently from 1fce2e0 to a87cc77 Compare February 15, 2022 16:12
@findepi findepi force-pushed the findepi/sql-function-pushdown branch from a87cc77 to ba73ff4 Compare February 16, 2022 07:59
Copy link

@slhmy slhmy left a comment

Choose a reason for hiding this comment

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

👍 This implementation of Predicate Pushdown looks good to me.

Currently I have no objection on these codes, only a few path problem I discovered.

I'll try projection pushdown based on this PR.
Specifically I want to try if I can deal with projection like unsupported_fn(supported_fn(a)) to make supported_fn(a) being pushed down.

If I meet any problem I'll reopen the review.

@findepi
Copy link
Member Author

findepi commented Feb 16, 2022

Specifically I want to try if I can deal with projection like unsupported_fn(supported_fn(a)) to make supported_fn(a) being pushed down.

we're pushing predicates so we operate on conjuncts level

i was thinking about reusing the machinery for projection pushdown as well (e.g. pushdown of substring), but this is a non-goal for now for me

@findepi findepi force-pushed the findepi/sql-function-pushdown branch from 8d58630 to be3bdf6 Compare February 17, 2022 11:59
@findepi
Copy link
Member Author

findepi commented Feb 17, 2022

rebased on current #7994 state

@findepi findepi force-pushed the findepi/sql-function-pushdown branch from be3bdf6 to d152b52 Compare February 17, 2022 12:13
@findepi findepi force-pushed the findepi/sql-function-pushdown branch 3 times, most recently from 3b0322c to 915aa8c Compare February 17, 2022 14:42
@findepi findepi mentioned this pull request Feb 17, 2022
@findepi findepi force-pushed the findepi/sql-function-pushdown branch 4 times, most recently from 79c95e8 to 536e0bc Compare February 18, 2022 08:59
@findepi findepi force-pushed the findepi/sql-function-pushdown branch from 536e0bc to 160a994 Compare March 2, 2022 09:55
@findepi
Copy link
Member Author

findepi commented Mar 2, 2022

Rebased after #7994 merged, no other changes.

@findepi findepi marked this pull request as ready for review March 2, 2022 09:55
@findepi findepi requested a review from hashhar March 2, 2022 09:55
@findepi findepi force-pushed the findepi/sql-function-pushdown branch from 160a994 to 31b7545 Compare March 2, 2022 10:35
@findepi findepi force-pushed the findepi/sql-function-pushdown branch 2 times, most recently from b209c42 to 7f14b64 Compare March 2, 2022 11:01
Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Some TODOs could use issues though since we'd want to actually resolve them - most important being lack of aggregation pushdown once expression pushdown is completed.

@findepi
Copy link
Member Author

findepi commented Mar 2, 2022

most important being lack of aggregation pushdown once expression pushdown is completed.

covered by #11083

Copy link
Member Author

@findepi findepi left a comment

Choose a reason for hiding this comment

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

(some notes)

@@ -126,17 126,18 @@ public ConnectorToSqlExpressionTranslator(Session session, PlannerContext planne
if (call.getFunctionName().getCatalogSchema().isPresent()) {
return Optional.empty();
}

// TODO Support ESCAPE character
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this included in #11117 @wendigo?

assertConditionallyPushedDown(
getSession(),
"SELECT regionkey, sum(nationkey) FROM nation WHERE name LIKE '%N%' GROUP BY regionkey",
false, // TODO: hasBehavior(SUPPORTS_PREDICATE_EXPRESSION_PUSHDOWN_WITH_LIKE), -- currently, applyAggregation is not invoked after applyFilter with expression
Copy link
Member Author

Choose a reason for hiding this comment

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

covered by #11083

@@ -544,7 544,7 @@ public ConnectorTableProperties getTableProperties(ConnectorSession session, Con
if (expression instanceof Call) {
Call call = (Call) expression;
// TODO Support ESCAPE character when it's pushed down by the engine
Copy link
Member Author

Choose a reason for hiding this comment

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

@assaf2 i think this was added in #7994. Did you create an issue for this?

@@ -275,7 276,7 @@ public SqlToConnectorExpressionTranslator(Session session, Map<NodeRef<Expressio
Optional<ConnectorExpression> value = process(node.getValue());
Optional<ConnectorExpression> pattern = process(node.getPattern());
if (value.isPresent() && pattern.isPresent()) {
return Optional.of(new Call(typeOf(node), new FunctionName(LIKE_PATTERN_FUNCTION_NAME), List.of(value.get(), pattern.get())));
return Optional.of(new Call(typeOf(node), StandardFunctions.LIKE_PATTERN_FUNCTION_NAME, List.of(value.get(), pattern.get())));
Copy link
Member

Choose a reason for hiding this comment

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

static import here and in other places?

Copy link
Member Author

Choose a reason for hiding this comment

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

in this class, SPI's StandardFunctions.LIKE_PATTERN_FUNCTION_NAME and (internal) LikeFunctions.LIKE_PATTERN_FUNCTION_NAME ar eused.

getAdditionalPredicate(table.getConstraintExpressions(), split.flatMap(JdbcSplit::getAdditionalPredicate))));
}

protected static Optional<String> getAdditionalPredicate(List<String> constraintExpressions, Optional<String> splitPredicate)
Copy link
Member

Choose a reason for hiding this comment

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

nit: appendConjunct?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, it doesn't append.

handle.getSortOrder(),
handle.getLimit(),
handle.getColumns(),
handle.getOtherReferencedTables(),
handle.getNextSyntheticColumnId());

return Optional.of(new ConstraintApplicationResult<>(handle, remainingFilter, false));
return Optional.of(
Copy link
Member

Choose a reason for hiding this comment

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

feels like exposing private ConstraintApplicationResult(T handle, TupleDomain<ColumnHandle> remainingFilter, Optional<ConnectorExpression> remainingExpression, boolean precalculateStatistics) as public would make this call a bit nicer to read.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not a big deal.
Also, the two constructors are supposed not to be used together in the long run. I.e. either connector supports expression pushdown (and uses new constructor) or does not (and uses the old one).
Having a kill switch in the connector (like here), complicates things, as connector's support becomes conditional.

I hope we will remove the switch some day.

StringJoiner stringJoiner = new StringJoiner(", ", Constraint.class.getSimpleName() "[", "]");
stringJoiner.add("summary=" summary);
stringJoiner.add("expression=" expression);
if (predicate.isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe predicate.ifPresent(p -> stringJoiner.add("predicate=" p)) and other places too?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch

@findepi
Copy link
Member Author

findepi commented Mar 3, 2022

CI #10772

Connectors should be able to refer to known constants for builtin
functions. This is especially true for function calls resulting from
desugaring, i.e. otherwise undocumented functions.
Add support for complex function pushdown in JDBC connectors. This comes
with example implementation for LIKE pushdown in PostgreSQL.
@findepi findepi force-pushed the findepi/sql-function-pushdown branch from 7f14b64 to 13e52e8 Compare March 3, 2022 15:35
@findepi
Copy link
Member Author

findepi commented Mar 4, 2022

ci / test (plugin/trino-kudu) (pull_request) Failing after 54m — test (plugin/trino-kudu)

kudu failure isn't a surprise to anyone, sadly

@findepi findepi merged commit a58bb8e into trinodb:master Mar 4, 2022
@findepi findepi deleted the findepi/sql-function-pushdown branch March 4, 2022 09:33
@github-actions github-actions bot added this to the 373 milestone Mar 4, 2022
This was referenced Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

6 participants