-
Notifications
You must be signed in to change notification settings - Fork 714
[#9529] feat(server): Add server-side REST interface for UDFs (part-1) #9566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
33d1824
[#9561] feat(common): Add Function DTOs and REST API request/response…
mchades c1e12b3
address comments
mchades 95cb1d7
use @Builder
mchades c650262
use @Builder with style
mchades e0b41c8
remove full qualified class name
mchades File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
common/src/main/java/org/apache/gravitino/dto/function/FunctionColumnDTO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * 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.dto.function; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
| import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
| import javax.annotation.Nullable; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import org.apache.gravitino.function.FunctionColumn; | ||
| import org.apache.gravitino.json.JsonUtils; | ||
| import org.apache.gravitino.rel.types.Type; | ||
|
|
||
| /** DTO for function column. */ | ||
| @Getter | ||
| @EqualsAndHashCode | ||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
| @AllArgsConstructor | ||
| @Builder(setterPrefix = "with") | ||
| public class FunctionColumnDTO { | ||
|
|
||
| @JsonProperty("name") | ||
| private String name; | ||
|
|
||
| @JsonProperty("dataType") | ||
| @JsonSerialize(using = JsonUtils.TypeSerializer.class) | ||
| @JsonDeserialize(using = JsonUtils.TypeDeserializer.class) | ||
| private Type dataType; | ||
|
|
||
| @Nullable | ||
| @JsonProperty("comment") | ||
| private String comment; | ||
|
|
||
| /** | ||
| * Convert this DTO to a {@link FunctionColumn} instance. | ||
| * | ||
| * @return The function column. | ||
| */ | ||
| public FunctionColumn toFunctionColumn() { | ||
| return FunctionColumn.of(name, dataType, comment); | ||
| } | ||
|
|
||
| /** | ||
| * Create a {@link FunctionColumnDTO} from a {@link FunctionColumn} instance. | ||
| * | ||
| * @param column The function column. | ||
| * @return The function column DTO. | ||
| */ | ||
| public static FunctionColumnDTO fromFunctionColumn(FunctionColumn column) { | ||
| return new FunctionColumnDTO(column.name(), column.dataType(), column.comment()); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "FunctionColumnDTO{" | ||
| + "name='" | ||
| + name | ||
| + '\'' | ||
| + ", dataType=" | ||
| + dataType | ||
| + ", comment='" | ||
| + comment | ||
| + '\'' | ||
| + '}'; | ||
| } | ||
| } |
145 changes: 145 additions & 0 deletions
145
common/src/main/java/org/apache/gravitino/dto/function/FunctionDTO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /* | ||
| * 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.dto.function; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
| import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
| import java.util.Arrays; | ||
| import javax.annotation.Nullable; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.NoArgsConstructor; | ||
| import org.apache.gravitino.Audit; | ||
| import org.apache.gravitino.dto.AuditDTO; | ||
| 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.json.JsonUtils; | ||
| import org.apache.gravitino.rel.types.Type; | ||
|
|
||
| /** Represents a Function DTO (Data Transfer Object). */ | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder(setterPrefix = "with") | ||
| @EqualsAndHashCode | ||
| public class FunctionDTO implements Function { | ||
|
|
||
| @JsonProperty("name") | ||
| private String name; | ||
|
|
||
| @JsonProperty("functionType") | ||
| private FunctionType functionType; | ||
|
|
||
| @JsonProperty("deterministic") | ||
| private boolean deterministic; | ||
|
|
||
| @Nullable | ||
| @JsonProperty("comment") | ||
| private String comment; | ||
|
|
||
| @Nullable | ||
| @JsonProperty("returnType") | ||
| @JsonSerialize(using = JsonUtils.TypeSerializer.class) | ||
| @JsonDeserialize(using = JsonUtils.TypeDeserializer.class) | ||
| private Type returnType; | ||
|
|
||
| @JsonProperty("returnColumns") | ||
| private FunctionColumnDTO[] returnColumns; | ||
|
|
||
| @JsonProperty("definitions") | ||
| private FunctionDefinitionDTO[] definitions; | ||
|
|
||
| @JsonProperty("audit") | ||
| private AuditDTO audit; | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| public FunctionType functionType() { | ||
| return functionType; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean deterministic() { | ||
| return deterministic; | ||
| } | ||
|
|
||
| @Override | ||
| public String comment() { | ||
| return comment; | ||
| } | ||
|
|
||
| @Override | ||
| public Type returnType() { | ||
| return returnType; | ||
| } | ||
|
|
||
| @Override | ||
| public FunctionColumn[] returnColumns() { | ||
| if (returnColumns == null) { | ||
| return new FunctionColumn[0]; | ||
| } | ||
| return Arrays.stream(returnColumns) | ||
| .map(FunctionColumnDTO::toFunctionColumn) | ||
| .toArray(FunctionColumn[]::new); | ||
| } | ||
|
|
||
| @Override | ||
| public FunctionDefinition[] definitions() { | ||
| if (definitions == null) { | ||
| return new FunctionDefinition[0]; | ||
| } | ||
| return definitions; | ||
| } | ||
|
|
||
| @Override | ||
| public Audit auditInfo() { | ||
| return audit; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "FunctionDTO{" | ||
| + "name='" | ||
| + name | ||
| + '\'' | ||
| + ", functionType=" | ||
| + functionType | ||
| + ", deterministic=" | ||
| + deterministic | ||
| + ", comment='" | ||
| + comment | ||
| + '\'' | ||
| + ", returnType=" | ||
| + returnType | ||
| + ", returnColumns=" | ||
| + Arrays.toString(returnColumns) | ||
| + ", definitions=" | ||
| + Arrays.toString(definitions) | ||
| + ", audit=" | ||
| + audit | ||
| + '}'; | ||
| } | ||
| } |
120 changes: 120 additions & 0 deletions
120
common/src/main/java/org/apache/gravitino/dto/function/FunctionDefinitionDTO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * 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.dto.function; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import java.util.Arrays; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import org.apache.gravitino.function.FunctionDefinition; | ||
| import org.apache.gravitino.function.FunctionDefinitions; | ||
| import org.apache.gravitino.function.FunctionImpl; | ||
| import org.apache.gravitino.function.FunctionParam; | ||
|
|
||
| /** DTO for function definition. */ | ||
| @Getter | ||
| @EqualsAndHashCode | ||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
| @AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
| @Builder(setterPrefix = "with") | ||
| public class FunctionDefinitionDTO implements FunctionDefinition { | ||
|
|
||
| @JsonProperty("parameters") | ||
| private FunctionParamDTO[] parameters; | ||
|
|
||
| @JsonProperty("impls") | ||
| private FunctionImplDTO[] impls; | ||
|
|
||
| @Override | ||
| public FunctionParam[] parameters() { | ||
| if (parameters == null) { | ||
| return new FunctionParam[0]; | ||
| } | ||
| return parameters; | ||
| } | ||
|
|
||
| @Override | ||
| public FunctionImpl[] impls() { | ||
| if (impls == null) { | ||
| return new FunctionImpl[0]; | ||
| } | ||
| return Arrays.stream(impls).map(FunctionImplDTO::toFunctionImpl).toArray(FunctionImpl[]::new); | ||
| } | ||
|
|
||
| /** | ||
| * Convert this DTO to a {@link FunctionDefinition} instance. | ||
| * | ||
| * @return The function definition. | ||
| */ | ||
| public FunctionDefinition toFunctionDefinition() { | ||
| FunctionParam[] params = | ||
| parameters == null | ||
| ? new FunctionParam[0] | ||
| : Arrays.stream(parameters) | ||
| .map(FunctionParamDTO::toFunctionParam) | ||
| .toArray(FunctionParam[]::new); | ||
| FunctionImpl[] implArr = | ||
| impls == null | ||
| ? new FunctionImpl[0] | ||
| : Arrays.stream(impls) | ||
| .map(FunctionImplDTO::toFunctionImpl) | ||
| .toArray(FunctionImpl[]::new); | ||
| return FunctionDefinitions.of(params, implArr); | ||
| } | ||
|
|
||
| /** | ||
| * Create a {@link FunctionDefinitionDTO} from a {@link FunctionDefinition} instance. | ||
| * | ||
| * @param definition The function definition. | ||
| * @return The function definition DTO. | ||
| */ | ||
| public static FunctionDefinitionDTO fromFunctionDefinition(FunctionDefinition definition) { | ||
| FunctionParamDTO[] paramDTOs = | ||
| definition.parameters() == null | ||
| ? new FunctionParamDTO[0] | ||
| : Arrays.stream(definition.parameters()) | ||
| .map( | ||
| param -> | ||
| param instanceof FunctionParamDTO | ||
| ? (FunctionParamDTO) param | ||
| : FunctionParamDTO.fromFunctionParam(param)) | ||
| .toArray(FunctionParamDTO[]::new); | ||
| FunctionImplDTO[] implDTOs = | ||
| definition.impls() == null | ||
| ? new FunctionImplDTO[0] | ||
| : Arrays.stream(definition.impls()) | ||
| .map(FunctionImplDTO::fromFunctionImpl) | ||
| .toArray(FunctionImplDTO[]::new); | ||
| return new FunctionDefinitionDTO(paramDTOs, implDTOs); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "FunctionDefinitionDTO{" | ||
| + "parameters=" | ||
| + Arrays.toString(parameters) | ||
| + ", impls=" | ||
| + Arrays.toString(impls) | ||
| + '}'; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.