-
Notifications
You must be signed in to change notification settings - Fork 188
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
[Coral-Trino] Change NullCollation.LAST to NullCollation.HIGH in TrinoSqlDialect #450
[Coral-Trino] Change NullCollation.LAST to NullCollation.HIGH in TrinoSqlDialect #450
Conversation
protected boolean condition(SqlCall sqlCall) { | ||
return sqlCall.getOperator().kind == SqlKind.NULLS_LAST && sqlCall.operand(0).getKind() == SqlKind.DESCENDING; | ||
} | ||
|
||
@Override | ||
protected SqlCall transform(SqlCall sqlCall) { | ||
final List<SqlNode> sourceOperands = sqlCall.getOperandList(); | ||
String orderBy = sourceOperands.get(0).getKind().toString(); | ||
if (orderBy == "DESCENDING" && sqlCall.operandCount() > 0) { | ||
// drop redundant "NULLS LAST" | ||
return sqlCall.operand(0); | ||
} | ||
|
||
return sqlCall; | ||
} |
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.
We may change condition
to be return sqlCall.getOperator().kind == SqlKind.NULLS_LAST && sqlCall.operandCount() > 0 && sqlCall.operand(0).getKind() == SqlKind.DESCENDING
, then transform
can be modified to return sqlCall.operand(0);
.
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.
made the change! thanks
return sqlCall.getOperator().kind == SqlKind.NULLS_LAST && sqlCall.operand(0).getKind() == SqlKind.DESCENDING | ||
&& sqlCall.operandCount() > 0; |
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.
sqlCall.operandCount() > 0
should be put before sqlCall.operand(0).getKind() == SqlKind.DESCENDING
?
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, fixed
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, please merge if the regression test passed.
...o/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NullOrderingTransformer.java
Show resolved
Hide resolved
...o/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NullOrderingTransformer.java
Outdated
Show resolved
Hide resolved
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, thanks for working on the PR @KevinGe00.
Left minor comments for documentation.
|
||
RelNode relNode = TestUtils.getHiveToRelConverter() | ||
.convertSql("SELECT a, SUBSTR(b, 1, 1) AS aliased_column, c FROM test.tabler ORDER BY aliased_column ASC"); | ||
// We want NULLS FIRST since we're translating from Hive and that is the default null ordering for ASC in Hive |
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.
is this same as existing behaviour?
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.
Yes, current behavior is no explicit ASC
and with NULLS FIRST
since it needs to overwrite the default NULLS LAST
of trino
What changes are proposed in this pull request, and why are they necessary?
We're changing the null collation of
TrinoSqlDialect
to from NullCollation.LAST to NullCollation.HIGH sinceCoralRelToSqlNodeConverter
use NullCollation.HIGH. This is an incremental piece that works towards the goal of eventually getting rid ofTrinoSqlDialect
and usingCoralRelToSqlNodeConverter
as the common coral dialect.How was this patch tested?
New unit test:
testAliasOrderByASC
Testing that the translated Trino sql explicitly says NULLS FIRST since we're translating from Hive and that is the default null ordering for ASC in Hive
./gradlew clean build
waiting on i-tests