pick from master #37360 when enable datev1, we should return datev1/datetimev1
This commit is contained in:
@ -17,6 +17,8 @@
|
||||
|
||||
package org.apache.doris.nereids.trees.expressions.functions.executable;
|
||||
|
||||
import org.apache.doris.catalog.ScalarType;
|
||||
import org.apache.doris.catalog.Type;
|
||||
import org.apache.doris.nereids.exceptions.AnalysisException;
|
||||
import org.apache.doris.nereids.trees.expressions.ExecFunction;
|
||||
import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
@ -32,8 +34,10 @@ import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
|
||||
import org.apache.doris.nereids.types.DataType;
|
||||
import org.apache.doris.nereids.types.DateTimeV2Type;
|
||||
import org.apache.doris.nereids.types.DateType;
|
||||
import org.apache.doris.nereids.types.DateV2Type;
|
||||
import org.apache.doris.nereids.types.DecimalV3Type;
|
||||
import org.apache.doris.nereids.types.VarcharType;
|
||||
import org.apache.doris.nereids.util.DateUtils;
|
||||
@ -611,11 +615,23 @@ public class DateTimeExtractAndTransform {
|
||||
@ExecFunction(name = "str_to_date", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "DATETIMEV2")
|
||||
public static Expression strToDate(StringLikeLiteral str, StringLikeLiteral format) {
|
||||
if (org.apache.doris.analysis.DateLiteral.hasTimePart(format.getStringValue())) {
|
||||
return DateTimeV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
|
||||
.toFormatter(), str.getValue()));
|
||||
DataType returnType = DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATETIME));
|
||||
if (returnType instanceof DateTimeV2Type) {
|
||||
return DateTimeV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
|
||||
.toFormatter(), str.getValue()));
|
||||
} else {
|
||||
return DateTimeLiteral.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
|
||||
.toFormatter(), str.getValue()));
|
||||
}
|
||||
} else {
|
||||
return DateV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
|
||||
.toFormatter(), str.getValue()));
|
||||
DataType returnType = DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATE));
|
||||
if (returnType instanceof DateV2Type) {
|
||||
return DateV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
|
||||
.toFormatter(), str.getValue()));
|
||||
} else {
|
||||
return DateLiteral.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
|
||||
.toFormatter(), str.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user