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
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,14 @@ public static String toSql(ScalarFunction fn, boolean ifNotExists) {
.append("\"" + (fn.getLocation() == null ? "" : fn.getLocation().toString()) + "\"");
boolean isReturnNull = fn.getNullableMode() == NullableMode.ALWAYS_NULLABLE;
sb.append(",\n \"ALWAYS_NULLABLE\"=").append("\"" + isReturnNull + "\"");
if (!fn.isUDTFunction()) {
sb.append(",\n \"VOLATILITY\"=").append("\"" + fn.getVolatility().toSql() + "\"");
}
sb.append(",\n \"VOLATILITY\"=").append("\"" + fn.getVolatility().toSql() + "\"");
} else if (fn.getBinaryType() == Function.BinaryType.PYTHON_UDF) {
appendFileIfPresent(sb, fn, true);
boolean isReturnNull = fn.getNullableMode() == NullableMode.ALWAYS_NULLABLE;
sb.append(",\n \"ALWAYS_NULLABLE\"=").append("\"" + isReturnNull + "\"");
sb.append(",\n \"RUNTIME_VERSION\"=").append("\"" + Strings.nullToEmpty(fn.getRuntimeVersion()) + "\"");
appendExpirationTimeIfNeeded(sb, fn);
if (!fn.isUDTFunction()) {
sb.append(",\n \"VOLATILITY\"=").append("\"" + fn.getVolatility().toSql() + "\"");
}
sb.append(",\n \"VOLATILITY\"=").append("\"" + fn.getVolatility().toSql() + "\"");
} else {
sb.append(",\n \"OBJECT_FILE\"=")
.append("\"" + (fn.getLocation() == null ? "" : fn.getLocation().toString()) + "\"");
Expand Down Expand Up @@ -167,6 +163,7 @@ public static String toSql(AggregateFunction fn, boolean ifNotExists) {
.append("\"" + (fn.getLocation() == null ? "" : fn.getLocation().toString()) + "\",");
boolean isReturnNull = fn.getNullableMode() == NullableMode.ALWAYS_NULLABLE;
sb.append("\n \"ALWAYS_NULLABLE\"=").append("\"" + isReturnNull + "\",");
sb.append("\n \"VOLATILITY\"=").append("\"" + fn.getVolatility().toSql() + "\",");
} else if (fn.getBinaryType() == Function.BinaryType.PYTHON_UDF) {
appendFileIfPresent(sb, fn, false);
if (fn.getLocation() != null) {
Expand All @@ -179,6 +176,7 @@ public static String toSql(AggregateFunction fn, boolean ifNotExists) {
if (fn.getExpirationTime() != DEFAULT_EXPIRATION_TIME) {
sb.append("\n \"EXPIRATION_TIME\"=").append("\"" + fn.getExpirationTime() + "\",");
}
sb.append("\n \"VOLATILITY\"=").append("\"" + fn.getVolatility().toSql() + "\",");
} else {
sb.append("\n \"OBJECT_FILE\"=")
.append("\"" + (fn.getLocation() == null ? "" : fn.getLocation().toString()) + "\",");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.doris.catalog.Function;
import org.apache.doris.catalog.Function.NullableMode;
import org.apache.doris.catalog.FunctionVolatility;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Expression;

Expand All @@ -45,8 +46,27 @@ default boolean nullable() {

NullableMode getNullableMode();

FunctionVolatility getVolatility();

List<Expression> children();

default boolean isImmutable() {
return getVolatility() == FunctionVolatility.IMMUTABLE;
}

default boolean isStable() {
return getVolatility() == FunctionVolatility.STABLE;
}

default boolean isVolatile() {
return getVolatility() == FunctionVolatility.VOLATILE;
}

@Override
default boolean isDeterministic() {
return isImmutable();
}

@Override
default boolean foldable() {
// Udf should not be folded in FE.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.doris.catalog.Function.NullableMode;
import org.apache.doris.catalog.FunctionName;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.catalog.FunctionVolatility;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.util.URI;
import org.apache.doris.nereids.exceptions.AnalysisException;
Expand Down Expand Up @@ -50,6 +51,7 @@ public class JavaUdaf extends AggregateFunction implements ExplicitlyCastableSig
private final FunctionSignature signature;
private final DataType intermediateType;
private final NullableMode nullableMode;
private final FunctionVolatility volatility;
private final String objectFile;
private final String symbol;
private final String initFn;
Expand All @@ -69,7 +71,7 @@ public class JavaUdaf extends AggregateFunction implements ExplicitlyCastableSig
public JavaUdaf(String name, long functionId, String dbName, Function.BinaryType binaryType,
FunctionSignature signature,
DataType intermediateType, NullableMode nullableMode,
String objectFile, String symbol,
FunctionVolatility volatility, String objectFile, String symbol,
String initFn, String updateFn, String mergeFn,
String serializeFn, String finalizeFn, String getValueFn, String removeFn,
boolean isDistinct, String checkSum, boolean isStaticLoad, long expirationTime, Expression... args) {
Expand All @@ -80,6 +82,7 @@ public JavaUdaf(String name, long functionId, String dbName, Function.BinaryType
this.signature = signature;
this.intermediateType = intermediateType == null ? signature.returnType : intermediateType;
this.nullableMode = nullableMode;
this.volatility = volatility;
this.objectFile = objectFile;
this.symbol = symbol;
this.initFn = initFn;
Expand Down Expand Up @@ -121,8 +124,8 @@ public NullableMode getNullableMode() {
public JavaUdaf withDistinctAndChildren(boolean isDistinct, List<Expression> children) {
Preconditions.checkArgument(children.size() == this.children.size());
return new JavaUdaf(getName(), functionId, dbName, binaryType, signature, intermediateType, nullableMode,
objectFile, symbol, initFn, updateFn, mergeFn, serializeFn, finalizeFn, getValueFn, removeFn,
isDistinct, checkSum, isStaticLoad, expirationTime, children.toArray(new Expression[0]));
volatility, objectFile, symbol, initFn, updateFn, mergeFn, serializeFn, finalizeFn, getValueFn,
removeFn, isDistinct, checkSum, isStaticLoad, expirationTime, children.toArray(new Expression[0]));
}

/**
Expand Down Expand Up @@ -152,6 +155,7 @@ public static void translateToNereidsFunction(String dbName, org.apache.doris.ca
JavaUdaf udaf = new JavaUdaf(fnName, aggregate.getId(), dbName, aggregate.getBinaryType(), sig,
intermediateType,
aggregate.getNullableMode(),
aggregate.getVolatility(),
aggregate.getLocation() == null ? null : aggregate.getLocation().getLocation(),
aggregate.getSymbolName(),
aggregate.getInitFnSymbol(),
Expand Down Expand Up @@ -201,9 +205,15 @@ public Function getCatalogFunction() {
expr.setId(functionId);
expr.setStaticLoad(isStaticLoad);
expr.setExpirationTime(expirationTime);
expr.setVolatility(volatility);
return expr;
} catch (Exception e) {
throw new AnalysisException(e.getMessage(), e.getCause());
}
}

@Override
public FunctionVolatility getVolatility() {
return volatility;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ public JavaUdf withFreshVolatileIdentity() {
children.toArray(new Expression[0]));
}

@Override
public boolean isDeterministic() {
return volatility == FunctionVolatility.IMMUTABLE;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof JavaUdf)) {
Expand Down Expand Up @@ -226,6 +221,11 @@ public Function getCatalogFunction() {
}
}

@Override
public FunctionVolatility getVolatility() {
return volatility;
}

private static VolatileIdentity createVolatileIdentity(FunctionVolatility volatility) {
return volatility == FunctionVolatility.VOLATILE
? VolatileIdentity.newVolatileIdentity() : VolatileIdentity.NON_VOLATILE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.doris.catalog.Function.NullableMode;
import org.apache.doris.catalog.FunctionName;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.catalog.FunctionVolatility;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.util.URI;
import org.apache.doris.nereids.exceptions.AnalysisException;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class JavaUdtf extends TableGeneratingFunction implements ExplicitlyCasta
private final Function.BinaryType binaryType;
private final FunctionSignature signature;
private final NullableMode nullableMode;
private final FunctionVolatility volatility;
private final String objectFile;
private final String symbol;
private final String prepareFn;
Expand All @@ -62,14 +64,16 @@ public class JavaUdtf extends TableGeneratingFunction implements ExplicitlyCasta
*/
public JavaUdtf(String name, long functionId, String dbName, Function.BinaryType binaryType,
FunctionSignature signature,
NullableMode nullableMode, String objectFile, String symbol, String prepareFn, String closeFn,
NullableMode nullableMode, FunctionVolatility volatility, String objectFile, String symbol,
String prepareFn, String closeFn,
String checkSum, boolean isStaticLoad, long expirationTime, Expression... args) {
super(name, args);
this.dbName = dbName;
this.functionId = functionId;
this.binaryType = binaryType;
this.signature = signature;
this.nullableMode = nullableMode;
this.volatility = volatility;
this.objectFile = objectFile;
this.symbol = symbol;
this.prepareFn = prepareFn;
Expand All @@ -86,7 +90,7 @@ public JavaUdtf(String name, long functionId, String dbName, Function.BinaryType
public JavaUdtf withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() == this.children.size());
return new JavaUdtf(getName(), functionId, dbName, binaryType, signature, nullableMode,
objectFile, symbol, prepareFn, closeFn, checkSum, isStaticLoad, expirationTime,
volatility, objectFile, symbol, prepareFn, closeFn, checkSum, isStaticLoad, expirationTime,
children.toArray(new Expression[0]));
}

Expand Down Expand Up @@ -125,6 +129,7 @@ public Function getCatalogFunction() {
expr.setStaticLoad(isStaticLoad);
expr.setExpirationTime(expirationTime);
expr.setUDTFunction(true);
expr.setVolatility(volatility);
return expr;
} catch (Exception e) {
throw new AnalysisException(e.getMessage(), e.getCause());
Expand Down Expand Up @@ -152,6 +157,7 @@ public static void translateToNereidsFunction(String dbName, org.apache.doris.ca

JavaUdtf udf = new JavaUdtf(fnName, scalar.getId(), dbName, scalar.getBinaryType(), sig,
scalar.getNullableMode(),
scalar.getVolatility(),
scalar.getLocation() == null ? null : scalar.getLocation().getLocation(),
scalar.getSymbolName(),
scalar.getPrepareFnSymbol(),
Expand All @@ -170,6 +176,11 @@ public NullableMode getNullableMode() {
return nullableMode;
}

@Override
public FunctionVolatility getVolatility() {
return volatility;
}

@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitJavaUdtf(this, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.doris.catalog.Function.NullableMode;
import org.apache.doris.catalog.FunctionName;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.catalog.FunctionVolatility;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.util.URI;
import org.apache.doris.nereids.exceptions.AnalysisException;
Expand Down Expand Up @@ -50,6 +51,7 @@ public class PythonUdaf extends AggregateFunction implements ExplicitlyCastableS
private final FunctionSignature signature;
private final DataType intermediateType;
private final NullableMode nullableMode;
private final FunctionVolatility volatility;
private final String objectFile;
private final String symbol;
private final String initFn;
Expand All @@ -71,7 +73,7 @@ public class PythonUdaf extends AggregateFunction implements ExplicitlyCastableS
public PythonUdaf(String name, long functionId, String dbName, Function.BinaryType binaryType,
FunctionSignature signature,
DataType intermediateType, NullableMode nullableMode,
String objectFile, String symbol,
FunctionVolatility volatility, String objectFile, String symbol,
String initFn, String updateFn, String mergeFn,
String serializeFn, String finalizeFn, String getValueFn, String removeFn,
boolean isDistinct, String checkSum, boolean isStaticLoad, long expirationTime,
Expand All @@ -83,6 +85,7 @@ public PythonUdaf(String name, long functionId, String dbName, Function.BinaryTy
this.signature = signature;
this.intermediateType = intermediateType == null ? signature.returnType : intermediateType;
this.nullableMode = nullableMode;
this.volatility = volatility;
this.objectFile = objectFile;
this.symbol = symbol;
this.initFn = initFn;
Expand Down Expand Up @@ -126,7 +129,8 @@ public NullableMode getNullableMode() {
public PythonUdaf withDistinctAndChildren(boolean isDistinct, List<Expression> children) {
Preconditions.checkArgument(children.size() == this.children.size());
return new PythonUdaf(getName(), functionId, dbName, binaryType, signature, intermediateType, nullableMode,
objectFile, symbol, initFn, updateFn, mergeFn, serializeFn, finalizeFn, getValueFn, removeFn,
volatility, objectFile, symbol, initFn, updateFn, mergeFn, serializeFn, finalizeFn, getValueFn,
removeFn,
isDistinct, checkSum, isStaticLoad, expirationTime, runtimeVersion, functionCode,
children.toArray(new Expression[0]));
}
Expand Down Expand Up @@ -158,6 +162,7 @@ public static void translateToNereidsFunction(String dbName, org.apache.doris.ca
PythonUdaf udaf = new PythonUdaf(fnName, aggregate.getId(), dbName, aggregate.getBinaryType(), sig,
intermediateType,
aggregate.getNullableMode(),
aggregate.getVolatility(),
aggregate.getLocation() == null ? null : aggregate.getLocation().getLocation(),
aggregate.getSymbolName(),
aggregate.getInitFnSymbol(),
Expand Down Expand Up @@ -211,9 +216,15 @@ public Function getCatalogFunction() {
expr.setExpirationTime(expirationTime);
expr.setRuntimeVersion(runtimeVersion);
expr.setFunctionCode(functionCode);
expr.setVolatility(volatility);
return expr;
} catch (Exception e) {
throw new AnalysisException(e.getMessage(), e.getCause());
}
}

@Override
public FunctionVolatility getVolatility() {
return volatility;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ public PythonUdf withFreshVolatileIdentity() {
runtimeVersion, functionCode, children.toArray(new Expression[0]));
}

@Override
public boolean isDeterministic() {
return volatility == FunctionVolatility.IMMUTABLE;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof PythonUdf)) {
Expand Down Expand Up @@ -235,6 +230,11 @@ public Function getCatalogFunction() {
}
}

@Override
public FunctionVolatility getVolatility() {
return volatility;
}

private static VolatileIdentity createVolatileIdentity(FunctionVolatility volatility) {
return volatility == FunctionVolatility.VOLATILE
? VolatileIdentity.newVolatileIdentity() : VolatileIdentity.NON_VOLATILE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.doris.catalog.Function.NullableMode;
import org.apache.doris.catalog.FunctionName;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.catalog.FunctionVolatility;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.util.URI;
import org.apache.doris.nereids.exceptions.AnalysisException;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class PythonUdtf extends TableGeneratingFunction implements ExplicitlyCas
private final Function.BinaryType binaryType;
private final FunctionSignature signature;
private final NullableMode nullableMode;
private final FunctionVolatility volatility;
private final String objectFile;
private final String symbol;
private final String prepareFn;
Expand All @@ -64,7 +66,8 @@ public class PythonUdtf extends TableGeneratingFunction implements ExplicitlyCas
*/
public PythonUdtf(String name, long functionId, String dbName, Function.BinaryType binaryType,
FunctionSignature signature,
NullableMode nullableMode, String objectFile, String symbol, String prepareFn, String closeFn,
NullableMode nullableMode, FunctionVolatility volatility, String objectFile, String symbol,
String prepareFn, String closeFn,
String checkSum, boolean isStaticLoad, long expirationTime,
String runtimeVersion, String functionCode, Expression... args) {
super(name, args);
Expand All @@ -73,6 +76,7 @@ public PythonUdtf(String name, long functionId, String dbName, Function.BinaryTy
this.binaryType = binaryType;
this.signature = signature;
this.nullableMode = nullableMode;
this.volatility = volatility;
this.objectFile = objectFile;
this.symbol = symbol;
this.prepareFn = prepareFn;
Expand All @@ -91,7 +95,7 @@ public PythonUdtf(String name, long functionId, String dbName, Function.BinaryTy
public PythonUdtf withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() == this.children.size());
return new PythonUdtf(getName(), functionId, dbName, binaryType, signature, nullableMode,
objectFile, symbol, prepareFn, closeFn, checkSum, isStaticLoad, expirationTime,
volatility, objectFile, symbol, prepareFn, closeFn, checkSum, isStaticLoad, expirationTime,
runtimeVersion, functionCode, children.toArray(new Expression[0]));
}

Expand Down Expand Up @@ -132,6 +136,7 @@ public Function getCatalogFunction() {
expr.setUDTFunction(true);
expr.setRuntimeVersion(runtimeVersion);
expr.setFunctionCode(functionCode);
expr.setVolatility(volatility);
return expr;
} catch (Exception e) {
throw new AnalysisException(e.getMessage(), e.getCause());
Expand Down Expand Up @@ -159,6 +164,7 @@ public static void translateToNereidsFunction(String dbName, org.apache.doris.ca

PythonUdtf udtf = new PythonUdtf(fnName, scalar.getId(), dbName, scalar.getBinaryType(), sig,
scalar.getNullableMode(),
scalar.getVolatility(),
scalar.getLocation() == null ? null : scalar.getLocation().getLocation(),
scalar.getSymbolName(),
scalar.getPrepareFnSymbol(),
Expand All @@ -179,6 +185,11 @@ public NullableMode getNullableMode() {
return nullableMode;
}

@Override
public FunctionVolatility getVolatility() {
return volatility;
}

@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitPythonUdtf(this, context);
Expand Down
Loading
Loading