InvisibleProgrammer commented on code in PR #6393:
URL: https://github.com/apache/hive/pull/6393#discussion_r3493682913
##########
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 ?
Review Comment:
Modified the expression. Let me check the nested views.
--
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]