[fix](function) fix error result in time_to_sec and timediff (#30248)

This commit is contained in:
Mryange
2024-01-26 10:29:09 +08:00
committed by yiguolei
parent 144204fecc
commit a954bab81a
6 changed files with 24 additions and 24 deletions

View File

@ -25,6 +25,7 @@ import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TimeType;
import org.apache.doris.nereids.types.TimeV2Type;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@ -38,7 +39,8 @@ public class TimeToSec extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(IntegerType.INSTANCE).args(TimeType.INSTANCE));
FunctionSignature.ret(IntegerType.INSTANCE).args(TimeType.INSTANCE),
FunctionSignature.ret(IntegerType.INSTANCE).args(TimeV2Type.INSTANCE));
/**
* constructor with 1 argument.

View File

@ -58,12 +58,12 @@ public class FEFunctions {
/**
* date and time function
*/
@FEFunction(name = "timediff", argTypes = { "DATETIME", "DATETIME" }, returnType = "TIME")
@FEFunction(name = "timediff", argTypes = { "DATETIME", "DATETIME" }, returnType = "TIMEV2")
public static FloatLiteral timeDiff(LiteralExpr first, LiteralExpr second) throws AnalysisException {
long firstTimestamp = ((DateLiteral) first).unixTimestamp(TimeUtils.getTimeZone());
long secondTimestamp = ((DateLiteral) second).unixTimestamp(TimeUtils.getTimeZone());
return new FloatLiteral((double) (firstTimestamp - secondTimestamp) / 1000,
FloatLiteral.getDefaultTimeType(Type.TIME));
return new FloatLiteral((double) (firstTimestamp - secondTimestamp) * 1000,
FloatLiteral.getDefaultTimeType(Type.TIMEV2));
}
@FEFunction(name = "datediff", argTypes = { "DATETIME", "DATETIME" }, returnType = "INT")