flyrain commented on code in PR #14954: URL: https://github.com/apache/iceberg/pull/14954#discussion_r2743893877
########## core/src/main/java/org/apache/iceberg/udf/UdfSpecResolver.java: ########## @@ -0,0 +1,535 @@ +/* + * 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.iceberg.udf; + +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.util.Iterator; +import java.util.List; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; + +/** Engine-agnostic resolver for Iceberg UDF spec JSON. */ +public final class UdfSpecResolver { + + private static final ObjectMapper MAPPER = new ObjectMapper(); + + private UdfSpecResolver() {} + + private static final String FUNCTION_UUID = "function-uuid"; + private static final String FORMAT_VERSION = "format-version"; + private static final String PARAMETER_NAMES = "parameter-names"; + private static final String DEFINITIONS = "definitions"; + private static final String DEFINITION_LOG = "definition-log"; + private static final String SECURE = "secure"; + private static final String DOC = "doc"; + private static final String LOCATION = "location"; + private static final String PROPERTIES = "properties"; + + private static final String DEFINITION_ID = "definition-id"; + private static final String PARAMETERS = "parameters"; + private static final String RETURN_TYPE = "return-type"; + private static final String FUNCTION_TYPE = "function-type"; + private static final String CURRENT_VERSION_ID = "current-version-id"; + private static final String VERSIONS = "versions"; + private static final String NULLABLE_RETURN = "nullable-return"; + + private static final String VERSION_ID = "version-id"; + private static final String TIMESTAMP_MS = "timestamp-ms"; + private static final String REPRESENTATIONS = "representations"; + private static final String DETERMINISTIC = "deterministic"; + private static final String ON_NULL_INPUT = "on-null-input"; + private static final String DEFINITION_VERSIONS = "definition-versions"; + + private static final String TYPE = "type"; + private static final String DEFAULT = "default"; + private static final String DIALECT = "dialect"; + private static final String BODY = "body"; + + private static final class ParameterName { + private final String name; + private final String doc; + + private ParameterName(String name, String doc) { + this.name = name; + this.doc = doc; + } + } + + /** + * Resolve all definitions' current versions for a dialect, returning one ResolvedSpec per + * definition (overload). + */ + @SuppressWarnings("checkstyle:CyclomaticComplexity") + public static List<ResolvedSpec> resolveAll(String udfMetadataJson, String dialect) { + try { + ObjectNode root = (ObjectNode) MAPPER.readTree(udfMetadataJson); + validateRoot(root); + + boolean secure = root.has(SECURE) && root.get(SECURE).asBoolean(false); + if (secure) { + // Engines must not expose secure function bodies via inspection; Stage 1 implementations + // do not support secure functions. + throw new IllegalArgumentException("Secure UDFs are not supported"); + } + + ArrayNode definitions = (ArrayNode) root.get(DEFINITIONS); + List<ParameterName> globalParameterNames = parseGlobalParameterNames(root); Review Comment: We have removed the globalParameterNames from the spec. -- 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]
