This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new e7b05f7  Date format support java date style "yyyy-MM-dd HH:mm:ss" 
(#2309)
e7b05f7 is described below

commit e7b05f7eb3a63881d4812af4a6992f03b2308a13
Author: HangyuanLiu <[email protected]>
AuthorDate: Thu Nov 28 14:34:31 2019 +0800

    Date format support java date style "yyyy-MM-dd HH:mm:ss" (#2309)
---
 .../sql-functions/date-time-functions/from_unixtime.md     |  9 ++++++++-
 .../java/org/apache/doris/analysis/FunctionCallExpr.java   | 14 ++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git 
a/docs/documentation/cn/sql-reference/sql-functions/date-time-functions/from_unixtime.md
 
b/docs/documentation/cn/sql-reference/sql-functions/date-time-functions/from_unixtime.md
index 352a143..9b48a22 100644
--- 
a/docs/documentation/cn/sql-reference/sql-functions/date-time-functions/from_unixtime.md
+++ 
b/docs/documentation/cn/sql-reference/sql-functions/date-time-functions/from_unixtime.md
@@ -26,7 +26,7 @@ under the License.
 
 将 unix 时间戳转化位对应的 time 格式,返回的格式由 `string_format` 指定
 
-默认为 yyyy-MM-dd HH:mm:ss
+默认为 yyyy-MM-dd HH:mm:ss ,也支持date_format中的format格式
 
 传入的是整形,返回的是字符串类型
 
@@ -55,6 +55,13 @@ mysql> select from_unixtime(1196440219);
 | 2007-12-01 00:30:19       |
 +---------------------------+
 
+mysql> select from_unixtime(1196440219, 'yyyy-MM-dd HH:mm:ss');
++--------------------------------------------------+
+| from_unixtime(1196440219, 'yyyy-MM-dd HH:mm:ss') |
++--------------------------------------------------+
+| 2007-12-01 00:30:19                              |
++--------------------------------------------------+
+
 mysql> select from_unixtime(1196440219, '%Y-%m-%d');
 +-----------------------------------------+
 | from_unixtime(1196440219, '%Y-%m-%d') |
diff --git a/fe/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java 
b/fe/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
index f624d54..3720883 100644
--- a/fe/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
+++ b/fe/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
@@ -596,6 +596,20 @@ public class FunctionCallExpr extends Expr {
             throw new 
AnalysisException(getFunctionNotFoundError(collectChildReturnTypes()));
         }
 
+        if (fnName.getFunction().equalsIgnoreCase("from_unixtime")) {
+            // if has only one child, it has default time format: yyyy-MM-dd 
HH:mm:ss.SSSSSS
+            if (children.size() > 1) {
+                final StringLiteral fmtLiteral = (StringLiteral) 
children.get(1);
+                if (fmtLiteral.getStringValue().equals("yyyyMMdd")) {
+                    children.set(1, new StringLiteral("%Y%m%d"));
+                } else if (fmtLiteral.getStringValue().equals("yyyy-MM-dd")) {
+                    children.set(1, new StringLiteral("%Y-%m-%d"));
+                } else if (fmtLiteral.getStringValue().equals("yyyy-MM-dd 
HH:mm:ss")) {
+                    children.set(1, new StringLiteral("%Y-%m-%d %H:%i:%s"));
+                }
+            }
+        }
+
         if (fn.getFunctionName().getFunction().equals("time_diff")) {
             fn.getReturnType().getPrimitiveType().setTimeType();
             return;


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

Reply via email to