morrySnow commented on code in PR #18209:
URL: https://github.com/apache/doris/pull/18209#discussion_r1189333545


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java:
##########
@@ -1337,7 +1337,8 @@ public void analyzeImpl(Analyzer analyzer) throws 
AnalysisException {
                     Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
         } else if (fnName.getFunction().equalsIgnoreCase("if")) {
             Type[] childTypes = collectChildReturnTypes();
-            Type assignmentCompatibleType = 
ScalarType.getAssignmentCompatibleType(childTypes[1], childTypes[2], true);
+            Type assignmentCompatibleType = Type.convertDateLikeTypeToV2(
+                    ScalarType.getAssignmentCompatibleType(childTypes[1], 
childTypes[2], true));

Review Comment:
   why add this?



##########
fe/fe-core/src/main/java/org/apache/doris/analysis/NullLiteral.java:
##########
@@ -132,7 +132,7 @@ protected Expr uncheckedCastTo(Type targetType) throws 
AnalysisException {
         Preconditions.checkState(targetType.isValid());
         if (!type.equals(targetType)) {
             NullLiteral nullLiteral = new NullLiteral(this);
-            nullLiteral.setType(targetType);
+            nullLiteral.setType(Type.convertDateLikeTypeToV2(targetType));

Review Comment:
   why add this?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExpressionEvaluator.java:
##########
@@ -75,7 +87,8 @@ public Expression eval(Expression expression) {
             }
         }
 
-        return invoke(expression, fnName, args);
+        Expression res = invoke(expression, fnName, args);
+        return res == null ? new NullLiteral() : res;

Review Comment:
   why not return NullLiteral directly in real executable method?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java:
##########
@@ -287,23 +295,31 @@ public Expression visitCast(Cast cast, 
ExpressionRewriteContext context) {
 
     @Override
     public Expression visitBoundFunction(BoundFunction boundFunction, 
ExpressionRewriteContext context) {
+        boundFunction = rewriteChildren(boundFunction, context);
         //functions, like current_date, do not have arg
         if (boundFunction.getArguments().isEmpty()) {
             return boundFunction;
         }
-        if (!ExpressionUtils.isAllLiteral(boundFunction.getArguments())) {
-            return boundFunction;
+        Optional<Expression> checkedExpr = checkNeedCalculate(boundFunction);
+        if (checkedExpr.isPresent()) {
+            return checkedExpr.get();
         }
         return ExpressionEvaluator.INSTANCE.eval(boundFunction);
     }
 
     @Override
     public Expression visitBinaryArithmetic(BinaryArithmetic binaryArithmetic, 
ExpressionRewriteContext context) {
+        binaryArithmetic = rewriteChildren(binaryArithmetic, context);
+        Optional<Expression> checkedExpr = 
checkNeedCalculate(binaryArithmetic);

Review Comment:
   i think we cannot do fold constant if this function return 
Optional.empty(),right?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java:
##########
@@ -352,7 +360,8 @@ public static Optional<Expression> 
characterLiteralTypeCoercion(String value, Da
             } else if (dataType instanceof StringType) {
                 ret = new StringLiteral(value);
             } else if (dataType.isDateTimeV2Type()) {
-                ret = new DateTimeV2Literal(value);
+                DateTimeV2Type castDataType = ((DateTimeV2Type) dataType);

Review Comment:
   castDataType is not a good name



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java:
##########
@@ -316,6 +317,13 @@ public static <T extends BinaryOperator> T 
processCharacterLiteralInBinaryOperat
     @Developing
     public static Optional<Expression> characterLiteralTypeCoercion(String 
value, DataType dataType) {
         Expression ret = null;
+        if (Config.enable_date_conversion) {
+            if (dataType instanceof DateType) {
+                dataType = DateV2Type.INSTANCE;
+            } else if (dataType instanceof DateTimeType) {
+                dataType = DateTimeV2Type.MAX;
+            }
+        }

Review Comment:
   why do this?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -1121,7 +1121,7 @@ public Expression 
visitTypeConstructor(TypeConstructorContext ctx) {
         String type = ctx.type.getText().toUpperCase();
         switch (type) {
             case "DATE":
-                return new DateLiteral(value);
+                return Config.enable_date_conversion ? new 
DateV2Literal(value) : new DateLiteral(value);
             case "TIMESTAMP":
                 return new DateTimeLiteral(value);

Review Comment:
   does this need conversion?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java:
##########
@@ -204,4 +214,13 @@ public DateLiteral plusYears(int years) {
         LocalDateTime dateTime = DateUtils.getTime(DATE_FORMATTER, 
getStringValue()).plusYears(years);
         return new DateLiteral(dateTime.getYear(), dateTime.getMonthValue(), 
dateTime.getDayOfMonth());
     }
+
+    public LocalDateTime toJavaDateType() {
+        return LocalDateTime.of(((int) getYear()), ((int) getMonth()), ((int) 
getDay()), 0, 0, 0);
+    }
+
+    public static DateLiteral fromJavaDateType(LocalDateTime dateTime) {
+        return isDateOutOfRange(dateTime) ? null

Review Comment:
   do not return null, return NullLiteral or throw exception



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java:
##########
@@ -44,7 +44,10 @@ public class DateLiteral extends Literal {
     protected static DateTimeFormatter DATE_FORMATTER = null;
     protected static DateTimeFormatter DATE_FORMATTER_TWO_DIGIT = null;
     protected static DateTimeFormatter DATEKEY_FORMATTER = null;
-
+    // for cast date-time type to date-type.

Review Comment:
   ```suggestion
       // for cast datetime type to date type.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to