-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-29345: Support Alter table command for write ordering. #6256
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
base: master
Are you sure you want to change the base?
Conversation
22a148b to
9d5ffb3
Compare
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/BaseHiveIcebergMetaHook.java
Outdated
Show resolved
Hide resolved
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/BaseHiveIcebergMetaHook.java
Outdated
Show resolved
Hide resolved
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java
Outdated
Show resolved
Hide resolved
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/BaseHiveIcebergMetaHook.java
Outdated
Show resolved
Hide resolved
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java
Outdated
Show resolved
Hide resolved
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/BaseHiveIcebergMetaHook.java
Outdated
Show resolved
Hide resolved
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java
Outdated
Show resolved
Hide resolved
.../java/org/apache/hadoop/hive/ql/ddl/table/storage/order/AlterTableSetWriteOrderAnalyzer.java
Outdated
Show resolved
Hide resolved
.../java/org/apache/hadoop/hive/ql/ddl/table/storage/order/AlterTableSetWriteOrderAnalyzer.java
Outdated
Show resolved
Hide resolved
9d5ffb3 to
f35e6f3
Compare
f35e6f3 to
c020934
Compare
|
I have addressed all the comments and refactored the code as well. |
| for (SortFieldDesc fieldDesc : sortFieldDescList) { | ||
| NullOrder nullOrder = convertNullOrder(fieldDesc.getNullOrdering()); | ||
|
|
||
| if (fieldDesc.getDirection() == SortFieldDesc.SortDirection.ASC) { |
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.
how about
BiConsumer<String, SortOrder.NullOrder> sortMethod =
fieldDesc.getDirection() == SortFieldDesc.SortDirection.ASC
? replaceSortOrder::asc
: replaceSortOrder::desc;
sortMethod.accept(fieldDesc.getColumnName(), nullOrder);
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 considered the BiConsumer approach but I don’t see a clear benefit here since it introduces an extra level of indirection without reducing complexity. The logic is a simple ASC vs DESC decision and directly mutates replaceSortOrder, so an explicit if/else is more readable and easier to understand and debug.
If there is significant advantage to using BiConsumer in this context, it can be changed.
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.
@kokila-19, this way it removes duplicated call-site logic, similar to https://github.com/apache/hive/pull/6256/files#diff-e7a6dc1b51c479f2b51a7b66596d321c7c0d4a2a2ccea09a5ea65d4e5c6e0f61R64-R67.
I think it's more clear than use if else branching, but I'll leave it to you
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java
Outdated
Show resolved
Hide resolved
ql/src/java/org/apache/hadoop/hive/ql/ddl/misc/sortoder/SortOrderUtils.java
Outdated
Show resolved
Hide resolved
ql/src/java/org/apache/hadoop/hive/ql/ddl/misc/sortoder/SortOrderUtils.java
Outdated
Show resolved
Hide resolved
ql/src/java/org/apache/hadoop/hive/ql/ddl/misc/sortoder/SortOrderUtils.java
Outdated
Show resolved
Hide resolved
| LOG.warn("Can not create write order json. ", e); | ||
| return null; | ||
| } | ||
| return SortOrderUtils.parseSortOrderToJson(ast); |
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.
nice!
.../java/org/apache/hadoop/hive/ql/ddl/table/storage/order/AlterTableSetWriteOrderAnalyzer.java
Show resolved
Hide resolved
.../java/org/apache/hadoop/hive/ql/ddl/table/storage/order/AlterTableSetWriteOrderAnalyzer.java
Show resolved
Hide resolved
.../java/org/apache/hadoop/hive/ql/ddl/table/storage/order/AlterTableSetWriteOrderAnalyzer.java
Outdated
Show resolved
Hide resolved
deniskuzZ
left a comment
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, some minor things
SYNTAX: ALTER TABLE table_name SET WRITE ORDERED BY column_name sort_direction NULLS FIRST/LAST, ... EXAMPLE: ALTER TABLE table_order SET WRITE ORDERED BY id desc nulls first, name asc nulls last;
c020934 to
1acba18
Compare
|
deniskuzZ
left a comment
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.
+1



What changes were proposed in this pull request?
Implemented Natural ordering(write ordered by) ALTER TABLE DDL support for Iceberg tables.
Why are the changes needed?
Existing tables can be converted to natural ordered tables using ALTER command. Note that only the data inserted after alter query are ordered, not existing data.
Does this PR introduce any user-facing change?
yes, supported new syntax
SYNTAX:
ALTER TABLE table_name SET WRITE ORDERED BY column_name sort_direction NULLS FIRST/LAST, ...
EXAMPLE:
ALTER TABLE table_order SET WRITE ORDERED BY id desc nulls first, name asc nulls last;
How was this patch tested?
qtest