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

[Coral-Trino] Change NullCollation.LAST to NullCollation.HIGH in TrinoSqlDialect #450

Merged
merged 13 commits into from
Sep 12, 2023

Conversation

KevinGe00
Copy link
Contributor

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 since CoralRelToSqlNodeConverter use NullCollation.HIGH. This is an incremental piece that works towards the goal of eventually getting rid of TrinoSqlDialect and using CoralRelToSqlNodeConverter 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

@KevinGe00 KevinGe00 changed the title Drop null collation trino [Coral-Trino] Change NullCollation.LAST to NullCollation.HIGH in TrinoSqlDialect Sep 7, 2023
Comment on lines 28 to 42
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;
}
Copy link
Collaborator

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);.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

made the change! thanks

Comment on lines 26 to 27
return sqlCall.getOperator().kind == SqlKind.NULLS_LAST && sqlCall.operand(0).getKind() == SqlKind.DESCENDING
&& sqlCall.operandCount() > 0;
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, fixed

Copy link
Collaborator

@ljfgem ljfgem left a 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.

Copy link
Contributor

@aastha25 aastha25 left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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

@aastha25 aastha25 merged commit db56069 into linkedin:master Sep 12, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants