Copilot commented on code in PR #9560:
URL: https://github.com/apache/gravitino/pull/9560#discussion_r2667207559
##########
core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.java:
##########
@@ -117,21 +159,448 @@ public Function registerFunction(
FunctionColumn[] returnColumns,
FunctionDefinition[] definitions)
throws NoSuchSchemaException, FunctionAlreadyExistsException {
- // TODO: Implement when FunctionEntity is available
- throw new UnsupportedOperationException(
- "registerFunction for table-valued functions: FunctionEntity not yet
implemented");
+ return doRegisterFunction(
+ ident, comment, FunctionType.TABLE, deterministic, null,
returnColumns, definitions);
}
@Override
public Function alterFunction(NameIdentifier ident, FunctionChange...
changes)
throws NoSuchFunctionException, IllegalArgumentException {
- // TODO: Implement when FunctionEntity is available
- throw new UnsupportedOperationException("alterFunction: FunctionEntity not
yet implemented");
+ try {
+ return store.update(
+ ident,
+ FunctionEntity.class,
+ Entity.EntityType.FUNCTION,
+ oldEntity -> applyChanges(oldEntity, changes));
+
+ } catch (NoSuchEntityException e) {
+ throw new NoSuchFunctionException(e, "Function %s does not exist",
ident);
+ } catch (EntityAlreadyExistsException e) {
+ throw new IllegalArgumentException("Failed to alter function " + ident,
e);
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to alter function " + ident, e);
+ }
}
@Override
public boolean dropFunction(NameIdentifier ident) {
- // TODO: Implement when FunctionEntity is available
- throw new UnsupportedOperationException("dropFunction: FunctionEntity not
yet implemented");
+ try {
+ return store.delete(ident, Entity.EntityType.FUNCTION);
+ } catch (NoSuchEntityException e) {
+ return false;
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to drop function " + ident, e);
+ }
+ }
+
+ /**
+ * Converts a function identifier to a versioned identifier. The versioned
identifier uses the
+ * version number as the name to allow the store to retrieve specific
versions.
+ *
+ * @param ident The function identifier.
+ * @param version The version number, or {@link
FunctionEntity#LATEST_VERSION} for the latest.
+ * @return The versioned identifier.
+ */
+ private NameIdentifier toVersionedIdent(NameIdentifier ident, int version) {
+ return NameIdentifier.of(
+ ident.namespace().level(0),
+ ident.namespace().level(1),
+ ident.namespace().level(2),
+ ident.name(),
+ String.valueOf(version));
Review Comment:
The toVersionedIdent method hardcodes namespace level access (level(0),
level(1), level(2)), which assumes the namespace always has exactly 3 levels.
This is fragile and could cause ArrayIndexOutOfBoundsException if used with a
namespace that has fewer than 3 levels. Consider using namespace.levels() to
construct the versioned identifier more robustly, or add a precondition check
to validate the namespace length.
```suggestion
String[] namespaceLevels = ident.namespace().levels();
String[] versionedNamespaceLevels = Arrays.copyOf(namespaceLevels,
namespaceLevels.length + 1);
versionedNamespaceLevels[namespaceLevels.length] = ident.name();
return NameIdentifier.of(versionedNamespaceLevels,
String.valueOf(version));
```
##########
core/src/main/java/org/apache/gravitino/catalog/ManagedFunctionOperations.java:
##########
@@ -117,21 +159,448 @@ public Function registerFunction(
FunctionColumn[] returnColumns,
FunctionDefinition[] definitions)
throws NoSuchSchemaException, FunctionAlreadyExistsException {
- // TODO: Implement when FunctionEntity is available
- throw new UnsupportedOperationException(
- "registerFunction for table-valued functions: FunctionEntity not yet
implemented");
+ return doRegisterFunction(
+ ident, comment, FunctionType.TABLE, deterministic, null,
returnColumns, definitions);
}
@Override
public Function alterFunction(NameIdentifier ident, FunctionChange...
changes)
throws NoSuchFunctionException, IllegalArgumentException {
- // TODO: Implement when FunctionEntity is available
- throw new UnsupportedOperationException("alterFunction: FunctionEntity not
yet implemented");
+ try {
+ return store.update(
+ ident,
+ FunctionEntity.class,
+ Entity.EntityType.FUNCTION,
+ oldEntity -> applyChanges(oldEntity, changes));
+
+ } catch (NoSuchEntityException e) {
+ throw new NoSuchFunctionException(e, "Function %s does not exist",
ident);
+ } catch (EntityAlreadyExistsException e) {
+ throw new IllegalArgumentException("Failed to alter function " + ident,
e);
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to alter function " + ident, e);
+ }
}
@Override
public boolean dropFunction(NameIdentifier ident) {
- // TODO: Implement when FunctionEntity is available
- throw new UnsupportedOperationException("dropFunction: FunctionEntity not
yet implemented");
+ try {
+ return store.delete(ident, Entity.EntityType.FUNCTION);
+ } catch (NoSuchEntityException e) {
+ return false;
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to drop function " + ident, e);
+ }
+ }
+
+ /**
+ * Converts a function identifier to a versioned identifier. The versioned
identifier uses the
+ * version number as the name to allow the store to retrieve specific
versions.
+ *
+ * @param ident The function identifier.
+ * @param version The version number, or {@link
FunctionEntity#LATEST_VERSION} for the latest.
+ * @return The versioned identifier.
+ */
+ private NameIdentifier toVersionedIdent(NameIdentifier ident, int version) {
+ return NameIdentifier.of(
+ ident.namespace().level(0),
+ ident.namespace().level(1),
+ ident.namespace().level(2),
+ ident.name(),
+ String.valueOf(version));
+ }
+
+ private Function doRegisterFunction(
+ NameIdentifier ident,
+ String comment,
+ FunctionType functionType,
+ boolean deterministic,
+ Type returnType,
+ FunctionColumn[] returnColumns,
+ FunctionDefinition[] definitions)
+ throws NoSuchSchemaException, FunctionAlreadyExistsException {
+ Preconditions.checkArgument(
+ definitions != null && definitions.length > 0,
+ "At least one function definition must be provided");
+
+ // Validate definitions for arity overlap when there are multiple
definitions
+ if (definitions.length > 1) {
+ validateDefinitionsNoArityOverlap(definitions);
+ }
+
+ String currentUser = PrincipalUtils.getCurrentUserName();
+ Instant now = Instant.now();
+ AuditInfo auditInfo =
AuditInfo.builder().withCreator(currentUser).withCreateTime(now).build();
+
+ FunctionEntity functionEntity =
+ FunctionEntity.builder()
+ .withId(idGenerator.nextId())
+ .withName(ident.name())
+ .withNamespace(ident.namespace())
+ .withComment(comment)
+ .withFunctionType(functionType)
+ .withDeterministic(deterministic)
+ .withReturnType(returnType)
+ .withReturnColumns(returnColumns)
+ .withDefinitions(definitions)
+ .withVersion(INIT_VERSION)
+ .withAuditInfo(auditInfo)
+ .build();
+
+ try {
+ store.put(functionEntity, false /* overwrite */);
+ return functionEntity;
+
+ } catch (NoSuchEntityException e) {
+ throw new NoSuchSchemaException(e, "Schema %s does not exist",
ident.namespace());
+ } catch (EntityAlreadyExistsException e) {
+ throw new FunctionAlreadyExistsException(e, "Function %s already
exists", ident);
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to register function " + ident, e);
+ }
+ }
+
+ private FunctionEntity applyChanges(FunctionEntity oldEntity,
FunctionChange... changes) {
+ String newComment = oldEntity.comment();
+ List<FunctionDefinition> newDefinitions =
+ new ArrayList<>(Arrays.asList(oldEntity.definitions()));
+
+ for (FunctionChange change : changes) {
+ if (change instanceof FunctionChange.UpdateComment) {
+ newComment = ((FunctionChange.UpdateComment) change).newComment();
+
+ } else if (change instanceof FunctionChange.AddDefinition) {
+ FunctionDefinition defToAdd = ((FunctionChange.AddDefinition)
change).definition();
+ validateNoArityOverlap(newDefinitions, defToAdd);
+ newDefinitions.add(defToAdd);
+
+ } else if (change instanceof FunctionChange.RemoveDefinition) {
+ FunctionParam[] paramsToRemove = ((FunctionChange.RemoveDefinition)
change).parameters();
+ validateRemoveDefinition(newDefinitions, paramsToRemove);
+ newDefinitions.removeIf(def -> parametersMatch(def.parameters(),
paramsToRemove));
+
+ } else if (change instanceof FunctionChange.AddImpl) {
+ FunctionChange.AddImpl addImpl = (FunctionChange.AddImpl) change;
+ FunctionParam[] targetParams = addImpl.parameters();
+ FunctionImpl implToAdd = addImpl.implementation();
+ newDefinitions = addImplToDefinition(newDefinitions, targetParams,
implToAdd);
+
+ } else if (change instanceof FunctionChange.UpdateImpl) {
+ FunctionChange.UpdateImpl updateImpl = (FunctionChange.UpdateImpl)
change;
+ FunctionParam[] targetParams = updateImpl.parameters();
+ FunctionImpl.RuntimeType runtime = updateImpl.runtime();
+ FunctionImpl newImpl = updateImpl.implementation();
+ newDefinitions = updateImplInDefinition(newDefinitions, targetParams,
runtime, newImpl);
+
+ } else if (change instanceof FunctionChange.RemoveImpl) {
+ FunctionChange.RemoveImpl removeImpl = (FunctionChange.RemoveImpl)
change;
+ FunctionParam[] targetParams = removeImpl.parameters();
+ FunctionImpl.RuntimeType runtime = removeImpl.runtime();
+ newDefinitions = removeImplFromDefinition(newDefinitions,
targetParams, runtime);
+
+ } else {
+ throw new IllegalArgumentException("Unknown function change: " +
change);
+ }
+ }
+
+ String currentUser = PrincipalUtils.getCurrentUserName();
+ Instant now = Instant.now();
+ AuditInfo newAuditInfo =
+ AuditInfo.builder()
+ .withCreator(oldEntity.auditInfo().creator())
+ .withCreateTime(oldEntity.auditInfo().createTime())
+ .withLastModifier(currentUser)
+ .withLastModifiedTime(now)
+ .build();
+
+ return FunctionEntity.builder()
+ .withId(oldEntity.id())
+ .withName(oldEntity.name())
+ .withNamespace(oldEntity.namespace())
+ .withComment(newComment)
+ .withFunctionType(oldEntity.functionType())
+ .withDeterministic(oldEntity.deterministic())
+ .withReturnType(oldEntity.returnType())
+ .withReturnColumns(oldEntity.returnColumns())
+ .withDefinitions(newDefinitions.toArray(new FunctionDefinition[0]))
+ .withVersion(oldEntity.version() + 1)
+ .withAuditInfo(newAuditInfo)
+ .build();
+ }
+
+ /**
+ * Validates that all definitions in the array do not have overlapping
arities. This is used when
+ * registering a function with multiple definitions.
+ *
+ * <p>Gravitino enforces strict validation to prevent ambiguity. Operations
MUST fail if any
+ * definition's invocation arities overlap with another. For example, if an
existing definition
+ * {@code foo(int, float default 1.0)} supports arities {@code (int)} and
{@code (int, float)},
+ * adding a new definition {@code foo(int, string default 'x')} (which
supports {@code (int)} and
+ * {@code (int, string)}) will be REJECTED because both support the call
{@code foo(1)}. This
+ * ensures every function invocation deterministically maps to a single
definition.
+ *
+ * @param definitions The array of definitions to validate.
+ * @throws IllegalArgumentException If any two definitions have overlapping
arities.
+ */
+ private void validateDefinitionsNoArityOverlap(FunctionDefinition[]
definitions) {
+ for (int i = 0; i < definitions.length; i++) {
+ Set<String> aritiesI = computeArities(definitions[i]);
+ for (int j = i + 1; j < definitions.length; j++) {
+ Set<String> aritiesJ = computeArities(definitions[j]);
+ for (String arity : aritiesI) {
+ if (aritiesJ.contains(arity)) {
+ throw new IllegalArgumentException(
+ String.format(
+ "Cannot register function: definitions at index %d and %d
have overlapping "
+ + "arity '%s'. This would create ambiguous function
invocations.",
+ i, j, arity));
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Validates that a new definition does not create ambiguous function
arities with existing
+ * definitions. Each definition can support multiple arities based on
parameters with default
+ * values.
+ *
+ * <p>Gravitino enforces strict validation to prevent ambiguity. Operations
MUST fail if a new
+ * definition's invocation arities overlap with existing ones. For example,
if an existing
+ * definition {@code foo(int, float default 1.0)} supports arities {@code
(int)} and {@code (int,
+ * float)}, adding a new definition {@code foo(int, string default 'x')}
(which supports {@code
+ * (int)} and {@code (int, string)}) will be REJECTED because both support
the call {@code
+ * foo(1)}. This ensures every function invocation deterministically maps to
a single definition.
+ *
+ * @param existingDefinitions The current definitions.
+ * @param newDefinition The definition to add.
+ * @throws IllegalArgumentException If the new definition creates
overlapping arities.
+ */
+ private void validateNoArityOverlap(
+ List<FunctionDefinition> existingDefinitions, FunctionDefinition
newDefinition) {
+ Set<String> newArities = computeArities(newDefinition);
+
+ for (FunctionDefinition existing : existingDefinitions) {
+ Set<String> existingArities = computeArities(existing);
+ for (String arity : newArities) {
+ if (existingArities.contains(arity)) {
+ throw new IllegalArgumentException(
+ String.format(
+ "Cannot add definition: arity '%s' overlaps with an existing
definition. "
+ + "This would create ambiguous function invocations.",
+ arity));
+ }
+ }
+ }
+ }
+
+ /**
+ * Computes all possible invocation arities for a function definition. A
definition with N
+ * parameters where the last M have default values supports arities from
(N-M) to N parameters.
+ *
+ * <p>For example:
+ *
+ * <ul>
+ * <li>{@code foo(int a)} → arities: {@code ["int"]}
+ * <li>{@code foo(int a, float b)} → arities: {@code ["int,float"]}
+ * <li>{@code foo(int a, float b default 1.0)} → arities: {@code ["int",
"int,float"]}
+ * <li>{@code foo(int a, float b default 1.0, string c default 'x')} →
arities: {@code ["int",
+ * "int,float", "int,float,string"]}
+ * <li>{@code foo()} (no args) → arities: {@code [""]}
+ * </ul>
+ *
+ * @param definition The function definition.
+ * @return A set of arity signatures (e.g., "int", "int,float", "").
+ */
+ private Set<String> computeArities(FunctionDefinition definition) {
+ Set<String> arities = new HashSet<>();
+ FunctionParam[] params = definition.parameters();
+
+ // Find the first parameter with a default value
+ int firstDefaultIndex = params.length;
+ for (int i = 0; i < params.length; i++) {
+ if (params[i].defaultValue() != Column.DEFAULT_VALUE_NOT_SET) {
+ firstDefaultIndex = i;
+ break;
+ }
+ }
+
+ // Generate all possible arities from firstDefaultIndex to params.length
+ for (int i = firstDefaultIndex; i <= params.length; i++) {
+ StringBuilder arity = new StringBuilder();
+ for (int j = 0; j < i; j++) {
+ if (j > 0) {
+ arity.append(",");
+ }
+ arity.append(params[j].dataType().simpleString());
+ }
+ arities.add(arity.toString());
+ }
+
+ return arities;
+ }
Review Comment:
The computeArities method doesn't validate that parameters with default
values must appear at the end of the parameter list. If a parameter with a
default value is followed by a required parameter (e.g., `foo(int a default 1,
string b)`), the arity computation will be incorrect. The algorithm finds the
first default parameter and generates all arities from that point, but it
should validate that all parameters after the first default parameter also have
default values. This could lead to incorrect arity overlap detection.
##########
core/src/main/java/org/apache/gravitino/meta/FunctionEntity.java:
##########
@@ -0,0 +1,357 @@
+/*
+ * 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.meta;
+
+import com.google.common.collect.Maps;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+import lombok.ToString;
+import org.apache.gravitino.Auditable;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.Field;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.function.Function;
+import org.apache.gravitino.function.FunctionColumn;
+import org.apache.gravitino.function.FunctionDefinition;
+import org.apache.gravitino.function.FunctionType;
+import org.apache.gravitino.rel.types.Type;
+
+/**
+ * A class representing a function entity in the metadata store.
+ *
+ * <p>This entity stores both the function metadata and its version
information together, avoiding
+ * the need for separate FunctionEntity and FunctionVersionEntity. When
retrieving, if version is
+ * set to the special value {@link #LATEST_VERSION}, the store should return
the latest version.
+ */
+@ToString
+public class FunctionEntity implements Entity, Auditable, HasIdentifier,
Function {
+
+ /** Special version value indicating the latest version should be retrieved.
*/
+ public static final int LATEST_VERSION = -1;
+
+ public static final Field ID =
+ Field.required("id", Long.class, "The unique id of the function
entity.");
+ public static final Field NAME =
+ Field.required("name", String.class, "The name of the function entity.");
+ public static final Field COMMENT =
+ Field.optional("comment", String.class, "The comment or description of
the function entity.");
+ public static final Field FUNCTION_TYPE =
+ Field.required("function_type", FunctionType.class, "The type of the
function.");
+ public static final Field DETERMINISTIC =
+ Field.required("deterministic", Boolean.class, "Whether the function is
deterministic.");
+ public static final Field RETURN_TYPE =
+ Field.optional(
+ "return_type", Type.class, "The return type for scalar or aggregate
functions.");
+ public static final Field RETURN_COLUMNS =
+ Field.optional(
+ "return_columns",
+ FunctionColumn[].class,
+ "The output columns for table-valued functions.");
+ public static final Field DEFINITIONS =
+ Field.required("definitions", FunctionDefinition[].class, "The
definitions of the function.");
+ public static final Field VERSION =
+ Field.required("version", Integer.class, "The version of the function
entity.");
+ public static final Field AUDIT_INFO =
+ Field.required("audit_info", AuditInfo.class, "The audit details of the
function entity.");
+
+ private Long id;
+ private String name;
+ private Namespace namespace;
+ private String comment;
+ private FunctionType functionType;
+ private boolean deterministic;
+ private Type returnType;
+ private FunctionColumn[] returnColumns;
+ private FunctionDefinition[] definitions;
+ private Integer version;
+ private AuditInfo auditInfo;
+
+ private FunctionEntity() {}
+
+ @Override
+ public Map<Field, Object> fields() {
+ Map<Field, Object> fields = Maps.newHashMap();
+ fields.put(ID, id);
+ fields.put(NAME, name);
+ fields.put(COMMENT, comment);
+ fields.put(FUNCTION_TYPE, functionType);
+ fields.put(DETERMINISTIC, deterministic);
+ fields.put(RETURN_TYPE, returnType);
+ fields.put(RETURN_COLUMNS, returnColumns);
+ fields.put(DEFINITIONS, definitions);
+ fields.put(VERSION, version);
+ fields.put(AUDIT_INFO, auditInfo);
+
+ return Collections.unmodifiableMap(fields);
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public Long id() {
+ return id;
+ }
+
+ @Override
+ public Namespace namespace() {
+ return namespace;
+ }
+
+ @Override
+ public String comment() {
+ return comment;
+ }
+
+ @Override
+ public FunctionType functionType() {
+ return functionType;
+ }
+
+ @Override
+ public boolean deterministic() {
+ return deterministic;
+ }
+
+ @Override
+ public Type returnType() {
+ return returnType;
+ }
+
+ @Override
+ public FunctionColumn[] returnColumns() {
+ return returnColumns != null ? returnColumns : new FunctionColumn[0];
+ }
+
+ @Override
+ public FunctionDefinition[] definitions() {
+ return definitions;
+ }
+
+ @Override
+ public int version() {
+ return version;
+ }
+
+ @Override
+ public AuditInfo auditInfo() {
+ return auditInfo;
+ }
+
+ @Override
+ public EntityType type() {
+ return EntityType.FUNCTION;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
+ if (!(o instanceof FunctionEntity)) {
+ return false;
+ }
+
+ FunctionEntity that = (FunctionEntity) o;
+ return Objects.equals(id, that.id)
+ && Objects.equals(name, that.name)
+ && Objects.equals(namespace, that.namespace)
+ && Objects.equals(comment, that.comment)
+ && functionType == that.functionType
+ && deterministic == that.deterministic
+ && Objects.equals(returnType, that.returnType)
+ && Arrays.equals(returnColumns, that.returnColumns)
+ && Arrays.equals(definitions, that.definitions)
+ && Objects.equals(version, that.version)
+ && Objects.equals(auditInfo, that.auditInfo);
+ }
+
+ @Override
+ public int hashCode() {
+ int result =
+ Objects.hash(
+ id,
+ name,
+ namespace,
+ comment,
+ functionType,
+ deterministic,
+ returnType,
+ version,
+ auditInfo);
+ result = 31 * result + Arrays.hashCode(returnColumns);
+ result = 31 * result + Arrays.hashCode(definitions);
+ return result;
+ }
+
+ /**
+ * Creates a new builder for constructing a FunctionEntity.
+ *
+ * @return A new builder instance.
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /** Builder class for creating instances of {@link FunctionEntity}. */
+ public static class Builder {
+ private final FunctionEntity functionEntity;
+
+ private Builder() {
+ functionEntity = new FunctionEntity();
+ }
+
+ /**
+ * Sets the unique id of the function entity.
+ *
+ * @param id The unique id.
+ * @return This builder instance.
+ */
+ public Builder withId(Long id) {
+ functionEntity.id = id;
+ return this;
+ }
+
+ /**
+ * Sets the name of the function entity.
+ *
+ * @param name The name of the function.
+ * @return This builder instance.
+ */
+ public Builder withName(String name) {
+ functionEntity.name = name;
+ return this;
+ }
+
+ /**
+ * Sets the namespace of the function entity.
+ *
+ * @param namespace The namespace.
+ * @return This builder instance.
+ */
+ public Builder withNamespace(Namespace namespace) {
+ functionEntity.namespace = namespace;
+ return this;
+ }
+
+ /**
+ * Sets the comment of the function entity.
+ *
+ * @param comment The comment or description.
+ * @return This builder instance.
+ */
+ public Builder withComment(String comment) {
+ functionEntity.comment = comment;
+ return this;
+ }
+
+ /**
+ * Sets the function type.
+ *
+ * @param functionType The type of the function (SCALAR, AGGREGATE, or
TABLE).
+ * @return This builder instance.
+ */
+ public Builder withFunctionType(FunctionType functionType) {
+ functionEntity.functionType = functionType;
+ return this;
+ }
+
+ /**
+ * Sets whether the function is deterministic.
+ *
+ * @param deterministic True if the function is deterministic, false
otherwise.
+ * @return This builder instance.
+ */
+ public Builder withDeterministic(boolean deterministic) {
+ functionEntity.deterministic = deterministic;
+ return this;
+ }
+
+ /**
+ * Sets the return type for scalar or aggregate functions.
+ *
+ * @param returnType The return type.
+ * @return This builder instance.
+ */
+ public Builder withReturnType(Type returnType) {
+ functionEntity.returnType = returnType;
+ return this;
+ }
+
+ /**
+ * Sets the return columns for table-valued functions.
+ *
+ * @param returnColumns The output columns.
+ * @return This builder instance.
+ */
+ public Builder withReturnColumns(FunctionColumn[] returnColumns) {
+ functionEntity.returnColumns = returnColumns;
+ return this;
+ }
+
+ /**
+ * Sets the function definitions.
+ *
+ * @param definitions The definitions (overloads) of the function.
+ * @return This builder instance.
+ */
+ public Builder withDefinitions(FunctionDefinition[] definitions) {
+ functionEntity.definitions = definitions;
+ return this;
+ }
+
+ /**
+ * Sets the version of the function entity.
+ *
+ * @param version The version number.
+ * @return This builder instance.
+ */
+ public Builder withVersion(Integer version) {
+ functionEntity.version = version;
+ return this;
+ }
+
+ /**
+ * Sets the audit information.
+ *
+ * @param auditInfo The audit information.
+ * @return This builder instance.
+ */
+ public Builder withAuditInfo(AuditInfo auditInfo) {
+ functionEntity.auditInfo = auditInfo;
+ return this;
+ }
+
+ /**
+ * Builds the FunctionEntity instance.
+ *
+ * @return The constructed FunctionEntity.
+ */
+ public FunctionEntity build() {
+ functionEntity.validate();
Review Comment:
Missing custom validation for FunctionEntity. Similar entity classes like
FilesetEntity override the validate() method to enforce additional invariants.
FunctionEntity should validate that:
1. For TABLE functions, returnType should be null and returnColumns should
not be empty
2. For SCALAR and AGGREGATE functions, returnType should not be null and
returnColumns should be empty or null
3. definitions array should not be null or empty
This validation is currently implicit and not enforced at the entity level.
--
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]