difin commented on code in PR #6449:
URL: https://github.com/apache/hive/pull/6449#discussion_r3230118838


##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/view/create/CreateViewAnalyzer.java:
##########
@@ -191,6 +200,58 @@ private List<FieldSchema> getPartitionColumns(List<String> 
partitionColumnNames)
     return partitionColumnsCopy;
   }
 
+  /**
+   * Returns the FQCN of the storage handler that should own native-catalog 
view metadata, or {@code null} for a
+   * classic HMS virtual view. If {@code TBLPROPERTIES} contains {@code 
view-format}, its value is resolved the same
+   * way as a {@code STORED BY} handler identifier (short name or FQCN) and 
used when it
+   * {@link HiveStorageHandler#supportsNativeViewCatalog()}. Otherwise, when 
{@code view-format} is absent,
+   * {@link HiveConf.ConfVars#HIVE_DEFAULT_STORAGE_HANDLER} is used if set and 
the handler supports native views.
+   */
+  private String resolveNativeViewStorageHandlerClass(Map<String, String> 
properties) throws SemanticException {
+    String fromViewFormat = findViewFormatHandlerClass(properties);
+    String fromDefaultConfig =
+        StringUtils.trimToNull(HiveConf.getVar(conf, 
HiveConf.ConfVars.HIVE_DEFAULT_STORAGE_HANDLER));
+    String handlerClass = fromViewFormat != null ? fromViewFormat : 
fromDefaultConfig;
+    if (StringUtils.isBlank(handlerClass)) {
+      return null;
+    }
+    return resolveNativeHandlerClass(handlerClass, fromViewFormat != null);
+  }
+
+  private static String findViewFormatHandlerClass(Map<String, String> 
properties) throws SemanticException {
+    if (properties == null) {
+      return null;
+    }
+    for (Map.Entry<String, String> e : properties.entrySet()) {
+      if (e.getKey() != null
+          && VIEW_FORMAT_TABLE_PROPERTY.equalsIgnoreCase(e.getKey())
+          && StringUtils.isNotBlank(e.getValue())) {
+        return 
StorageFormat.resolveStorageHandlerClassNameForView(e.getValue().trim());
+      }
+    }
+    return null;
+  }
+
+  private String resolveNativeHandlerClass(String handlerClass, boolean 
explicitViewFormat)
+      throws SemanticException {
+    try {
+      HiveStorageHandler handler = HiveUtils.getStorageHandler(conf, 
handlerClass);
+      if (handler != null && handler.supportsNativeViewCatalog()) {
+        return handlerClass;
+      }
+    } catch (HiveException e) {
+      if (explicitViewFormat) {
+        throw new 
SemanticException(ErrorMsg.VIEW_STORAGE_HANDLER_UNSUPPORTED.getMsg(e.getMessage()),
 e);
+      }
+      return null;
+    }
+    if (explicitViewFormat) {
+      throw new 
SemanticException(ErrorMsg.VIEW_STORAGE_HANDLER_UNSUPPORTED.getMsg(
+          "Native view metadata is not supported for storage handler: " + 
handlerClass));
+    }

Review Comment:
   Done, moved to the caller.



-- 
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]

Reply via email to