-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
Marking as draft as it's currently based on #7994. |
9b35035
to
8ac5c33
Compare
1fce2e0
to
a87cc77
Compare
plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/BaseJdbcConnectorTest.java
Outdated
Show resolved
Hide resolved
a87cc77
to
ba73ff4
Compare
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.
👍 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.
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/aggregation/RewriteLike.java
Outdated
Show resolved
Hide resolved
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 |
8d58630
to
be3bdf6
Compare
rebased on current #7994 state |
be3bdf6
to
d152b52
Compare
3b0322c
to
915aa8c
Compare
79c95e8
to
536e0bc
Compare
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/DefaultJdbcMetadata.java
Show resolved
Hide resolved
536e0bc
to
160a994
Compare
Rebased after #7994 merged, no other changes. |
...lugin-toolkit/src/main/java/io/trino/plugin/base/expression/ConnectorExpressionPatterns.java
Outdated
Show resolved
Hide resolved
160a994
to
31b7545
Compare
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/DefaultJdbcMetadata.java
Show resolved
Hide resolved
b209c42
to
7f14b64
Compare
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.
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.
covered by #11083 |
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.
(some notes)
@@ -126,17 126,18 @@ public ConnectorToSqlExpressionTranslator(Session session, PlannerContext planne | |||
if (call.getFunctionName().getCatalogSchema().isPresent()) { | |||
return Optional.empty(); | |||
} | |||
|
|||
// TODO Support ESCAPE character |
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.
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 |
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.
covered by #11083
plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/BaseJdbcConnectorTest.java
Show resolved
Hide resolved
@@ -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 |
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.
@@ -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()))); |
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.
static import here and in other places?
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.
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) |
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: appendConjunct?
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.
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( |
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.
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.
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.
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()) { |
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.
Maybe predicate.ifPresent(p -> stringJoiner.add("predicate=" p))
and other places too?
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.
good catch
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/expression/RewriteLike.java
Show resolved
Hide resolved
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.
7f14b64
to
13e52e8
Compare
kudu failure isn't a surprise to anyone, sadly |
Add support for complex function pushdown in JDBC connectors. This comes
with example implementation for LIKE pushdown in PostgreSQL.
Relates to #18