[fix](nereids)str_to_date function's signature for folding constant is wrong (#32474)
This commit is contained in:
@ -33,6 +33,8 @@ import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeA
|
||||
import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeArithmetic;
|
||||
import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeExtractAndTransform;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.DateTimeLiteral;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.DateTimeV2Literal;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.DateV2Literal;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
|
||||
|
||||
@ -163,12 +165,17 @@ public class MTMVUtil {
|
||||
String dateFormat = dateFormatOptional.get();
|
||||
Expression strToDate = DateTimeExtractAndTransform
|
||||
.strToDate(new VarcharLiteral(expr.getStringValue()), new VarcharLiteral(dateFormat));
|
||||
if (!(strToDate instanceof DateTimeLiteral)) {
|
||||
if (strToDate instanceof DateTimeV2Literal) {
|
||||
return ((IntegerLiteral) DateTimeExtractAndTransform
|
||||
.unixTimestamp((DateTimeV2Literal) strToDate)).getValue();
|
||||
} else if (strToDate instanceof DateV2Literal) {
|
||||
return ((IntegerLiteral) DateTimeExtractAndTransform
|
||||
.unixTimestamp((DateV2Literal) strToDate)).getValue();
|
||||
} else {
|
||||
throw new AnalysisException(
|
||||
String.format("strToDate failed, stringValue: %s, dateFormat: %s", expr.getStringValue(),
|
||||
dateFormat));
|
||||
String.format("strToDate failed, stringValue: %s, dateFormat: %s",
|
||||
expr.getStringValue(), dateFormat));
|
||||
}
|
||||
return ((IntegerLiteral) DateTimeExtractAndTransform.unixTimestamp((DateTimeLiteral) strToDate)).getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -593,10 +593,15 @@ public class DateTimeExtractAndTransform {
|
||||
/**
|
||||
* date transformation function: str_to_date
|
||||
*/
|
||||
@ExecFunction(name = "str_to_date", argTypes = {"VARCHAR, VARCHAR"}, returnType = "DATETIME")
|
||||
@ExecFunction(name = "str_to_date", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "DATETIMEV2")
|
||||
public static Expression strToDate(VarcharLiteral str, VarcharLiteral format) {
|
||||
return DateTimeLiteral.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
|
||||
.toFormatter(), str.getValue()));
|
||||
if (org.apache.doris.analysis.DateLiteral.hasTimePart(format.getStringValue())) {
|
||||
return DateTimeV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
|
||||
.toFormatter(), str.getValue()));
|
||||
} else {
|
||||
return DateV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
|
||||
.toFormatter(), str.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@ExecFunction(name = "timestamp", argTypes = {"DATETIME"}, returnType = "DATETIME")
|
||||
|
||||
Reference in New Issue
Block a user