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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java:
##########
@@ -1304,4 +1304,83 @@ public static Expression secToTime(IntegerLiteral sec) {
     public static Expression secToTime(DoubleLiteral sec) {
         return new TimeV2Literal(sec.getValue() * 1000000);
     }
+
+    /**
+     * get_format function for constant folding
+     */
+    @ExecFunction(name = "get_format")
+    public static Expression getFormat(StringLikeLiteral type, 
StringLikeLiteral format) {
+        String typeStr = type.getValue();
+        String formatStr = format.getValue().toUpperCase();
+
+        String result = null;
+
+        switch (typeStr) {
+            case "DATE":
+                switch (formatStr) {
+                    case "USA":
+                        result = "%m.%d.%Y";
+                        break;
+                    case "JIS":
+                    case "ISO":
+                        result = "%Y-%m-%d";
+                        break;
+                    case "EUR":
+                        result = "%d.%m.%Y";
+                        break;
+                    case "INTERNAL":
+                        result = "%Y%m%d";
+                        break;
+                    default:
+                        break;
+                }
+                break;
+            case "DATETIME":
+                switch (formatStr) {
+                    case "USA":
+                        result = "%Y-%m-%d %H.%i.%s";
+                        break;
+                    case "JIS":
+                    case "ISO":
+                        result = "%Y-%m-%d %H:%i:%s";
+                        break;
+                    case "EUR":
+                        result = "%Y-%m-%d %H.%i.%s";
+                        break;
+                    case "INTERNAL":
+                        result = "%Y%m%d%H%i%s";
+                        break;
+                    default:
+                        break;
+                }
+                break;
+            case "TIME":
+                switch (formatStr) {
+                    case "USA":
+                        result = "%h:%i:%s %p";
+                        break;
+                    case "JIS":
+                    case "ISO":
+                        result = "%H:%i:%s";
+                        break;
+                    case "EUR":
+                        result = "%H.%i.%s";
+                        break;
+                    case "INTERNAL":
+                        result = "%H%i%s";
+                        break;
+                    default:
+                        break;
+                }
+                break;
+            default:
+                break;
+        }
+
+        if (result == null) {
+            return new NullLiteral();

Review Comment:
   should add type for null literal



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to