deniskuzZ commented on code in PR #5995: URL: https://github.com/apache/hive/pull/5995#discussion_r2294049335
########## iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/MetastoreUtil.java: ########## @@ -104,38 +109,56 @@ public static void alterTable( } } - public static Table convertIcebergTableToHiveTable(org.apache.iceberg.Table icebergTable, Configuration conf) { - Table hiveTable = new Table(); - TableMetadata metadata = ((BaseTable) icebergTable).operations().current(); + public static List<FieldSchema> getPartitionKeys(org.apache.iceberg.Table table, int specId) { + Schema schema = table.specs().get(specId).schema(); + List<FieldSchema> hiveSchema = HiveSchemaUtil.convert(schema); + Map<String, String> colNameToColType = hiveSchema.stream() + .collect(Collectors.toMap(FieldSchema::getName, FieldSchema::getType)); + return table.specs().get(specId).fields().stream() + .map(partField -> new FieldSchema( + schema.findColumnName(partField.sourceId()), + colNameToColType.get(schema.findColumnName(partField.sourceId())), + String.format("Transform: %s", partField.transform().toString())) + ) + .toList(); + } + + public static Table toHiveTable(org.apache.iceberg.Table table, Configuration conf) { + var result = new Table(); + TableName tableName = TableName.fromString(table.name(), MetaStoreUtils.getDefaultCatalog(conf), + Warehouse.DEFAULT_DATABASE_NAME); + result.setCatName(tableName.getCat()); + result.setDbName(tableName.getDb()); + result.setTableName(tableName.getTable()); + result.setTableType(TableType.EXTERNAL_TABLE.toString()); + result.setPartitionKeys(getPartitionKeys(table, table.spec().specId())); + 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(), hiveTable, metadata, + HMSTablePropertyHelper.updateHmsTableForIcebergTable(metadata.metadataFileLocation(), result, metadata, null, true, maxHiveTablePropertySize, null); - hiveTable.getParameters().put(CatalogUtils.ICEBERG_CATALOG_TYPE, CatalogUtil.ICEBERG_CATALOG_TYPE_REST); - TableName tableName = TableName.fromString(icebergTable.name(), null, null); - hiveTable.setTableName(tableName.getTable()); - hiveTable.setDbName(tableName.getDb()); - StorageDescriptor storageDescriptor = new StorageDescriptor(); - hiveTable.setSd(storageDescriptor); - hiveTable.setTableType("EXTERNAL_TABLE"); - hiveTable.setPartitionKeys(new LinkedList<>()); - List<FieldSchema> cols = new LinkedList<>(); - storageDescriptor.setCols(cols); - storageDescriptor.setLocation(icebergTable.location()); - storageDescriptor.setInputFormat(DEFAULT_INPUT_FORMAT_CLASS); - storageDescriptor.setOutputFormat(DEFAULT_OUTPUT_FORMAT_CLASS); - storageDescriptor.setBucketCols(new LinkedList<>()); - storageDescriptor.setSortCols(new LinkedList<>()); - storageDescriptor.setParameters(Maps.newHashMap()); - SerDeInfo serDeInfo = new SerDeInfo("icebergSerde", DEFAULT_SERDE_CLASS, Maps.newHashMap()); - serDeInfo.getParameters().put(serdeConstants.SERIALIZATION_FORMAT, "1"); // Default serialization format. - storageDescriptor.setSerdeInfo(serDeInfo); - icebergTable.schema().columns().forEach(icebergColumn -> { - FieldSchema fieldSchema = new FieldSchema(); - fieldSchema.setName(icebergColumn.name()); - fieldSchema.setType(icebergColumn.type().toString()); - cols.add(fieldSchema); - }); - return hiveTable; + result.getParameters().put(CatalogUtil.ICEBERG_CATALOG_TYPE, conf.get(CatalogUtils.CATALOG_CONFIG_TYPE)); + result.setSd(toHiveStorageDescriptor(table)); + return result; + } + + private static StorageDescriptor toHiveStorageDescriptor(org.apache.iceberg.Table table) { Review Comment: getHiveStorageDescriptor() -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org