mchades commented on code in PR #12294:
URL: https://github.com/apache/gravitino/pull/12294#discussion_r3710561344
##########
catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveViewCatalogOperations.java:
##########
@@ -457,27 +597,62 @@ private SQLRepresentation validateSQLRepresentation(
HiveView.SPARK_VERSION_KEY);
return selected;
default:
- // TODO(design-docs/gravitino-logical-view-management.md): support
creating trino HMS views.
throw new UnsupportedOperationException(
String.format(
- "Hive catalog currently supports only '%s', '%s' and '%s' view
dialects, but got '%s' for view %s",
- Dialects.HIVE, Dialects.FLINK, Dialects.SPARK,
selected.dialect(), ident));
+ "Hive catalog currently supports only [%s] view dialects, but
got '%s' for view %s",
+ SUPPORTED_VIEW_DIALECTS, selected.dialect(), ident));
+ }
+ }
+
+ /**
+ * Sets or clears the {@code presto_view} marker in the given HMS property
map, so that a Trino
+ * dialect view is recognized as a native Trino view (see {@link
TrinoNativeViewCodec}).
+ */
+ private static void applyTrinoViewMarker(Map<String, String> params, String
dialect) {
Review Comment:
Is it necessary to use static?
##########
catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveViewCatalogOperations.java:
##########
@@ -116,18 +122,25 @@ public View createView(
Map<String, String> safeProperties = properties == null ?
ImmutableMap.of() : properties;
SQLRepresentation sqlRepresentation =
validateSQLRepresentation(
- representations, defaultCatalog, defaultSchema, safeProperties,
ident);
+ representations, defaultCatalog, defaultSchema, safeProperties,
columns, ident);
try {
Map<String, String> params = Maps.newHashMap(safeProperties);
params.put(TABLE_TYPE, TableType.VIRTUAL_VIEW.name());
- String viewOriginalText = toHmsViewOriginalText(sqlRepresentation,
ident);
+ applyTrinoViewMarker(params, sqlRepresentation.dialect());
Review Comment:
Could we align on the ownership contract for Trino-dialect views? The caller
should provide the logical SQL, output columns, user comment, default
catalog/schema, and ordinary user properties, while Gravitino should derive the
native HMS representation: `presto_view=true`, the HMS comment `Presto View`, a
dummy HMS column, and the encoded `viewOriginalText`.
If this is the intended contract, could we centralize that conversion for
both create and replace, and register `presto_view` in
`HiveTablePropertiesMetadata` as a reserved property? This would prevent
callers from setting or removing the storage marker while allowing the
connector to manage it from the final dialect.
##########
catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/TrinoNativeViewCodec.java:
##########
@@ -0,0 +1,435 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.catalog.hive;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.List;
+import java.util.Locale;
+import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+import org.apache.gravitino.rel.types.Type;
+import org.apache.gravitino.rel.types.Types;
+
+/**
+ * Encodes and decodes Trino/Presto's native "Presto View" HMS view format, so
that views created by
+ * Gravitino's Trino dialect are readable by a native Trino Hive connector
(and vice versa).
+ *
+ * <p>Trino recognizes a Hive Metastore VIRTUAL_VIEW table as a Trino view
when it carries the
+ * {@code presto_view=true} table parameter and its {@code comment} table
parameter equals {@code
+ * "Presto View"}; the view body is stored in {@code viewOriginalText} as
{@code "/* Presto View: "
+ * + base64(json) + " * /"}. The JSON payload mirrors Trino's {@code
ConnectorViewDefinition} wire
Review Comment:
Was this codec adapted from Trino source? If so, please add the
corresponding attribution for this file under `Trino` in the root `LICENSE`.
##########
catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveViewCatalogOperations.java:
##########
@@ -116,18 +122,25 @@ public View createView(
Map<String, String> safeProperties = properties == null ?
ImmutableMap.of() : properties;
SQLRepresentation sqlRepresentation =
validateSQLRepresentation(
- representations, defaultCatalog, defaultSchema, safeProperties,
ident);
+ representations, defaultCatalog, defaultSchema, safeProperties,
columns, ident);
try {
Map<String, String> params = Maps.newHashMap(safeProperties);
params.put(TABLE_TYPE, TableType.VIRTUAL_VIEW.name());
- String viewOriginalText = toHmsViewOriginalText(sqlRepresentation,
ident);
+ applyTrinoViewMarker(params, sqlRepresentation.dialect());
+ String viewOriginalText =
+ toHmsViewOriginalText(
+ sqlRepresentation, columns, comment, defaultCatalog,
defaultSchema, ident);
+ String hmsComment =
+ Dialects.TRINO.equalsIgnoreCase(sqlRepresentation.dialect())
+ ? TrinoNativeViewCodec.PRESTO_VIEW_COMMENT
Review Comment:
Could we add a create/load round-trip test with a non-null comment to verify
that the original comment is preserved in the encoded payload?
--
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]