InvisibleProgrammer commented on code in PR #6393:
URL: https://github.com/apache/hive/pull/6393#discussion_r3493687791
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java:
##########
@@ -279,4 +302,135 @@ private static Map<String, String>
filterIcebergTableProperties(Properties props
}
return map;
}
+
+ public static MaterializedView createMaterializedView(
+ Configuration conf, Properties props, String viewOriginalText,
String viewExpandedText,
+ CreationMetadata creationMetadata) {
+
+ boolean isExternalMaterializedView = "iceberg".equals(
+ HiveConf.getVar(conf,
HiveConf.ConfVars.HIVE_ICEBERG_MATERIALIZEDVIEW_METADATA_LOCATION));
+
+ Schema schema = schema(props);
+ PartitionSpec spec = spec(props, schema);
+ String location = props.getProperty(LOCATION);
+ String storageTableLocation = location +
+ (isExternalMaterializedView ?
MATERIALIZED_VIEW_STORAGE_TABLE_IDENTIFIER_SUFFIX : "");
+ String catalogName = props.getProperty(InputFormatConfig.CATALOG_NAME);
+
+ Optional<Catalog> catalog = loadCatalog(conf, catalogName);
+ SortOrder sortOrder = HMSTablePropertyHelper.getSortOrder(props, schema);
+ if (catalog.isEmpty()) {
+ throw new IllegalStateException("Unable to load catalog: " +
catalogName);
+ }
+ String name = props.getProperty(NAME);
+ Preconditions.checkNotNull(name, "Table identifier not set");
+
+ ViewCatalog viewCatalog = (ViewCatalog) catalog.get();
+
+ Map<String, String> map = filterIcebergTableProperties(props);
+ String storageTableIdentifier = name +
+ (isExternalMaterializedView ?
MATERIALIZED_VIEW_STORAGE_TABLE_IDENTIFIER_SUFFIX : "");
+ Table storageTable =
catalog.get().buildTable(TableIdentifier.parse(storageTableIdentifier), schema)
+
.withPartitionSpec(spec).withLocation(storageTableLocation).withProperties(map).withSortOrder(sortOrder)
+ .create();
+
+ Map<String, String> viewProperties = Maps.newHashMapWithExpectedSize(2);
+ viewProperties.put(MATERIALIZED_VIEW_PROPERTY_KEY, "true");
+ viewProperties.put(MATERIALIZED_VIEW_STORAGE_TABLE_PROPERTY_KEY,
storageTableIdentifier);
+ viewProperties.put(MATERIALIZED_VIEW_ORIGINAL_TEXT, viewOriginalText);
+
+ long createTime = System.currentTimeMillis();
+
+ List<SourceState> sourceStates = Lists.newArrayList();
+
+ for (var sourceTable : creationMetadata.getSourceTables()) {
+ SourceState.SourceStateType type =
sourceTable.getTable().getViewExpandedText() == null ?
+ SourceState.SourceStateType.TABLE :
+ SourceState.SourceStateType.VIEW;
+
+ String dbName = sourceTable.getTable().getDbName();
+ String sourceTableName = sourceTable.getTable().getTableName();
+ String sourceTableNamespace = "default";
+ String sourceTableCatalog = sourceTable.getTable().isSetCatName() ?
sourceTable.getTable().getCatName() : null;
+ Catalog tableCatalog = loadCatalog(conf,
sourceTableCatalog).orElse(catalog.get());
+ UUID uuid = null;
+ Snapshot snapshot = null;
+ ViewVersion version = null;
+
+ switch (type) {
+ case TABLE -> {
+ Table icebergTable =
tableCatalog.loadTable(TableIdentifier.parse(dbName + "." + sourceTableName));
Review Comment:
Sure.
--
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]