[Improvement](functions)Optimized some datetime function's return value (#18369)

This commit is contained in:
zclllyybb
2023-04-19 15:51:11 +08:00
committed by GitHub
parent 1f5f5a12b6
commit fb377a9da9
31 changed files with 462 additions and 279 deletions

View File

@ -26,7 +26,7 @@ import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TinyIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -40,9 +40,9 @@ public class DayOfMonth extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE)
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateV2Type.INSTANCE)
);
/**

View File

@ -26,7 +26,7 @@ import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TinyIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -40,9 +40,9 @@ public class DayOfWeek extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE)
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateV2Type.INSTANCE)
);
/**

View File

@ -26,7 +26,7 @@ import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.SmallIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -40,9 +40,9 @@ public class DayOfYear extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE)
FunctionSignature.ret(SmallIntType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(SmallIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(SmallIntType.INSTANCE).args(DateV2Type.INSTANCE)
);
/**

View File

@ -26,7 +26,7 @@ import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TinyIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -40,9 +40,9 @@ public class Hour extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE)
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateV2Type.INSTANCE)
);
/**

View File

@ -26,7 +26,7 @@ import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TinyIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -40,9 +40,9 @@ public class Minute extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE)
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateV2Type.INSTANCE)
);
/**

View File

@ -26,7 +26,7 @@ import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TinyIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -40,9 +40,9 @@ public class Month extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE)
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateV2Type.INSTANCE)
);
/**

View File

@ -26,7 +26,7 @@ import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TinyIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -40,9 +40,9 @@ public class Quarter extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE)
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateV2Type.INSTANCE)
);
/**

View File

@ -26,7 +26,7 @@ import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TinyIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -40,9 +40,9 @@ public class Second extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE)
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateV2Type.INSTANCE)
);
/**

View File

@ -26,6 +26,7 @@ import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TinyIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -39,12 +40,12 @@ public class Week extends ScalarFunction
implements ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE, IntegerType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE, IntegerType.INSTANCE)
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateV2Type.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeType.INSTANCE, IntegerType.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateV2Type.INSTANCE, IntegerType.INSTANCE)
);
/**

View File

@ -26,7 +26,7 @@ import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TinyIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -40,9 +40,9 @@ public class WeekOfYear extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE)
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateV2Type.INSTANCE)
);
/**

View File

@ -26,7 +26,7 @@ import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TinyIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -40,9 +40,9 @@ public class Weekday extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE)
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
FunctionSignature.ret(TinyIntType.INSTANCE).args(DateV2Type.INSTANCE)
);
/**

View File

@ -26,7 +26,7 @@ import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.SmallIntType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -40,9 +40,9 @@ public class Year extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(DateV2Type.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT)
FunctionSignature.ret(SmallIntType.INSTANCE).args(DateV2Type.INSTANCE),
FunctionSignature.ret(SmallIntType.INSTANCE).args(DateTimeType.INSTANCE),
FunctionSignature.ret(SmallIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT)
);
/**

View File

@ -77,7 +77,7 @@ public class FEFunctions {
return new IntLiteral(datediff, Type.INT);
}
@FEFunction(name = "dayofweek", argTypes = {"DATETIME"}, returnType = "INT")
@FEFunction(name = "dayofweek", argTypes = {"DATETIME"}, returnType = "TINYINT")
public static IntLiteral dayOfWeek(LiteralExpr date) throws AnalysisException {
// use zellar algorithm.
long year = ((DateLiteral) date).getYear();
@ -197,17 +197,17 @@ public class FEFunctions {
return secondsAdd(date, new IntLiteral(-(int) second.getLongValue()));
}
@FEFunction(name = "year", argTypes = { "DATETIME" }, returnType = "INT")
@FEFunction(name = "year", argTypes = { "DATETIME" }, returnType = "SMALLINT")
public static IntLiteral year(LiteralExpr arg) throws AnalysisException {
return new IntLiteral(((DateLiteral) arg).getYear(), Type.INT);
}
@FEFunction(name = "month", argTypes = { "DATETIME" }, returnType = "INT")
@FEFunction(name = "month", argTypes = { "DATETIME" }, returnType = "TINYINT")
public static IntLiteral month(LiteralExpr arg) throws AnalysisException {
return new IntLiteral(((DateLiteral) arg).getMonth(), Type.INT);
}
@FEFunction(name = "day", argTypes = { "DATETIME" }, returnType = "INT")
@FEFunction(name = "day", argTypes = { "DATETIME" }, returnType = "TINYINT")
public static IntLiteral day(LiteralExpr arg) throws AnalysisException {
return new IntLiteral(((DateLiteral) arg).getDay(), Type.INT);
}
@ -292,7 +292,7 @@ public class FEFunctions {
Type.DATETIME);
}
@FEFunction(name = "hour", argTypes = {"DATETIME"}, returnType = "INT")
@FEFunction(name = "hour", argTypes = {"DATETIME"}, returnType = "TINYINT")
public static IntLiteral hour(LiteralExpr arg) throws AnalysisException {
if (arg instanceof DateLiteral) {
return new IntLiteral(((DateLiteral) arg).getHour());
@ -300,7 +300,7 @@ public class FEFunctions {
return null;
}
@FEFunction(name = "minute", argTypes = {"DATETIME"}, returnType = "INT")
@FEFunction(name = "minute", argTypes = {"DATETIME"}, returnType = "TINYINT")
public static IntLiteral minute(LiteralExpr arg) throws AnalysisException {
if (arg instanceof DateLiteral) {
return new IntLiteral(((DateLiteral) arg).getMinute());
@ -308,7 +308,7 @@ public class FEFunctions {
return null;
}
@FEFunction(name = "second", argTypes = {"DATETIME"}, returnType = "INT")
@FEFunction(name = "second", argTypes = {"DATETIME"}, returnType = "TINYINT")
public static IntLiteral second(LiteralExpr arg) throws AnalysisException {
if (arg instanceof DateLiteral) {
return new IntLiteral(((DateLiteral) arg).getSecond());

View File

@ -22,6 +22,7 @@ import org.apache.doris.analysis.DescriptorTable;
import org.apache.doris.analysis.Expr;
import org.apache.doris.analysis.SlotRef;
import org.apache.doris.catalog.Column;
import org.apache.doris.common.Config;
import org.apache.doris.thrift.TAlterMaterializedViewParam;
import org.apache.doris.thrift.TAlterTabletReqV2;
import org.apache.doris.thrift.TAlterTabletType;
@ -112,6 +113,7 @@ public class AlterReplicaTask extends AgentTask {
public TAlterTabletReqV2 toThrift() {
TAlterTabletReqV2 req = new TAlterTabletReqV2(baseTabletId, signature, baseSchemaHash, newSchemaHash);
req.setAlterVersion(version);
req.setBeExecVersion(Config.be_exec_version);
switch (jobType) {
case ROLLUP:
req.setAlterTabletType(TAlterTabletType.ROLLUP);