-
Notifications
You must be signed in to change notification settings - Fork 3k
Hive: Convert the CREATE TABLE ... PARTITIONED BY to Iceberg identity partitions #1917
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,13 @@ | |
|
|
||
| package org.apache.iceberg.mr.hive; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Properties; | ||
| import java.util.Set; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hive.metastore.HiveMetaHook; | ||
| import org.apache.hadoop.hive.metastore.api.FieldSchema; | ||
| import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants; | ||
| import org.apache.iceberg.BaseMetastoreTableOperations; | ||
| import org.apache.iceberg.CatalogUtil; | ||
|
|
@@ -93,11 +96,16 @@ public void preCreateTable(org.apache.hadoop.hive.metastore.api.Table hmsTable) | |
| // If the table does not exist collect data for table creation | ||
| // - InputFormatConfig.TABLE_SCHEMA, InputFormatConfig.PARTITION_SPEC takes precedence so the user can override the | ||
| // Iceberg schema and specification generated by the code | ||
| // - Partitioned Hive tables are currently not allowed | ||
|
|
||
| Schema schema = schema(catalogProperties, hmsTable); | ||
| PartitionSpec spec = spec(schema, catalogProperties, hmsTable); | ||
|
|
||
| // If there are partition keys specified remove them from the HMS table and add them to the column list | ||
| if (hmsTable.isSetPartitionKeys()) { | ||
| hmsTable.getSd().getCols().addAll(hmsTable.getPartitionKeys()); | ||
| hmsTable.setPartitionKeysIsSet(false); | ||
| } | ||
|
|
||
| catalogProperties.put(InputFormatConfig.TABLE_SCHEMA, SchemaParser.toJson(schema)); | ||
| catalogProperties.put(InputFormatConfig.PARTITION_SPEC, PartitionSpecParser.toJson(spec)); | ||
|
|
||
|
|
@@ -197,20 +205,32 @@ private static Schema schema(Properties properties, org.apache.hadoop.hive.metas | |
| if (properties.getProperty(InputFormatConfig.TABLE_SCHEMA) != null) { | ||
| return SchemaParser.fromJson(properties.getProperty(InputFormatConfig.TABLE_SCHEMA)); | ||
| } else { | ||
| return HiveSchemaUtil.convert(hmsTable.getSd().getCols()); | ||
| if (hmsTable.isSetPartitionKeys() && !hmsTable.getPartitionKeys().isEmpty()) { | ||
pvary marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When would
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Theoretically it could be set to an empty list. Checked this way to keep on the safe side. |
||
| // Add partitioning columns to the original column list before creating the Iceberg Schema | ||
| List<FieldSchema> cols = new ArrayList<>(hmsTable.getSd().getCols()); | ||
pvary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cols.addAll(hmsTable.getPartitionKeys()); | ||
| return HiveSchemaUtil.convert(cols); | ||
| } else { | ||
| return HiveSchemaUtil.convert(hmsTable.getSd().getCols()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static PartitionSpec spec(Schema schema, Properties properties, | ||
| org.apache.hadoop.hive.metastore.api.Table hmsTable) { | ||
|
|
||
| Preconditions.checkArgument(hmsTable.getPartitionKeys() == null || hmsTable.getPartitionKeys().isEmpty(), | ||
| "Partitioned Hive tables are currently not supported"); | ||
|
|
||
| if (properties.getProperty(InputFormatConfig.PARTITION_SPEC) != null) { | ||
| Preconditions.checkArgument(!hmsTable.isSetPartitionKeys() || hmsTable.getPartitionKeys().isEmpty(), | ||
| "Provide only one of the following: Hive partition specification, or the " + | ||
| InputFormatConfig.PARTITION_SPEC + " property"); | ||
| return PartitionSpecParser.fromJson(schema, properties.getProperty(InputFormatConfig.PARTITION_SPEC)); | ||
| } else { | ||
| return PartitionSpec.unpartitioned(); | ||
| if (hmsTable.isSetPartitionKeys() && !hmsTable.getPartitionKeys().isEmpty()) { | ||
pvary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // If the table is partitioned then generate the identity partition definitions for the Iceberg table | ||
| return HiveSchemaUtil.spec(schema, hmsTable.getPartitionKeys()); | ||
| } else { | ||
| return PartitionSpec.unpartitioned(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
Why was this needed? Additional tasks because of partitioning?
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.
Yeah. The extra tasks eat more memory :(