-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Improve IS NULL pushdown for ClickHouse complex expression #23459
Improve IS NULL pushdown for ClickHouse complex expression #23459
Conversation
7e00f41
to
4195edb
Compare
4195edb
to
c0d94e2
Compare
c0d94e2
to
6be9498
Compare
@Praveen2112 @hashhar @ebyhr please review. |
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
5982fe3
to
a8c8d0c
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.
Overall lgtm.
{ | ||
checkState(!testCases.isEmpty(), "No test cases"); | ||
for (int specialColumn = 0; specialColumn < SPECIAL_COLUMNS; specialColumn++) { | ||
checkArgument(!"NULL".equalsIgnoreCase(testCases.get(specialColumn).inputLiteral())); |
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.
What we are verifying here actually? It is verifying for only first test case that inputLiteral should not be null.
It seems that before adding the round trip test case, we should be knowing that 1st test case should not have NULL
as input literal.
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.
After going through the code, I got the intention of why we needed SPECIAL_COLUMNS
. May be NON_NULL_COLUMNS
makes more sense here. WDYT?
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 had TestClickHouseConnectorTest#testTextualPredicatePushdown
in mind, where SPECIAL_COLUMNS are
unsupported_1 Point,
unsupported_2 Point,
some_column String,
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.
What if we could handle this special columns as part of this framework ?
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 think it's possible however I'm not sure how to make it look better that it is right now, because the type of the special columns may differ for different cases:
.addTestCase("String", "'z'", VARCHAR, "CAST('z' AS varchar)") // special, non null column
.addTestCase("String", "'z'", VARBINARY, "CAST('z' AS varbinary)") // special, non null column
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...n/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/TestClickHouseConnectorTest.java
Outdated
Show resolved
Hide resolved
9d6bf97
to
48e2843
Compare
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
48e2843
to
6c17091
Compare
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
+ withConnectorExpression; | ||
|
||
// Closing QueryAssertions would close the QueryRunner | ||
QueryAssertions queryAssertions = new QueryAssertions(queryRunner); |
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.
Can we inject queryAssertions
instead of query runner ?
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.
It conforms to the api of SqlDataTypeTest
if we later want to unify these assertions.
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.
Also not sure if it gives benefits.
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
{ | ||
checkState(!testCases.isEmpty(), "No test cases"); | ||
for (int specialColumn = 0; specialColumn < SPECIAL_COLUMNS; specialColumn++) { | ||
checkArgument(!"NULL".equalsIgnoreCase(testCases.get(specialColumn).inputLiteral())); |
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.
What if we could handle this special columns as part of this framework ?
...in/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/IsNullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
6c17091
to
15d804f
Compare
@Praveen2112 please approve and merge. |
...n/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/TestClickHouseConnectorTest.java
Outdated
Show resolved
Hide resolved
try { | ||
assertPushdown(expectPushdown, | ||
assertResult(isNull ? Optional.of(firstCase.expectedLiteral()) : Optional.empty(), | ||
assertThat(queryAssertions.query(session, queryWithAll)))); | ||
} | ||
catch (AssertionError e) { | ||
// if failed - identify exact column which caused the failure | ||
for (int column = SPECIAL_COLUMNS; column < testCases.size(); column++) { | ||
String queryWithSingleColumnPredicate = "SELECT " + firstColumnName + " FROM " + temporaryRelation.getName() + " WHERE " + getPredicate(column, isNull) + withConnectorExpression; | ||
assertPushdown(expectPushdown, | ||
assertResult(isNull ? Optional.of(firstCase.expectedLiteral()) : Optional.empty(), | ||
assertThat(queryAssertions.query(session, queryWithSingleColumnPredicate)))); | ||
} | ||
throw new IllegalStateException("Single column assertion should fail for at least one column, if query of all column failed", e); | ||
} | ||
} | ||
|
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.
Instead of asserting them twice like once with all columns AND
? Can we assert them each column at a time ? Like
for (int column = SPECIAL_COLUMNS; column < testCases.size(); column++) {
String queryWithSingleColumnPredicate = "SELECT " + firstColumnName + " FROM " + temporaryRelation.getName() + " WHERE " + getPredicate(column, isNull) + withConnectorExpression;
assertPushdown(expectPushdown,
assertResult(isNull ? Optional.of(firstCase.expectedLiteral()) : Optional.empty(),
assertThat(queryAssertions.query(session, queryWithSingleColumnPredicate))));
}
This would allow us to identify the specific columns which would cause failure 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.
Not sure if I follow your suggestion. We already asserting each column at a time, in case of failure.
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.
Instead of handling twice can we try asserting only once for each column so that it would be easier to debug in case of failures
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.
The first check for all columns is N times faster than the second for single columns. So it's an improvement for sunny-day scenario.
In case of failure there is overhead of 1 additional check, performing N additional checks for single columns.
This was copied from SqlDataTypeTest.
Please let me know if you want to simplify code.
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.
Makes sense !! Let's have it like this.
private String getPredicate(int column, boolean isNull) | ||
{ | ||
checkArgument(column >= SPECIAL_COLUMNS, "Special columns should not be a part of a predicate, as they are helpers and do not participate in the assertions"); | ||
String columnName = "col_" + column; | ||
checkArgument("NULL".equalsIgnoreCase(testCases.get(column).inputLiteral())); | ||
return isNull | ||
? columnName + " IS NULL" | ||
: columnName + " IS NOT NULL"; | ||
} | ||
|
||
private static QueryAssert assertResult(Optional<String> value, QueryAssert assertion) | ||
{ | ||
return value.isPresent() | ||
? assertion.matches("VALUES %s".formatted(value.get())) | ||
: assertion.returnsEmptyResult(); | ||
} |
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.
If we could inline IS NULL
and IS NOT NULL
and the assertion could be inlined right ? Ideally for the test data - we for IS NULL
we get a value and for IS NOT NULL
we get an empty value - Do we need this dedicated method for each assertion.
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.
Not sure if I follow. I'm ok with any solution, just to merge this PR.
15d804f
to
2360265
Compare
@Praveen2112 do you think we are good to merge this PR? |
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.
LGTM
plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/NullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/NullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/NullPushdownDataTypeTest.java
Outdated
Show resolved
Hide resolved
2360265
to
2ed946e
Compare
@Praveen2112 ptal |
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.
Thanks for working on this
@ssheikin Can we update the PR description. |
b8c37ac
to
0a81434
Compare
0a81434
to
cd7ddc4
Compare
Description
Additional context and related issues
Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
() Release notes are required. Please propose a release note for me.
(x ) Release notes are required, with the following suggested text: