Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
+ '\''
+ '}';
}
}
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
+ '}';
}
}
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)
+ '}';
}
}
Loading
Loading