InvisibleProgrammer commented on code in PR #6449:
URL: https://github.com/apache/hive/pull/6449#discussion_r3373457483
##########
iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/MetastoreUtil.java:
##########
@@ -134,20 +141,101 @@ public static Table toHiveTable(org.apache.iceberg.Table
table, Configuration co
result.setDbName(tableName.getDb());
result.setTableName(tableName.getTable());
result.setTableType(TableType.EXTERNAL_TABLE.toString());
- result.setPartitionKeys(getPartitionKeys(table, table.spec().specId()));
+
+ // TODO: Revert after HIVE-29633 is fixed
+ // result.setPartitionKeys(getPartitionKeys(table, table.spec().specId()));
+ result.setPartitionKeys(Lists.newArrayList());
+
TableMetadata metadata = ((BaseTable) table).operations().current();
long maxHiveTablePropertySize =
conf.getLong(HiveOperationsBase.HIVE_TABLE_PROPERTY_MAX_SIZE,
HiveOperationsBase.HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT);
HMSTablePropertyHelper.updateHmsTableForIcebergTable(metadata.metadataFileLocation(),
result, metadata,
null, true, maxHiveTablePropertySize, null);
String catalogType = IcebergCatalogProperties.getCatalogType(conf);
if (!StringUtils.isEmpty(catalogType) &&
!IcebergCatalogProperties.NO_CATALOG_TYPE.equals(catalogType)) {
- result.getParameters().put(CatalogUtil.ICEBERG_CATALOG_TYPE,
IcebergCatalogProperties.getCatalogType(conf));
+ result.getParameters().put(CatalogUtil.ICEBERG_CATALOG_TYPE,
catalogType);
}
result.setSd(getHiveStorageDescriptor(table));
return result;
}
+ /**
+ * Builds a minimal HMS {@link Table} shell for a native Iceberg logical
view (identity, view type,
+ * and Iceberg storage-handler markers only). The storage handler {@code
postGetTable} hook enriches
+ * this object via {@link
IcebergLogicalViewSupport#enrichHmsTableFromIcebergView} (view SQL,
+ * schema, and Iceberg parameters).
+ */
+ public static Table buildMinimalHMSView(String catName, String dbName,
String tableName) {
+ Table result = new Table();
+ result.setCatName(catName);
+ result.setDbName(dbName);
+ result.setTableName(tableName);
+ result.setTableType(TableType.VIRTUAL_VIEW.toString());
+
+ Map<String, String> parameters = Maps.newHashMap();
+ parameters.put(
+ BaseMetastoreTableOperations.TABLE_TYPE_PROP,
HiveOperationsBase.ICEBERG_VIEW_TYPE_VALUE);
+ parameters.put(
+ hive_metastoreConstants.META_TABLE_STORAGE,
HMSTablePropertyHelper.HIVE_ICEBERG_STORAGE_HANDLER);
+ result.setParameters(parameters);
+ return result;
+ }
+
+ /**
+ * Applies Iceberg view metadata (SQL, schema, params) onto an existing HMS
{@link Table}.
+ */
+ public static void applyIcebergViewToHmsTable(Table hmsTable, View view,
Configuration conf) {
+ ViewMetadata metadata = ((BaseView) view).operations().current();
+ String sqlText = viewSqlText(view, metadata);
+
+ boolean hiveEngineEnabled = false;
+ hmsTable.setSd(HiveOperationsBase.storageDescriptor(metadata.schema(),
metadata.location(), hiveEngineEnabled));
+ StorageDescriptor sd = hmsTable.getSd();
+
+ if (sd.getBucketCols() == null) {
+ sd.setBucketCols(Lists.newArrayList());
+ }
+
+ if (sd.getSortCols() == null) {
+ sd.setSortCols(Lists.newArrayList());
+ }
+
+ long maxHiveTablePropertySize =
+ conf.getLong(
+ HiveOperationsBase.HIVE_TABLE_PROPERTY_MAX_SIZE,
+ HiveOperationsBase.HIVE_TABLE_PROPERTY_MAX_SIZE_DEFAULT);
+ HMSTablePropertyHelper.updateHmsTableForIcebergView(
+ metadata.metadataFileLocation(),
+ hmsTable,
+ metadata,
+ Collections.emptySet(),
+ maxHiveTablePropertySize,
+ null);
+
+ hmsTable.setCreateTime((int) (metadata.version(1).timestampMillis() /
1000));
Review Comment:
Are you sure it is a right decision hard-coding the version?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]