Copilot commented on code in PR #13200:
URL: https://github.com/apache/gravitino/pull/13200#discussion_r4022033321
##########
web-v2/web/src/app/catalogs/rightContent/entitiesContent/FunctionDetailsPage.js:
##########
@@ -100,10 +100,19 @@ const buildSignature = (name, definition) => {
)
}
+// Only SQL implementations with the TRINO runtime are exposed as Trino
language functions
+const isTrinoVisible = impl => impl?.language === 'SQL' && impl?.runtime ===
'TRINO'
Review Comment:
The connector also filters out non-`SCALAR` functions in
`GravitinoMetadata.toLanguageFunctions`, but this predicate only examines the
implementation. An `AGGREGATE` or `TABLE` function with SQL/TRINO
implementation will therefore be shown as “Eligible” even though the connector
returns no `LanguageFunction`; pass the parent function type into this check
and require `SCALAR` as well.
##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/util/TrinoRoutineSpecification.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.trino.connector.util;
+
+import io.trino.spi.TrinoException;
+import io.trino.spi.type.Type;
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.gravitino.function.Function;
+import org.apache.gravitino.function.FunctionDefinition;
+import org.apache.gravitino.trino.connector.GravitinoErrorCode;
+
+/**
+ * Builds the SQL routine specification Trino expects for a language function
from a Gravitino
+ * function definition and its stored SQL body:
+ *
+ * <pre>FUNCTION name(params) RETURNS type [NOT] DETERMINISTIC SECURITY
INVOKER body</pre>
+ *
+ * <p>The stored body is either a bare expression, which is wrapped in a
{@code RETURN} statement,
+ * or a control statement ({@code RETURN ...} / {@code BEGIN ... END}) that is
used as-is. The form
+ * is decided by the first token of the body; since {@code return}, {@code
begin} and {@code
+ * function} are also valid identifiers, a parameter with one of these names
shadows the keyword and
+ * the body is treated as an expression. {@code SECURITY INVOKER} is always
declared because the
+ * function has no owner identity for Trino's {@code SECURITY DEFINER} default.
+ *
+ * <p>Identifiers are always quoted. Trino resolves routine and parameter
names case-insensitively
+ * regardless of quoting, so this is equivalent to plain identifiers while
also covering reserved
+ * words and names with special characters.
+ */
+public final class TrinoRoutineSpecification {
+
+ private TrinoRoutineSpecification() {}
+
+ /**
+ * Builds the routine specification for one definition of a function.
+ *
+ * @param function the Gravitino function
+ * @param definition the definition whose parameters and return type
describe the routine
+ * @param sql the stored SQL body
+ * @param typeTransformer converts Gravitino types to Trino types
+ * @return the complete routine specification
+ * @throws TrinoException if the definition or body is not supported or a
type cannot be mapped
+ */
+ public static String build(
+ Function function,
+ FunctionDefinition definition,
+ String sql,
+ GeneralDataTypeTransformer typeTransformer) {
+ if (definition.returnType() == null) {
+ throw new TrinoException(
+ GravitinoErrorCode.GRAVITINO_ILLEGAL_ARGUMENT,
+ "Function " + function.name() + " has a definition without a return
type");
+ }
+ Set<String> parameterNames =
+ Arrays.stream(definition.parameters())
+ .map(param -> param.name().toLowerCase(Locale.ENGLISH))
+ .collect(Collectors.toSet());
+ String body = stripLeadingComments(sql);
Review Comment:
When an SQL implementation contains only comments (which `SQLImpl` accepts
as non-blank), `stripLeadingComments` returns an empty string. The builder then
emits a `RETURN ` routine and returns an invalid `LanguageFunction` instead of
letting `GravitinoMetadata` skip the unsupported body. Reject an empty body
after stripping comments so this path is handled like the other invalid bodies.
--
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]