You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/10/18 04:12:39 UTC

[doris] branch master updated: [feature](nereids) let minValue and maxValue in stats support for Date, CHAR and VARCHAR type (#13311)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 18f2db6064 [feature](nereids) let minValue and maxValue in stats support for Date, CHAR and VARCHAR type (#13311)
18f2db6064 is described below

commit 18f2db6064157143921de9b470eb4fb562096332
Author: minghong <mi...@163.com>
AuthorDate: Tue Oct 18 12:12:33 2022 +0800

    [feature](nereids) let minValue and maxValue in stats support for Date, CHAR and VARCHAR type (#13311)
    
    1. enable varchar/char type set min/max value.
        take first 8 chars as long, and convert to double.
    2. fix bug when set min/max value for date and datav2
---
 .../java/org/apache/doris/statistics/ColumnStat.java  | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStat.java b/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStat.java
index a8ed00b031..4b9f0e292b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStat.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStat.java
@@ -34,6 +34,7 @@ import org.apache.doris.common.util.Util;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
@@ -259,18 +260,17 @@ public class ColumnStat {
                     return Double.parseDouble(columnValue);
                 case DATE:
                 case DATEV2:
-                    DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-                    return LocalDateTime
-                            .parse(columnValue, timeFormatter)
+                    return LocalDate.parse(columnValue).atStartOfDay()
                             .atZone(ZoneId.systemDefault()).toInstant().getEpochSecond();
                 case DATETIMEV2:
                 case DATETIME:
-                    timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                    DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                     return LocalDateTime
                             .parse(columnValue, timeFormatter)
                             .atZone(ZoneId.systemDefault()).toInstant().getEpochSecond();
                 case CHAR:
                 case VARCHAR:
+                    return convertStringToDouble(columnValue);
                 case HLL:
                 case BITMAP:
                 case ARRAY:
@@ -285,6 +285,17 @@ public class ColumnStat {
 
     }
 
+    private double convertStringToDouble(String s) {
+        long v = 0;
+        int pos = 0;
+        int len = Math.min(s.length(), 8);
+        while (pos < len) {
+            v += ((long) s.charAt(pos)) << ((7 - pos) * 8);
+            pos++;
+        }
+        return (double) v;
+    }
+
     public ColumnStat copy() {
         return new ColumnStat(this);
     }


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