Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions fe/fe-catalog/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ under the License.
<artifactId>fe-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>fe-type</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

package org.apache.doris.catalog;

import org.apache.doris.common.util.URI;
import org.apache.doris.thrift.TFunctionBinaryType;
import org.apache.doris.common.URI;

import com.google.gson.annotations.SerializedName;

Expand Down Expand Up @@ -77,7 +76,7 @@ public AggregateFunction(FunctionName fnName, List<Type> argTypes,
URI location, String updateFnSymbol, String initFnSymbol,
String serializeFnSymbol, String mergeFnSymbol, String getValueFnSymbol,
String removeFnSymbol, String finalizeFnSymbol, boolean ignoresDistinct,
boolean isAnalyticFn, boolean returnsNonNullOnEmpty, TFunctionBinaryType binaryType,
boolean isAnalyticFn, Function.BinaryType binaryType,
boolean userVisible, boolean vectorized, NullableMode nullableMode) {
// only `count` is always not nullable, other aggregate function is always nullable
super(0, fnName, argTypes, retType, hasVarArgs, binaryType, userVisible, vectorized, nullableMode);
Expand All @@ -99,8 +98,17 @@ public AggregateFunction(AggregateFunction other) {
if (other == null) {
return;
}
isAnalyticFn = other.isAnalyticFn;
isAggregateFn = other.isAggregateFn;
this.isAnalyticFn = other.isAnalyticFn;
this.isAggregateFn = other.isAggregateFn;
this.updateFnSymbol = other.updateFnSymbol;
this.initFnSymbol = other.initFnSymbol;
this.serializeFnSymbol = other.serializeFnSymbol;
this.mergeFnSymbol = other.mergeFnSymbol;
this.getValueFnSymbol = other.getValueFnSymbol;
this.removeFnSymbol = other.removeFnSymbol;
this.finalizeFnSymbol = other.finalizeFnSymbol;
this.intermediateType = other.intermediateType;
this.symbolName = other.symbolName;
}

@Override
Expand Down Expand Up @@ -129,7 +137,7 @@ public AggregateFunction(FunctionName fnName, Type[] argTypes,
}

public static class AggregateFunctionBuilder {
TFunctionBinaryType binaryType;
Function.BinaryType binaryType;
FunctionName name;
Type[] argTypes;
Type retType;
Expand All @@ -145,12 +153,12 @@ public static class AggregateFunctionBuilder {
String getValueFnSymbol;
String symbolName;

private AggregateFunctionBuilder(TFunctionBinaryType binaryType) {
private AggregateFunctionBuilder(Function.BinaryType binaryType) {
this.binaryType = binaryType;
}

public static AggregateFunctionBuilder createUdfBuilder() {
return new AggregateFunctionBuilder(TFunctionBinaryType.JAVA_UDF);
return new AggregateFunctionBuilder(Function.BinaryType.JAVA_UDF);
}

public AggregateFunctionBuilder name(FunctionName name) {
Expand Down Expand Up @@ -218,11 +226,6 @@ public AggregateFunctionBuilder removeFnSymbol(String symbol) {
return this;
}

public AggregateFunctionBuilder binaryType(TFunctionBinaryType binaryType) {
this.binaryType = binaryType;
return this;
}

public AggregateFunctionBuilder symbolName(String symbol) {
this.symbolName = symbol;
return this;
Expand Down Expand Up @@ -291,34 +294,6 @@ public Type getIntermediateType() {
return intermediateType;
}

public void setUpdateFnSymbol(String fn) {
updateFnSymbol = fn;
}

public void setInitFnSymbol(String fn) {
initFnSymbol = fn;
}

public void setSerializeFnSymbol(String fn) {
serializeFnSymbol = fn;
}

public void setMergeFnSymbol(String fn) {
mergeFnSymbol = fn;
}

public void setGetValueFnSymbol(String fn) {
getValueFnSymbol = fn;
}

public void setRemoveFnSymbol(String fn) {
removeFnSymbol = fn;
}

public void setFinalizeFnSymbol(String fn) {
finalizeFnSymbol = fn;
}

public void setSymbolName(String fn) {
symbolName = fn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

package org.apache.doris.catalog;

import org.apache.doris.common.URI;
import org.apache.doris.common.UserException;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.common.util.URI;
import org.apache.doris.persist.gson.GsonUtils;
import org.apache.doris.thrift.TFunctionBinaryType;
import org.apache.doris.persist.gson.GsonUtilsBase;

import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.gson.annotations.SerializedName;
import org.apache.commons.io.output.NullOutputStream;

Expand All @@ -52,6 +50,17 @@ public enum NullableMode {
ALWAYS_NOT_NULLABLE
}

public enum BinaryType {
BUILTIN,
HIVE,
NATIVE,
IR,
RPC,
JAVA_UDF,
AGG_STATE,
PYTHON_UDF
}

// Function id, every function has a unique id. Now all built-in functions' id is 0
@SerializedName("id")
private long id = 0;
Expand Down Expand Up @@ -79,7 +88,7 @@ public enum NullableMode {
@SerializedName("l")
private URI location;
@SerializedName("bt")
private TFunctionBinaryType binaryType;
private BinaryType binaryType;

@SerializedName("nm")
protected NullableMode nullableMode = NullableMode.DEPEND_ON_ARGUMENT;
Expand Down Expand Up @@ -119,12 +128,12 @@ public Function(FunctionName name, List<Type> args, Type retType,
}

public Function(long id, FunctionName name, List<Type> argTypes, Type retType, boolean hasVarArgs,
TFunctionBinaryType binaryType, boolean userVisible, boolean vectorized, NullableMode mode) {
Function.BinaryType binaryType, boolean userVisible, boolean vectorized, NullableMode mode) {
this.id = id;
this.name = name;
this.hasVarArgs = hasVarArgs;
if (argTypes.size() > 0) {
this.argTypes = argTypes.toArray(new Type[argTypes.size()]);
if (!argTypes.isEmpty()) {
this.argTypes = argTypes.toArray(new Type[0]);
} else {
this.argTypes = new Type[0];
}
Expand All @@ -137,7 +146,7 @@ public Function(long id, FunctionName name, List<Type> argTypes, Type retType, b

public Function(long id, FunctionName name, List<Type> argTypes, Type retType,
boolean hasVarArgs, boolean vectorized, NullableMode mode) {
this(id, name, argTypes, retType, hasVarArgs, TFunctionBinaryType.BUILTIN, true, vectorized, mode);
this(id, name, argTypes, retType, hasVarArgs, BinaryType.BUILTIN, true, vectorized, mode);
}

public Function(Function other) {
Expand Down Expand Up @@ -195,7 +204,7 @@ public Type[] getArgs() {
}

public void setArgs(List<Type> argTypes) {
this.argTypes = argTypes.toArray(new Type[argTypes.size()]);
this.argTypes = argTypes.toArray(new Type[0]);
}

// Returns the number of arguments to this function.
Expand All @@ -215,11 +224,11 @@ public void setName(FunctionName name) {
this.name = name;
}

public TFunctionBinaryType getBinaryType() {
public Function.BinaryType getBinaryType() {
return binaryType;
}

public void setBinaryType(TFunctionBinaryType type) {
public void setBinaryType(Function.BinaryType type) {
binaryType = type;
}

Expand All @@ -235,14 +244,6 @@ public void setUserVisible(boolean userVisible) {
this.userVisible = userVisible;
}

public Type getVarArgsType() {
if (!hasVarArgs) {
return Type.INVALID;
}
Preconditions.checkState(argTypes.length > 0);
return argTypes[argTypes.length - 1];
}

public void setHasVarArgs(boolean v) {
hasVarArgs = v;
}
Expand Down Expand Up @@ -330,11 +331,11 @@ public boolean isIdentical(Function o) {

@Override
public void write(DataOutput output) throws IOException {
Text.writeString(output, GsonUtils.GSON.toJson(this));
Text.writeString(output, GsonUtilsBase.GSON.toJson(this));
}

public static Function read(DataInput input) throws IOException {
return GsonUtils.GSON.fromJson(Text.readString(input), Function.class);
return GsonUtilsBase.GSON.fromJson(Text.readString(input), Function.class);
}

public void setNullableMode(NullableMode nullableMode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// 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.doris.catalog;

import org.apache.doris.common.URI;

import com.google.gson.annotations.SerializedName;

import java.util.Arrays;
import java.util.List;

// import org.apache.doris.thrift.TSymbolType;

/**
* Internal representation of a scalar function.
*/
public class ScalarFunction extends Function {
// The name inside the binary at location_ that contains this particular
// function. e.g. org.example.MyUdf.class.
@SerializedName("sn")
private String symbolName;
@SerializedName("pfs")
private String prepareFnSymbol;
@SerializedName("cfs")
private String closeFnSymbol;

DictFunction dictFunction = null;

public static class DictFunction {
private final long id;
private final long version;

public DictFunction(long id, long version) {
this.id = id;
this.version = version;
}

public long getId() {
return id;
}

public long getVersion() {
return version;
}
}

// Only used for serialization
protected ScalarFunction() {
}

public ScalarFunction(FunctionName fnName, List<Type> argTypes, Type retType, boolean hasVarArgs,
boolean userVisible) {
this(fnName, argTypes, retType, hasVarArgs, Function.BinaryType.BUILTIN, userVisible, true);
}

private ScalarFunction(FunctionName fnName, List<Type> argTypes, Type retType, boolean hasVarArgs,
Function.BinaryType binaryType, boolean userVisible, boolean isVec) {
super(0, fnName, argTypes, retType, hasVarArgs, binaryType, userVisible, isVec,
NullableMode.DEPEND_ON_ARGUMENT);
}

/**
* nerieds custom scalar function
*/
public ScalarFunction(FunctionName fnName, List<Type> argTypes, Type retType, boolean hasVarArgs, String symbolName,
BinaryType binaryType, boolean userVisible, boolean isVec, NullableMode nullableMode) {
super(0, fnName, argTypes, retType, hasVarArgs, binaryType, userVisible, isVec, nullableMode);
this.symbolName = symbolName;
}

public static ScalarFunction createUdf(
Function.BinaryType binaryType,
FunctionName name, Type[] args,
Type returnType, boolean isVariadic,
URI location, String symbol, String prepareFnSymbol, String closeFnSymbol) {
ScalarFunction fn = new ScalarFunction(name, Arrays.asList(args), returnType, isVariadic, binaryType,
true, false);
fn.symbolName = symbol;
fn.prepareFnSymbol = prepareFnSymbol;
fn.closeFnSymbol = closeFnSymbol;
fn.setLocation(location);
return fn;
}

public ScalarFunction(ScalarFunction other) {
super(other);
if (other == null) {
return;
}
symbolName = other.symbolName;
prepareFnSymbol = other.prepareFnSymbol;
closeFnSymbol = other.closeFnSymbol;
dictFunction = other.dictFunction;
}

@Override
public Function clone() {
return new ScalarFunction(this);
}

public String getSymbolName() {
return symbolName;
}

public String getPrepareFnSymbol() {
return prepareFnSymbol;
}

public String getCloseFnSymbol() {
return closeFnSymbol;
}

public DictFunction getDictFunction() {
return dictFunction;
}

public void setDictFunction(DictFunction dictFunction) {
this.dictFunction = dictFunction;
}
}
Loading
Loading