InvisibleProgrammer commented on code in PR #6449:
URL: https://github.com/apache/hive/pull/6449#discussion_r3347549936
##########
iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/MetastoreUtil.java:
##########
@@ -134,20 +139,102 @@ 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 Hive metastore {@link Table} representation for an Iceberg
{@link View}, for clients
+ * (e.g. {@code HiveRESTCatalogClient}) that bridge Iceberg catalog metadata
into the HMS API.
+ */
+ public static Table toHiveView(View view, Configuration conf) {
+ Table result = new Table();
+ TableName tableName =
+ TableName.fromString(
+ view.name(), MetaStoreUtils.getDefaultCatalog(conf),
Warehouse.DEFAULT_DATABASE_NAME);
+ result.setCatName(tableName.getCat());
+ result.setDbName(tableName.getDb());
+ result.setTableName(tableName.getTable());
+ result.setTableType(TableType.VIRTUAL_VIEW.toString());
+
+ long nowMillis = System.currentTimeMillis();
+ int nowSec = (int) (nowMillis / 1000);
+ ViewMetadata metadata = ((BaseView) view).operations().current();
+ String owner =
+ PropertyUtil.propertyAsString(
+ metadata.properties(), HiveCatalog.HMS_TABLE_OWNER,
System.getProperty("user.name"));
+ result.setOwner(owner);
+ result.setCreateTime(nowSec);
+ result.setLastAccessTime(nowSec);
+ result.setRetention(Integer.MAX_VALUE);
+
+ applyIcebergViewToHmsTable(result, view, conf);
+ 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);
+
+ // In-memory overlay for compile/describe: authoritative SQL comes from
Iceberg metadata.
+ hmsTable.setViewOriginalText(sqlText);
Review Comment:
Can it cause any trouble on Hive side of the original text is actually the
expanded text?
--
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]