You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by kx...@apache.org on 2023/10/24 02:05:20 UTC

[doris] branch branch-2.0 updated (8093b4b3342 -> 48c962e7738)

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

kxiao pushed a change to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


    from 8093b4b3342 [branch-2.0-pick] "[Fix](partial-update) Correct the alignment process when the table has sequence column and add cases #25346" (#25789)
     new 9ed12250f5f [fix](datetime) fix unstable str_to_date function result (#25707)
     new 847eb11d3ce [build](extension) Update build-extension.yml (#25721)
     new dd2cc616c17 [Fix](segment) need to rebuild col_id_to_predicates when true predicates encountered (#25685)
     new 10d9625a8eb [fix](rpc) Rebuild failed channel to avoid connection refused (#25688)
     new ccb7e3779cb [regresstion-test](jdbc catalog)Mariadb compatible test (#25664)
     new fe97a17025c [Fix](partial update) Fix wrong comment in .proto file (#25742)
     new 22962c3b15a [enhancement](stmt-exec) make CTAS use insert timeout fix forward timeout (#25731)
     new 4f3dc637afd [bug](function) fix regexp_extract_all can't handle empty str (#25717)
     new b58f1a68c7c [fix](prefetch-read) make prefetch range correct to accelerate S3 load and fix its speed unbalance  (#25775)
     new 48c962e7738 [Fix](exec) Fix date dict dead loop. (#25570)

The 10 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .github/workflows/build-extension.yml              |   1 +
 be/src/olap/rowset/segment_v2/segment.cpp          |  12 ++
 be/src/vec/exec/format/csv/csv_reader.cpp          |   2 +-
 be/src/vec/exec/format/orc/vorc_reader.cpp         |   2 +-
 be/src/vec/exec/format/orc/vorc_reader.h           |   2 +-
 be/src/vec/exec/format/parquet/decoder.cpp         |   2 +-
 be/src/vec/exec/format/parquet/decoder.h           |   2 +-
 be/src/vec/functions/function_regexp.cpp           |   1 +
 be/src/vec/functions/function_timestamp.cpp        |  16 +-
 be/src/vec/runtime/vdatetime_value.cpp             |  26 ++--
 be/src/vec/runtime/vdatetime_value.h               |  18 ++-
 be/test/vec/function/function_string_test.cpp      |  19 ---
 be/test/vec/function/function_time_test.cpp        |  17 ---
 be/test/vec/runtime/vdatetime_value_test.cpp       | 168 +++++++++++++++++++++
 .../{mysql => mariadb}/init/01-drop-db.sql         |   0
 .../{mysql => mariadb}/init/02-create-db.sql       |   0
 .../mariadb/init/03-create-table.sql               |  76 ++++++++++
 .../docker-compose/mariadb/init/04-insert.sql      |  36 +++++
 .../oracle-11.env => mariadb/mariadb-10.env}       |   2 +-
 .../mariadb-10.yaml.tpl}                           |  22 +--
 docker/thirdparties/run-thirdparties-docker.sh     |  26 +++-
 .../org/apache/doris/analysis/DateLiteral.java     |  19 ++-
 .../apache/doris/analysis/FunctionCallExpr.java    |   6 +-
 .../expressions/functions/scalar/StrToDate.java    |   7 +-
 .../java/org/apache/doris/qe/ConnectContext.java   |   4 +-
 .../java/org/apache/doris/qe/StmtExecutor.java     |   9 +-
 .../java/org/apache/doris/rewrite/FEFunctions.java |   2 +-
 .../org/apache/doris/rpc/BackendServiceClient.java |   9 ++
 .../org/apache/doris/rpc/BackendServiceProxy.java  |  19 ++-
 gensrc/proto/descriptors.proto                     |   2 +-
 regression-test/conf/regression-conf.groovy        |   1 +
 .../jdbc/test_mariadb_jdbc_catalog.out             | 117 ++++++++++++++
 .../datetime_functions/test_date_function.out      |   4 +-
 .../test_string_function_regexp.out                |   6 +
 .../pipeline/p0/conf/regression-conf.groovy        |   2 +-
 .../jdbc/test_mariadb_jdbc_catalog.groovy          |  82 ++++++++++
 .../test_string_function_regexp.groovy             |   1 +
 37 files changed, 642 insertions(+), 98 deletions(-)
 copy docker/thirdparties/docker-compose/{mysql => mariadb}/init/01-drop-db.sql (100%)
 copy docker/thirdparties/docker-compose/{mysql => mariadb}/init/02-create-db.sql (100%)
 create mode 100644 docker/thirdparties/docker-compose/mariadb/init/03-create-table.sql
 create mode 100644 docker/thirdparties/docker-compose/mariadb/init/04-insert.sql
 copy docker/thirdparties/docker-compose/{oracle/oracle-11.env => mariadb/mariadb-10.env} (95%)
 copy docker/thirdparties/docker-compose/{mysql/mysql-5.7.yaml.tpl => mariadb/mariadb-10.yaml.tpl} (77%)
 create mode 100644 regression-test/data/external_table_p0/jdbc/test_mariadb_jdbc_catalog.out
 create mode 100644 regression-test/suites/external_table_p0/jdbc/test_mariadb_jdbc_catalog.groovy


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


[doris] 07/10: [enhancement](stmt-exec) make CTAS use insert timeout fix forward timeout (#25731)

Posted by kx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 22962c3b15a73a2769dc966eac6d4a64c4a10dc5
Author: Siyang Tang <82...@users.noreply.github.com>
AuthorDate: Mon Oct 23 14:57:02 2023 +0800

    [enhancement](stmt-exec) make CTAS use insert timeout fix forward timeout (#25731)
---
 fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java | 4 ++--
 fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java   | 9 ++++++---
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
index 90d04c8a2dd..cfb41d3b819 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
@@ -660,7 +660,7 @@ public class ConnectContext {
         } else {
             String timeoutTag = "query";
             // insert stmt particularly
-            if (executor != null && executor.isInsertStmt()) {
+            if (executor != null && executor.isSyncLoadKindStmt()) {
                 timeoutTag = "insert";
             }
             //to ms
@@ -714,7 +714,7 @@ public class ConnectContext {
      * @return exact execution timeout
      */
     public int getExecTimeout() {
-        if (executor != null && executor.isInsertStmt()) {
+        if (executor != null && executor.isSyncLoadKindStmt()) {
             // particular for insert stmt, we can expand other type of timeout in the same way
             return Math.max(sessionVariable.getInsertTimeoutS(), sessionVariable.getQueryTimeoutS());
         } else if (executor != null && executor.isAnalyzeStmt()) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index 5dcb392fb62..24e8f553a8e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -121,6 +121,7 @@ import org.apache.doris.nereids.minidump.MinidumpUtils;
 import org.apache.doris.nereids.parser.NereidsParser;
 import org.apache.doris.nereids.stats.StatsErrorEstimator;
 import org.apache.doris.nereids.trees.plans.commands.Command;
+import org.apache.doris.nereids.trees.plans.commands.CreateTableCommand;
 import org.apache.doris.nereids.trees.plans.commands.Forward;
 import org.apache.doris.nereids.trees.plans.commands.InsertIntoTableCommand;
 import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
@@ -386,15 +387,17 @@ public class StmtExecutor {
         return masterOpExecutor.getProxyStatus();
     }
 
-    public boolean isInsertStmt() {
+    public boolean isSyncLoadKindStmt() {
         if (parsedStmt == null) {
             return false;
         }
         if (parsedStmt instanceof LogicalPlanAdapter) {
             LogicalPlan logicalPlan = ((LogicalPlanAdapter) parsedStmt).getLogicalPlan();
-            return logicalPlan instanceof InsertIntoTableCommand;
+            return logicalPlan instanceof InsertIntoTableCommand
+                    || (logicalPlan instanceof CreateTableCommand
+                    && ((CreateTableCommand) logicalPlan).isCtasCommand());
         }
-        return parsedStmt instanceof InsertStmt;
+        return parsedStmt instanceof InsertStmt || parsedStmt instanceof CreateTableAsSelectStmt;
     }
 
     public boolean isAnalyzeStmt() {


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


[doris] 08/10: [bug](function) fix regexp_extract_all can't handle empty str (#25717)

Posted by kx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 4f3dc637afd5d481e1fb8f1adf1793f1882f1e85
Author: zhangstar333 <87...@users.noreply.github.com>
AuthorDate: Mon Oct 23 15:47:12 2023 +0800

    [bug](function) fix regexp_extract_all can't handle empty str (#25717)
---
 be/src/vec/functions/function_regexp.cpp                            | 1 +
 .../sql_functions/string_functions/test_string_function_regexp.out  | 6 ++++++
 .../string_functions/test_string_function_regexp.groovy             | 1 +
 3 files changed, 8 insertions(+)

diff --git a/be/src/vec/functions/function_regexp.cpp b/be/src/vec/functions/function_regexp.cpp
index 31ad61cc187..8cd5b64c71a 100644
--- a/be/src/vec/functions/function_regexp.cpp
+++ b/be/src/vec/functions/function_regexp.cpp
@@ -361,6 +361,7 @@ struct RegexpExtractAllImpl {
         }
 
         if (res_matches.empty()) {
+            StringOP::push_empty_string(index_now, result_data, result_offset);
             return;
         }
 
diff --git a/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_regexp.out b/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_regexp.out
index 1684a03a152..133076ec13b 100644
--- a/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_regexp.out
+++ b/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_regexp.out
@@ -67,6 +67,12 @@ d
 -- !sql --
 ['ab','c','c','c']
 
+-- !sql_regexp_extract_all --
+	0
+	0
+	0
+	0
+
 -- !sql --
 a-b-c
 
diff --git a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_regexp.groovy b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_regexp.groovy
index e3e04a5456f..59414f5c1b7 100644
--- a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_regexp.groovy
+++ b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_regexp.groovy
@@ -58,6 +58,7 @@ suite("test_string_function_regexp") {
     qt_sql "select regexp_extract_all('xxfs','f');"
     qt_sql "select regexp_extract_all('asdfg', '(z|x|c|)');"
     qt_sql "select regexp_extract_all('abcdfesscca', '(ab|c|)');"
+    qt_sql_regexp_extract_all "select regexp_extract_all('', '\"([^\"]+)\":'), length(regexp_extract_all('', '\"([^\"]+)\":')) from test_string_function_regexp;"
 
     qt_sql "SELECT regexp_replace('a b c', \" \", \"-\");"
     qt_sql "SELECT regexp_replace('a b c','(b)','<\\\\1>');"


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


[doris] 04/10: [fix](rpc) Rebuild failed channel to avoid connection refused (#25688)

Posted by kx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 10d9625a8eb3ecb2f61293dff029c411539ae4af
Author: walter <pa...@foxmail.com>
AuthorDate: Mon Oct 23 11:32:24 2023 +0800

    [fix](rpc) Rebuild failed channel to avoid connection refused (#25688)
---
 .../org/apache/doris/rpc/BackendServiceClient.java    |  9 +++++++++
 .../org/apache/doris/rpc/BackendServiceProxy.java     | 19 +++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/rpc/BackendServiceClient.java b/fe/fe-core/src/main/java/org/apache/doris/rpc/BackendServiceClient.java
index 8df33927fd1..e4ece51146b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/rpc/BackendServiceClient.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/rpc/BackendServiceClient.java
@@ -27,6 +27,7 @@ import io.grpc.CallOptions;
 import io.grpc.Channel;
 import io.grpc.ClientCall;
 import io.grpc.ClientInterceptor;
+import io.grpc.ConnectivityState;
 import io.grpc.ForwardingClientCall;
 import io.grpc.ManagedChannel;
 import io.grpc.Metadata;
@@ -64,6 +65,14 @@ public class BackendServiceClient {
         execPlanTimeout = Config.remote_fragment_exec_timeout_ms + 5000;
     }
 
+    // Is the underlying channel in a normal state? (That means the RPC call will not fail immediately)
+    public boolean isNormalState() {
+        ConnectivityState state = channel.getState(false);
+        return state == ConnectivityState.CONNECTING
+            || state == ConnectivityState.IDLE
+            || state == ConnectivityState.READY;
+    }
+
     public Future<InternalService.PExecPlanFragmentResult> execPlanFragmentAsync(
             InternalService.PExecPlanFragmentRequest request) {
         return stub.withDeadlineAfter(execPlanTimeout, TimeUnit.MILLISECONDS)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/rpc/BackendServiceProxy.java b/fe/fe-core/src/main/java/org/apache/doris/rpc/BackendServiceProxy.java
index 5fc3ef2815c..9b5c491df69 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/rpc/BackendServiceProxy.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/rpc/BackendServiceProxy.java
@@ -109,18 +109,30 @@ public class BackendServiceProxy {
     private BackendServiceClient getProxy(TNetworkAddress address) throws UnknownHostException {
         String realIp = NetUtils.getIpByHost(address.getHostname());
         BackendServiceClientExtIp serviceClientExtIp = serviceMap.get(address);
-        if (serviceClientExtIp != null && serviceClientExtIp.realIp.equals(realIp)) {
+        if (serviceClientExtIp != null && serviceClientExtIp.realIp.equals(realIp)
+                && serviceClientExtIp.client.isNormalState()) {
             return serviceClientExtIp.client;
         }
+
         // not exist, create one and return.
+        BackendServiceClient removedClient = null;
         lock.lock();
         try {
             serviceClientExtIp = serviceMap.get(address);
             if (serviceClientExtIp != null && !serviceClientExtIp.realIp.equals(realIp)) {
                 LOG.warn("Cached ip changed ,before ip: {}, curIp: {}", serviceClientExtIp.realIp, realIp);
                 serviceMap.remove(address);
+                removedClient = serviceClientExtIp.client;
+                serviceClientExtIp = null;
+            }
+            if (serviceClientExtIp != null && !serviceClientExtIp.client.isNormalState()) {
+                // At this point we cannot judge the progress of reconnecting the underlying channel.
+                // In the worst case, it may take two minutes. But we can't stand the connection refused
+                // for two minutes, so rebuild the channel directly.
+                serviceMap.remove(address);
+                removedClient = serviceClientExtIp.client;
+                serviceClientExtIp = null;
             }
-            serviceClientExtIp = serviceMap.get(address);
             if (serviceClientExtIp == null) {
                 BackendServiceClient client = new BackendServiceClient(address, grpcThreadPool);
                 serviceMap.put(address, new BackendServiceClientExtIp(realIp, client));
@@ -128,6 +140,9 @@ public class BackendServiceProxy {
             return serviceMap.get(address).client;
         } finally {
             lock.unlock();
+            if (removedClient != null) {
+                removedClient.shutdown();
+            }
         }
     }
 


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


[doris] 02/10: [build](extension) Update build-extension.yml (#25721)

Posted by kx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 847eb11d3ceb565cb60c49a2d682ef8afb766150
Author: Jeffrey <co...@gmail.com>
AuthorDate: Sat Oct 21 16:52:55 2023 +0800

    [build](extension) Update build-extension.yml (#25721)
---
 .github/workflows/build-extension.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.github/workflows/build-extension.yml b/.github/workflows/build-extension.yml
index 4a9fc5d38ef..d58e21a75dc 100644
--- a/.github/workflows/build-extension.yml
+++ b/.github/workflows/build-extension.yml
@@ -100,6 +100,7 @@ jobs:
         run: |
           git clone https://github.com/apache/doris-website.git website
           cd website
+          echo "[\"current\"]" > versions.json 
           mkdir -p docs
           cp -R ../docs/en/docs/* docs/
           cp -R ../docs/sidebars.json sidebars.json


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


[doris] 06/10: [Fix](partial update) Fix wrong comment in .proto file (#25742)

Posted by kx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit fe97a17025c9368e43fdf48808aa55365fc6c44e
Author: bobhan1 <bh...@outlook.com>
AuthorDate: Mon Oct 23 14:39:54 2023 +0800

    [Fix](partial update) Fix wrong comment in .proto file (#25742)
    
    1. remove deprecated comment on fields that is wrongly added in #25147. These fields will be used when coordinator BE send infos to executor BEs. They will only be used during RPC and will not be persisted.
    2. eliminate some unnecessary copys.
---
 gensrc/proto/descriptors.proto | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gensrc/proto/descriptors.proto b/gensrc/proto/descriptors.proto
index 97c2e6d9935..65a001e0ba0 100644
--- a/gensrc/proto/descriptors.proto
+++ b/gensrc/proto/descriptors.proto
@@ -63,7 +63,7 @@ message POlapTableSchemaParam {
     repeated PSlotDescriptor slot_descs = 4;
     required PTupleDescriptor tuple_desc = 5;
     repeated POlapTableIndexSchema indexes = 6;
-    optional bool partial_update = 7;
+    optional bool partial_update = 7 [default = false];
     repeated string partial_update_input_columns = 8;
     optional bool is_strict_mode = 9 [default = false];
 };


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


[doris] 10/10: [Fix](exec) Fix date dict dead loop. (#25570)

Posted by kx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 48c962e77381846ab874c36c1fa08002301a5987
Author: Qi Chen <ka...@gmail.com>
AuthorDate: Tue Oct 24 02:51:43 2023 +0800

    [Fix](exec) Fix date dict dead loop. (#25570)
---
 be/src/vec/exec/format/orc/vorc_reader.cpp   |   2 +-
 be/src/vec/exec/format/orc/vorc_reader.h     |   2 +-
 be/src/vec/exec/format/parquet/decoder.cpp   |   2 +-
 be/src/vec/exec/format/parquet/decoder.h     |   2 +-
 be/src/vec/runtime/vdatetime_value.cpp       |  26 +++--
 be/src/vec/runtime/vdatetime_value.h         |  18 +--
 be/test/vec/runtime/vdatetime_value_test.cpp | 168 +++++++++++++++++++++++++++
 7 files changed, 200 insertions(+), 20 deletions(-)

diff --git a/be/src/vec/exec/format/orc/vorc_reader.cpp b/be/src/vec/exec/format/orc/vorc_reader.cpp
index c88ea70dfa7..b7399300b63 100644
--- a/be/src/vec/exec/format/orc/vorc_reader.cpp
+++ b/be/src/vec/exec/format/orc/vorc_reader.cpp
@@ -150,7 +150,7 @@ OrcReader::OrcReader(RuntimeProfile* profile, RuntimeState* state,
     TimezoneUtils::find_cctz_time_zone(ctz, _time_zone);
     VecDateTimeValue t;
     t.from_unixtime(0, ctz);
-    _offset_days = t.day() == 31 ? 0 : 1;
+    _offset_days = t.day() == 31 ? -1 : 0; // If 1969-12-31, then returns -1.
     _init_profile();
     _init_system_properties();
     _init_file_description();
diff --git a/be/src/vec/exec/format/orc/vorc_reader.h b/be/src/vec/exec/format/orc/vorc_reader.h
index e14c93244ee..0d9fb3df29d 100644
--- a/be/src/vec/exec/format/orc/vorc_reader.h
+++ b/be/src/vec/exec/format/orc/vorc_reader.h
@@ -503,7 +503,7 @@ private:
     int64_t _range_size;
     const std::string& _ctz;
     const std::vector<std::string>* _column_names;
-    size_t _offset_days = 0;
+    int32_t _offset_days = 0;
     cctz::time_zone _time_zone;
 
     std::list<std::string> _read_cols;
diff --git a/be/src/vec/exec/format/parquet/decoder.cpp b/be/src/vec/exec/format/parquet/decoder.cpp
index bf8ef0b2330..0a158176091 100644
--- a/be/src/vec/exec/format/parquet/decoder.cpp
+++ b/be/src/vec/exec/format/parquet/decoder.cpp
@@ -181,7 +181,7 @@ void Decoder::init(FieldSchema* field_schema, cctz::time_zone* ctz) {
     if (_decode_params->ctz) {
         VecDateTimeValue t;
         t.from_unixtime(0, *_decode_params->ctz);
-        _decode_params->offset_days = t.day() == 31 ? 0 : 1;
+        _decode_params->offset_days = t.day() == 31 ? -1 : 0; // If 1969-12-31, then returns -1.
     }
 }
 } // namespace doris::vectorized
diff --git a/be/src/vec/exec/format/parquet/decoder.h b/be/src/vec/exec/format/parquet/decoder.h
index 6c1030818cd..acd9965bad8 100644
--- a/be/src/vec/exec/format/parquet/decoder.h
+++ b/be/src/vec/exec/format/parquet/decoder.h
@@ -71,7 +71,7 @@ struct DecodeParams {
     static const cctz::time_zone utc0;
     // schema.logicalType.TIMESTAMP.isAdjustedToUTC == true, we should set the time zone
     cctz::time_zone* ctz = nullptr;
-    size_t offset_days = 0;
+    int32_t offset_days = 0;
     int64_t second_mask = 1;
     int64_t scale_to_nano_factor = 1;
     DecimalScaleParams decimal_scale;
diff --git a/be/src/vec/runtime/vdatetime_value.cpp b/be/src/vec/runtime/vdatetime_value.cpp
index 10fe6a9a721..e04382532ff 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -2665,10 +2665,10 @@ template <typename T>
 typename DateV2Value<T>::underlying_value DateV2Value<T>::to_date_int_val() const {
     return int_val_;
 }
-
+// [1900-01-01, 2039-12-31]
 static std::array<DateV2Value<DateV2ValueType>, date_day_offset_dict::DICT_DAYS>
         DATE_DAY_OFFSET_ITEMS;
-
+// [1900-01-01, 2039-12-31]
 static std::array<std::array<std::array<int, 31>, 12>, 140> DATE_DAY_OFFSET_DICT;
 
 static bool DATE_DAY_OFFSET_ITEMS_INIT = false;
@@ -2685,19 +2685,27 @@ bool date_day_offset_dict::get_dict_init() {
 
 date_day_offset_dict::date_day_offset_dict() {
     DateV2Value<DateV2ValueType> d;
+    // Init days before epoch.
     d.set_time(1969, 12, 31, 0, 0, 0, 0);
-    for (int i = 0; i < DAY_AFTER_EPOCH; ++i) {
-        DATE_DAY_OFFSET_ITEMS[DAY_BEFORE_EPOCH + i] = d;
+    for (int i = 0; i < DAY_BEFORE_EPOCH; ++i) {
+        DATE_DAY_OFFSET_ITEMS[DAY_BEFORE_EPOCH - i - 1] = d;
         DATE_DAY_OFFSET_DICT[d.year() - START_YEAR][d.month() - 1][d.day() - 1] =
                 calc_daynr(d.year(), d.month(), d.day());
-        d += 1;
+        d -= 1;
     }
-    d.set_time(1969, 12, 31, 0, 0, 0, 0);
-    for (int i = 0; i <= DAY_BEFORE_EPOCH; ++i) {
-        DATE_DAY_OFFSET_ITEMS[DAY_BEFORE_EPOCH - i] = d;
+    // Init epoch day.
+    d.set_time(1970, 1, 1, 0, 0, 0, 0);
+    DATE_DAY_OFFSET_ITEMS[DAY_BEFORE_EPOCH] = d;
+    DATE_DAY_OFFSET_DICT[d.year() - START_YEAR][d.month() - 1][d.day() - 1] =
+            calc_daynr(d.year(), d.month(), d.day());
+    d += 1;
+
+    // Init days after epoch.
+    for (int i = 0; i < DAY_AFTER_EPOCH; ++i) {
+        DATE_DAY_OFFSET_ITEMS[DAY_BEFORE_EPOCH + 1 + i] = d;
         DATE_DAY_OFFSET_DICT[d.year() - START_YEAR][d.month() - 1][d.day() - 1] =
                 calc_daynr(d.year(), d.month(), d.day());
-        d -= 1;
+        d += 1;
     }
 
     DATE_DAY_OFFSET_ITEMS_INIT = true;
diff --git a/be/src/vec/runtime/vdatetime_value.h b/be/src/vec/runtime/vdatetime_value.h
index 1f96d5e9e35..c1d2c5bbadd 100644
--- a/be/src/vec/runtime/vdatetime_value.h
+++ b/be/src/vec/runtime/vdatetime_value.h
@@ -1516,6 +1516,9 @@ class DataTypeDateTime;
 class DataTypeDateV2;
 class DataTypeDateTimeV2;
 
+/**
+ * Date dict table. date range is [1900-01-01, 2039-12-31].
+ */
 class date_day_offset_dict {
 private:
     static date_day_offset_dict instance;
@@ -1526,15 +1529,16 @@ private:
     date_day_offset_dict& operator=(const date_day_offset_dict&) = default;
 
 public:
-    static constexpr int DAY_BEFORE_EPOCH = 25566; // 1900-01-01
-    static constexpr int DAY_AFTER_EPOCH = 25500;  // 2039-10-24
-    static constexpr int DICT_DAYS = DAY_BEFORE_EPOCH + DAY_AFTER_EPOCH;
+    static constexpr int DAY_BEFORE_EPOCH = 25567;                           // 1900-01-01
+    static constexpr int DAY_AFTER_EPOCH = 25566;                            // 2039-12-31
+    static constexpr int DICT_DAYS = DAY_BEFORE_EPOCH + 1 + DAY_AFTER_EPOCH; // 1 means 1970-01-01
 
-    static constexpr int START_YEAR = 1900;                         // 1900-01-01
-    static constexpr int END_YEAR = 2039;                           // 2039-10-24
-    static constexpr int DAY_OFFSET_CAL_START_POINT_DAYNR = 719527; // 1969-12-31
+    static constexpr int START_YEAR = 1900; // 1900-01-01
+    static constexpr int END_YEAR = 2039;   // 2039-10-24
+    static constexpr int DAY_OFFSET_CAL_START_POINT_DAYNR =
+            719528; // 1970-01-01 (start from 0000-01-01, 0000-01-01 is day 1, returns 1)
 
-    static bool can_speed_up_calc_daynr(int year) { return year >= START_YEAR && year < END_YEAR; }
+    static bool can_speed_up_calc_daynr(int year) { return year >= START_YEAR && year <= END_YEAR; }
 
     static int get_offset_by_daynr(int daynr) { return daynr - DAY_OFFSET_CAL_START_POINT_DAYNR; }
 
diff --git a/be/test/vec/runtime/vdatetime_value_test.cpp b/be/test/vec/runtime/vdatetime_value_test.cpp
index 05943dcc6c3..bb396b2ce6f 100644
--- a/be/test/vec/runtime/vdatetime_value_test.cpp
+++ b/be/test/vec/runtime/vdatetime_value_test.cpp
@@ -570,4 +570,172 @@ TEST(VDateTimeValueTest, date_v2_to_string_test) {
     }
 }
 
+TEST(VDateTimeValueTest, date_v2_daynr_test) {
+    {
+        DateV2Value<DateV2ValueType> date_v2;
+        // 1970/01/01
+        EXPECT_TRUE(date_v2.get_date_from_daynr(719528));
+        EXPECT_TRUE(date_v2.year() == 1970);
+        EXPECT_TRUE(date_v2.month() == 1);
+        EXPECT_TRUE(date_v2.day() == 1);
+        EXPECT_TRUE(date_v2.hour() == 0);
+        EXPECT_TRUE(date_v2.minute() == 0);
+        EXPECT_TRUE(date_v2.second() == 0);
+        EXPECT_TRUE(date_v2.microsecond() == 0);
+        EXPECT_TRUE(doris::calc_daynr(1970, 1, 1) == 719528);
+        EXPECT_TRUE(date_day_offset_dict::get().get_dict_init());
+        EXPECT_TRUE(date_day_offset_dict::get().can_speed_up_calc_daynr(1970));
+        EXPECT_TRUE(date_day_offset_dict::get().can_speed_up_daynr_to_date(719528));
+    }
+
+    {
+        DateV2Value<DateV2ValueType> date_v2;
+        // 1969/12/31
+        EXPECT_TRUE(date_v2.get_date_from_daynr(719527));
+        EXPECT_TRUE(date_v2.year() == 1969);
+        EXPECT_TRUE(date_v2.month() == 12);
+        EXPECT_TRUE(date_v2.day() == 31);
+        EXPECT_TRUE(date_v2.hour() == 0);
+        EXPECT_TRUE(date_v2.minute() == 0);
+        EXPECT_TRUE(date_v2.second() == 0);
+        EXPECT_TRUE(date_v2.microsecond() == 0);
+        EXPECT_TRUE(doris::calc_daynr(1969, 12, 31) == 719527);
+        EXPECT_TRUE(date_day_offset_dict::get().get_dict_init());
+        EXPECT_TRUE(date_day_offset_dict::get().can_speed_up_calc_daynr(1969));
+        EXPECT_TRUE(date_day_offset_dict::get().can_speed_up_daynr_to_date(719527));
+    }
+
+    {
+        DateV2Value<DateV2ValueType> date_v2;
+        // 1900/01/01
+        EXPECT_TRUE(date_v2.get_date_from_daynr(693961));
+        EXPECT_TRUE(date_v2.year() == 1900);
+        EXPECT_TRUE(date_v2.month() == 1);
+        EXPECT_TRUE(date_v2.day() == 1);
+        EXPECT_TRUE(date_v2.hour() == 0);
+        EXPECT_TRUE(date_v2.minute() == 0);
+        EXPECT_TRUE(date_v2.second() == 0);
+        EXPECT_TRUE(date_v2.microsecond() == 0);
+        EXPECT_TRUE(doris::calc_daynr(1900, 1, 1) == 693961);
+        EXPECT_TRUE(date_day_offset_dict::get().get_dict_init());
+        EXPECT_TRUE(date_day_offset_dict::get().can_speed_up_calc_daynr(1900));
+        EXPECT_TRUE(date_day_offset_dict::get().can_speed_up_daynr_to_date(693961));
+    }
+
+    {
+        DateV2Value<DateV2ValueType> date_v2;
+        // 1899/12/31
+        EXPECT_TRUE(date_v2.get_date_from_daynr(693960));
+        EXPECT_TRUE(date_v2.year() == 1899);
+        EXPECT_TRUE(date_v2.month() == 12);
+        EXPECT_TRUE(date_v2.day() == 31);
+        EXPECT_TRUE(date_v2.hour() == 0);
+        EXPECT_TRUE(date_v2.minute() == 0);
+        EXPECT_TRUE(date_v2.second() == 0);
+        EXPECT_TRUE(date_v2.microsecond() == 0);
+        EXPECT_TRUE(doris::calc_daynr(1899, 12, 31) == 693960);
+        EXPECT_TRUE(date_day_offset_dict::get().get_dict_init());
+        EXPECT_FALSE(date_day_offset_dict::get().can_speed_up_calc_daynr(1899));
+        EXPECT_FALSE(date_day_offset_dict::get().can_speed_up_daynr_to_date(693960));
+    }
+
+    {
+        DateV2Value<DateV2ValueType> date_v2;
+        // 2039/12/31
+        EXPECT_TRUE(date_v2.get_date_from_daynr(745094));
+        EXPECT_TRUE(date_v2.year() == 2039);
+        EXPECT_TRUE(date_v2.month() == 12);
+        EXPECT_TRUE(date_v2.day() == 31);
+        EXPECT_TRUE(date_v2.hour() == 0);
+        EXPECT_TRUE(date_v2.minute() == 0);
+        EXPECT_TRUE(date_v2.second() == 0);
+        EXPECT_TRUE(date_v2.microsecond() == 0);
+        EXPECT_TRUE(doris::calc_daynr(2039, 12, 31) == 745094);
+        EXPECT_TRUE(date_day_offset_dict::get().get_dict_init());
+        EXPECT_TRUE(date_day_offset_dict::get().can_speed_up_calc_daynr(2039));
+        EXPECT_TRUE(date_day_offset_dict::get().can_speed_up_daynr_to_date(745094));
+    }
+
+    {
+        DateV2Value<DateV2ValueType> date_v2;
+        // 2040/01/01
+        EXPECT_TRUE(date_v2.get_date_from_daynr(745095));
+        EXPECT_TRUE(date_v2.year() == 2040);
+        EXPECT_TRUE(date_v2.month() == 1);
+        EXPECT_TRUE(date_v2.day() == 1);
+        EXPECT_TRUE(date_v2.hour() == 0);
+        EXPECT_TRUE(date_v2.minute() == 0);
+        EXPECT_TRUE(date_v2.second() == 0);
+        EXPECT_TRUE(date_v2.microsecond() == 0);
+        EXPECT_TRUE(doris::calc_daynr(2040, 01, 01) == 745095);
+        EXPECT_TRUE(date_day_offset_dict::get().get_dict_init());
+        EXPECT_FALSE(date_day_offset_dict::get().can_speed_up_calc_daynr(2040));
+        EXPECT_FALSE(date_day_offset_dict::get().can_speed_up_daynr_to_date(745095));
+    }
+
+    {
+        DateV2Value<DateV2ValueType> date_v2;
+        // 0000/01/01
+        EXPECT_TRUE(date_v2.get_date_from_daynr(1));
+        EXPECT_TRUE(date_v2.year() == 0);
+        EXPECT_TRUE(date_v2.month() == 1);
+        EXPECT_TRUE(date_v2.day() == 1);
+        EXPECT_TRUE(date_v2.hour() == 0);
+        EXPECT_TRUE(date_v2.minute() == 0);
+        EXPECT_TRUE(date_v2.second() == 0);
+        EXPECT_TRUE(date_v2.microsecond() == 0);
+        EXPECT_TRUE(doris::calc_daynr(0, 01, 01) == 1);
+        EXPECT_TRUE(date_day_offset_dict::get().get_dict_init());
+        EXPECT_FALSE(date_day_offset_dict::get().can_speed_up_calc_daynr(0));
+        EXPECT_FALSE(date_day_offset_dict::get().can_speed_up_daynr_to_date(1));
+    }
+
+    {
+        DateV2Value<DateV2ValueType> date_v2;
+        // Invalid date 0000/00/01
+        EXPECT_TRUE(date_v2.year() == 0);
+        EXPECT_TRUE(date_v2.month() == 0);
+        EXPECT_TRUE(date_v2.day() == 0);
+        EXPECT_TRUE(date_v2.hour() == 0);
+        EXPECT_TRUE(date_v2.minute() == 0);
+        EXPECT_TRUE(date_v2.second() == 0);
+        EXPECT_TRUE(date_v2.microsecond() == 0);
+        EXPECT_TRUE(doris::calc_daynr(0, 0, 1) == 0);
+    }
+
+    {
+        DateV2Value<DateV2ValueType> date_v2;
+        // 9999/12/31
+        EXPECT_TRUE(date_v2.get_date_from_daynr(3652424));
+        EXPECT_TRUE(date_v2.year() == 9999);
+        EXPECT_TRUE(date_v2.month() == 12);
+        EXPECT_TRUE(date_v2.day() == 31);
+        EXPECT_TRUE(date_v2.hour() == 0);
+        EXPECT_TRUE(date_v2.minute() == 0);
+        EXPECT_TRUE(date_v2.second() == 0);
+        EXPECT_TRUE(date_v2.microsecond() == 0);
+        EXPECT_TRUE(doris::calc_daynr(9999, 12, 31) == 3652424);
+        EXPECT_TRUE(date_day_offset_dict::get().get_dict_init());
+        EXPECT_FALSE(date_day_offset_dict::get().can_speed_up_calc_daynr(9999));
+        EXPECT_FALSE(date_day_offset_dict::get().can_speed_up_daynr_to_date(3652424));
+    }
+
+    {
+        DateV2Value<DateV2ValueType> date_v2;
+        // Invalid date 10000/01/01
+        EXPECT_FALSE(date_v2.get_date_from_daynr(3652425));
+        EXPECT_TRUE(date_v2.year() == 0);
+        EXPECT_TRUE(date_v2.month() == 0);
+        EXPECT_TRUE(date_v2.day() == 0);
+        EXPECT_TRUE(date_v2.hour() == 0);
+        EXPECT_TRUE(date_v2.minute() == 0);
+        EXPECT_TRUE(date_v2.second() == 0);
+        EXPECT_TRUE(date_v2.microsecond() == 0);
+        EXPECT_TRUE(doris::calc_daynr(10000, 01, 01) == 3652425);
+        EXPECT_TRUE(date_day_offset_dict::get().get_dict_init());
+        EXPECT_FALSE(date_day_offset_dict::get().can_speed_up_calc_daynr(10000));
+        EXPECT_FALSE(date_day_offset_dict::get().can_speed_up_daynr_to_date(3652425));
+    }
+}
+
 } // namespace doris::vectorized


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


[doris] 05/10: [regresstion-test](jdbc catalog)Mariadb compatible test (#25664)

Posted by kx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit ccb7e3779cbf68d418bfe9effb3fd3372028b108
Author: Petrichor <31...@users.noreply.github.com>
AuthorDate: Sun Oct 22 22:51:03 2023 -0500

    [regresstion-test](jdbc catalog)Mariadb compatible test (#25664)
---
 .../docker-compose/mariadb/init/01-drop-db.sql     |  18 ++++
 .../docker-compose/mariadb/init/02-create-db.sql   |  18 ++++
 .../mariadb/init/03-create-table.sql               |  76 +++++++++++++
 .../docker-compose/mariadb/init/04-insert.sql      |  36 +++++++
 .../docker-compose/mariadb/mariadb-10.env          |  19 ++++
 .../docker-compose/mariadb/mariadb-10.yaml.tpl     |  49 +++++++++
 docker/thirdparties/run-thirdparties-docker.sh     |  26 ++++-
 regression-test/conf/regression-conf.groovy        |   1 +
 .../jdbc/test_mariadb_jdbc_catalog.out             | 117 +++++++++++++++++++++
 .../pipeline/p0/conf/regression-conf.groovy        |   2 +-
 .../jdbc/test_mariadb_jdbc_catalog.groovy          |  82 +++++++++++++++
 11 files changed, 439 insertions(+), 5 deletions(-)

diff --git a/docker/thirdparties/docker-compose/mariadb/init/01-drop-db.sql b/docker/thirdparties/docker-compose/mariadb/init/01-drop-db.sql
new file mode 100644
index 00000000000..d0db4a7e1ac
--- /dev/null
+++ b/docker/thirdparties/docker-compose/mariadb/init/01-drop-db.sql
@@ -0,0 +1,18 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--   http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+drop database if exists doris_test;
diff --git a/docker/thirdparties/docker-compose/mariadb/init/02-create-db.sql b/docker/thirdparties/docker-compose/mariadb/init/02-create-db.sql
new file mode 100644
index 00000000000..f87b6922d9f
--- /dev/null
+++ b/docker/thirdparties/docker-compose/mariadb/init/02-create-db.sql
@@ -0,0 +1,18 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--   http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+create database doris_test;
diff --git a/docker/thirdparties/docker-compose/mariadb/init/03-create-table.sql b/docker/thirdparties/docker-compose/mariadb/init/03-create-table.sql
new file mode 100644
index 00000000000..e82da905dca
--- /dev/null
+++ b/docker/thirdparties/docker-compose/mariadb/init/03-create-table.sql
@@ -0,0 +1,76 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--   http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+CREATE TABLE doris_test.ex_tb0
+(
+    `id`   int PRIMARY KEY,
+    `name` varchar(128)
+);
+
+create table doris_test.all_types (
+  `tinyint_u` tinyint unsigned,
+  `smallint_u` smallint unsigned,
+  `mediumint_u` mediumint unsigned,
+  `int_u` int unsigned,
+  `bigint_u` bigint unsigned,
+  `decimal_u` decimal(18, 5) unsigned,
+  `double_u` double unsigned,
+  `float_u` float unsigned,
+  `boolean` boolean,
+  `tinyint` tinyint,
+  `smallint` smallint,
+  `year` year,
+  `mediumint` mediumint,
+  `int` int,
+  `bigint` bigint,
+  `date` date,
+  `timestamp` timestamp(4) null,
+  `datetime` datetime,
+  `float` float,
+  `double` double,
+  `decimal` decimal(12, 4),
+  `char` char(5),
+  `varchar` varchar(10),
+  `time` time(4),
+  `text` text,
+  `blob` blob,
+  `json` json,
+  `set` set('Option1', 'Option2', 'Option3'),
+  `bit` bit(6),
+  `binary` binary(12),
+  `varbinary` varbinary(12),
+  `enum` enum('Value1', 'Value2', 'Value3')
+) engine=innodb charset=utf8;
+
+CREATE TABLE `doris_test`.`auto_default_t` (
+    `id` bigint NOT NULL AUTO_INCREMENT,
+    `name` varchar(64) DEFAULT NULL,
+    `dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+    PRIMARY KEY (`id`)
+) engine=innodb charset=utf8;
+
+CREATE TABLE doris_test.dt (
+  `timestamp0` timestamp(0) DEFAULT CURRENT_TIMESTAMP(),
+  `timestamp1` timestamp(0) DEFAULT CURRENT_TIMESTAMP(0),
+  `timestamp2` timestamp(1) DEFAULT CURRENT_TIMESTAMP(1),
+  `timestamp3` timestamp(2) DEFAULT CURRENT_TIMESTAMP(2),
+  `timestamp4` timestamp(3) DEFAULT CURRENT_TIMESTAMP(3),
+  `timestamp5` timestamp(4) DEFAULT CURRENT_TIMESTAMP(4),
+  `timestamp6` timestamp(5) DEFAULT CURRENT_TIMESTAMP(5),
+  `timestamp7` timestamp(6) DEFAULT CURRENT_TIMESTAMP(6)
+) ENGINE=INNODB CHARSET=utf8;
+
diff --git a/docker/thirdparties/docker-compose/mariadb/init/04-insert.sql b/docker/thirdparties/docker-compose/mariadb/init/04-insert.sql
new file mode 100644
index 00000000000..5856e419e7c
--- /dev/null
+++ b/docker/thirdparties/docker-compose/mariadb/init/04-insert.sql
@@ -0,0 +1,36 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--   http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+insert into doris_test.ex_tb0 values (111, 'abc'), (112, 'abd'), (113, 'abe'),(114, 'abf'),(115, 'abg');
+
+INSERT INTO doris_test.all_types VALUES
+(201, 301, 401, 501, 601, 3.14159, 4.1415926, 5.141592, true, -123, -301, 2012, -401, -501, -601, '2012-10-30', '2012-10-25 12:05:36.3456712', '2012-10-25 08:08:08.3456712',
+ -4.14145001, -5.1400000001, -6.140000001, 'row1', 'line1', '09:09:09.56782346', 'text1', X'48656C6C6F20576F726C64', '{"name": "Alice", "age": 30, "city": "London"}',
+ 'Option1,Option3', b'101010', X'48656C6C6F', X'48656C6C6F', 'Value2'),
+(202, 302, 402, 502, 602, 4.14159, 5.1415926, 6.141592, false, -124, -302, 2013, -402, -502, -602, '2012-11-01', '2012-10-26 02:08:39.3456712', '2013-10-26 08:09:18.3456712',
+ -5.14145001, -6.1400000001, -7.140000001, 'row2', 'line2', '09:11:09.56782346', 'text2', X'E86F6C6C6F20576F726C67', '{"name": "Gaoxin", "age": 18, "city": "ChongQing"}',
+ 'Option1,Option2', b'101111', X'58676C6C6F', X'88656C6C9F', 'Value3'),
+(null, 302, null, 502, 602, 4.14159, null, 6.141592, null, -124, -302, 2013, -402, -502, -602, null, '2012-10-26 02:08:39.3456712', '2013-10-26 08:09:18.3456712',
+ -5.14145001, null, -7.140000001, 'row2', null, '09:11:09.56782346', 'text2', X'E86F6C6C6F20576F726C67', null,
+ null, b'101111', null, X'88656C6C9F', 'Value3'),
+(203, 303, 403, 503, 603, 7.14159, 8.1415926, 9.141592, false, null, -402, 2017, -602, -902, -1102, '2012-11-02', null, '2013-10-27 08:11:18.3456712',
+ -5.14145000001, -6.1400000000001, -7.140000000001, 'row3', 'line3', '09:11:09.56782346', 'text3', X'E86F6C6C6F20576F726C67', '{"name": "ChenQi", "age": 24, "city": "ChongQing"}',
+ 'Option2', b'101111', X'58676C6C6F', null, 'Value1');
+
+INSERT INTO doris_test.dt (`timestamp0`, `timestamp1`, `timestamp2`, `timestamp3`, `timestamp4`, `timestamp5`, `timestamp6`,`timestamp7`)
+VALUES ('2023-06-17 10:00:00', '2023-06-17 10:00:01.1', '2023-06-17 10:00:02.22', '2023-06-17 10:00:03.333', 
+        '2023-06-17 10:00:04.4444', '2023-06-17 10:00:05.55555', '2023-06-17 10:00:06.666666','2023-06-17 10:00:06.666666');
+
diff --git a/docker/thirdparties/docker-compose/mariadb/mariadb-10.env b/docker/thirdparties/docker-compose/mariadb/mariadb-10.env
new file mode 100644
index 00000000000..a8537d46f81
--- /dev/null
+++ b/docker/thirdparties/docker-compose/mariadb/mariadb-10.env
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+DOCKER_MARIADB_EXTERNAL_PORT=3326
diff --git a/docker/thirdparties/docker-compose/mariadb/mariadb-10.yaml.tpl b/docker/thirdparties/docker-compose/mariadb/mariadb-10.yaml.tpl
new file mode 100644
index 00000000000..ad3f3109549
--- /dev/null
+++ b/docker/thirdparties/docker-compose/mariadb/mariadb-10.yaml.tpl
@@ -0,0 +1,49 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+version: "3.1"
+
+services:
+  doris--mariadb:
+    image: mariadb:10.4
+    command: --default-authentication-plugin=mysql_native_password
+    restart: always
+    environment:
+      MARIADB_ROOT_PASSWORD: 123456
+      MARIADBL_DATABASE: init_db
+      # set terminal charset
+      LANG: C.UTF-8
+    ports:
+      - ${DOCKER_MARIADB_EXTERNAL_PORT}:3306
+    healthcheck:
+      test: mysqladmin ping -h 127.0.0.1 -u root --password=$$MARIADB_ROOT_PASSWORD
+      interval: 5s
+      timeout: 60s
+      retries: 120
+    volumes:
+      - ./data/:/var/lib/mysql
+      - ./init:/docker-entrypoint-initdb.d
+    networks:
+      - doris--mariadb
+  hello-world:
+    image: hello-world
+    depends_on:
+      doris--mariadb:
+        condition: service_healthy 
+
+networks:
+  doris--mariadb:
diff --git a/docker/thirdparties/run-thirdparties-docker.sh b/docker/thirdparties/run-thirdparties-docker.sh
index d1065fa4dd9..bf2cc1de744 100755
--- a/docker/thirdparties/run-thirdparties-docker.sh
+++ b/docker/thirdparties/run-thirdparties-docker.sh
@@ -37,7 +37,7 @@ Usage: $0 <options>
      --stop             stop the specified components
 
   All valid components:
-    mysql,pg,oracle,sqlserver,clickhouse,es,hive,iceberg,kafka,hudi,trino
+    mysql,pg,oracle,sqlserver,clickhouse,es,hive,iceberg,hudi,trino,kafka,mariadb
   "
     exit 1
 }
@@ -60,7 +60,7 @@ STOP=0
 
 if [[ "$#" == 1 ]]; then
     # default
-    COMPONENTS="mysql,es,hive,pg,oracle,sqlserver,clickhouse"
+    COMPONENTS="mysql,es,hive,pg,oracle,sqlserver,clickhouse,mariadb"
 else
     while true; do
         case "$1" in
@@ -92,7 +92,7 @@ else
     done
     if [[ "${COMPONENTS}"x == ""x ]]; then
         if [[ "${STOP}" -eq 1 ]]; then
-            COMPONENTS="mysql,pg,oracle,sqlserver,clickhouse,hive,iceberg,kafka,hudi,trino"
+            COMPONENTS="mysql,es,pg,oracle,sqlserver,clickhouse,hive,iceberg,hudi,trino,kafka,mariadb"
         fi
     fi
 fi
@@ -128,9 +128,11 @@ RUN_CLICKHOUSE=0
 RUN_HIVE=0
 RUN_ES=0
 RUN_ICEBERG=0
-RUN_KAFKA=0
 RUN_HUDI=0
 RUN_TRINO=0
+RUN_KAFKA=0
+RUN_SPARK=0
+RUN_MARIADB=0
 
 for element in "${COMPONENTS_ARR[@]}"; do
     if [[ "${element}"x == "mysql"x ]]; then
@@ -155,6 +157,10 @@ for element in "${COMPONENTS_ARR[@]}"; do
         RUN_HUDI=1
     elif [[ "${element}"x == "trino"x ]];then
         RUN_TRINO=1
+    elif [[ "${element}"x == "spark"x ]];then
+        RUN_SPARK=1
+    elif [[ "${element}"x == "mariadb"x ]];then
+        RUN_MARIADB=1
     else
         echo "Invalid component: ${element}"
         usage
@@ -422,3 +428,15 @@ if  [[ "${RUN_TRINO}" -eq 1 ]]; then
         docker exec -it ${TRINO_CONTAINER_ID} /bin/bash -c 'trino -f /scripts/create_trino_table.sql'
     fi
 fi
+
+if [[ "${RUN_MARIADB}" -eq 1 ]]; then
+    # mariadb
+    cp "${ROOT}"/docker-compose/mariadb/mariadb-10.yaml.tpl "${ROOT}"/docker-compose/mariadb/mariadb-10.yaml
+    sed -i "s/doris--/${CONTAINER_UID}/g" "${ROOT}"/docker-compose/mariadb/mariadb-10.yaml
+    sudo docker compose -f "${ROOT}"/docker-compose/mariadb/mariadb-10.yaml --env-file "${ROOT}"/docker-compose/mariadb/mariadb-10.env down
+    if [[ "${STOP}" -ne 1 ]]; then
+        sudo mkdir -p "${ROOT}"/docker-compose/mariadb/data/
+        sudo rm "${ROOT}"/docker-compose/mariadb/data/* -rf
+        sudo docker compose -f "${ROOT}"/docker-compose/mariadb/mariadb-10.yaml --env-file "${ROOT}"/docker-compose/mariadb/mariadb-10.env up -d
+    fi
+fi
diff --git a/regression-test/conf/regression-conf.groovy b/regression-test/conf/regression-conf.groovy
index d6001476392..a7cb35fdf4f 100644
--- a/regression-test/conf/regression-conf.groovy
+++ b/regression-test/conf/regression-conf.groovy
@@ -93,6 +93,7 @@ oracle_11_port=1521
 sqlserver_2022_port=1433
 clickhouse_22_port=8123
 doris_port=9030
+mariadb_10_port=3326
 
 // hive catalog test config
 // To enable hive/paimon test, you need first start hive container.
diff --git a/regression-test/data/external_table_p0/jdbc/test_mariadb_jdbc_catalog.out b/regression-test/data/external_table_p0/jdbc/test_mariadb_jdbc_catalog.out
new file mode 100644
index 00000000000..f6641395575
--- /dev/null
+++ b/regression-test/data/external_table_p0/jdbc/test_mariadb_jdbc_catalog.out
@@ -0,0 +1,117 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !sql --
+internal
+
+-- !sql --
+internal
+
+-- !sql --
+mariadb_jdbc_catalog
+
+-- !ex_tb0 --
+111	abc
+112	abd
+113	abe
+114	abf
+115	abg
+
+-- !in_tb --
+111	abc
+112	abd
+113	abe
+114	abf
+115	abg
+
+-- !information_schema --
+ALL_PLUGINS
+APPLICABLE_ROLES
+CHARACTER_SETS
+CHECK_CONSTRAINTS
+CLIENT_STATISTICS
+COLLATIONS
+COLLATION_CHARACTER_SET_APPLICABILITY
+COLUMNS
+COLUMN_PRIVILEGES
+ENABLED_ROLES
+ENGINES
+EVENTS
+FILES
+GEOMETRY_COLUMNS
+GLOBAL_STATUS
+GLOBAL_VARIABLES
+INDEX_STATISTICS
+INNODB_BUFFER_PAGE
+INNODB_BUFFER_PAGE_LRU
+INNODB_BUFFER_POOL_STATS
+INNODB_CMP
+INNODB_CMPMEM
+INNODB_CMPMEM_RESET
+INNODB_CMP_PER_INDEX
+INNODB_CMP_PER_INDEX_RESET
+INNODB_CMP_RESET
+INNODB_FT_BEING_DELETED
+INNODB_FT_CONFIG
+INNODB_FT_DEFAULT_STOPWORD
+INNODB_FT_DELETED
+INNODB_FT_INDEX_CACHE
+INNODB_FT_INDEX_TABLE
+INNODB_LOCKS
+INNODB_LOCK_WAITS
+INNODB_METRICS
+INNODB_MUTEXES
+INNODB_SYS_COLUMNS
+INNODB_SYS_DATAFILES
+INNODB_SYS_FIELDS
+INNODB_SYS_FOREIGN
+INNODB_SYS_FOREIGN_COLS
+INNODB_SYS_INDEXES
+INNODB_SYS_SEMAPHORE_WAITS
+INNODB_SYS_TABLES
+INNODB_SYS_TABLESPACES
+INNODB_SYS_TABLESTATS
+INNODB_SYS_VIRTUAL
+INNODB_TABLESPACES_ENCRYPTION
+INNODB_TABLESPACES_SCRUBBING
+INNODB_TRX
+KEYWORDS
+KEY_CACHES
+KEY_COLUMN_USAGE
+OPTIMIZER_TRACE
+PARAMETERS
+PARTITIONS
+PLUGINS
+PROCESSLIST
+PROFILING
+REFERENTIAL_CONSTRAINTS
+ROUTINES
+SCHEMATA
+SCHEMA_PRIVILEGES
+SESSION_STATUS
+SESSION_VARIABLES
+SPATIAL_REF_SYS
+SQL_FUNCTIONS
+STATISTICS
+SYSTEM_VARIABLES
+TABLES
+TABLESPACES
+TABLE_CONSTRAINTS
+TABLE_PRIVILEGES
+TABLE_STATISTICS
+TRIGGERS
+USER_PRIVILEGES
+USER_STATISTICS
+VIEWS
+user_variables
+
+-- !auto_default_t --
+0
+
+-- !dt --
+2023-06-17T10:00	2023-06-17T10:00:01	2023-06-17T10:00:02.200	2023-06-17T10:00:03.330	2023-06-17T10:00:04.444	2023-06-17T10:00:05.555500	2023-06-17T10:00:06.666660	2023-06-17T10:00:06.666666
+
+-- !mysql_all_types --
+\N	302	\N	502	602	4.14159	\N	6.14159	\N	-124	-302	2013	-402	-502	-602	\N	2012-10-26T02:08:39.345600	2013-10-26T08:09:18	-5.14145	\N	-7.1400	row2	\N	09:11:09.567	text2	0xE86F6C6C6F20576F726C67	\N	\N	0x2F	\N	0x88656C6C9F	Value3
+201	301	401	501	601	3.14159	4.1415926	5.14159	1	-123	-301	2012	-401	-501	-601	2012-10-30	2012-10-25T12:05:36.345600	2012-10-25T08:08:08	-4.14145	-5.1400000001	-6.1400	row1	line1	09:09:09.567	text1	0x48656C6C6F20576F726C64	{"name": "Alice", "age": 30, "city": "London"}	Option1,Option3	0x2A	0x48656C6C6F00000000000000	0x48656C6C6F	Value2
+202	302	402	502	602	4.14159	5.1415926	6.14159	0	-124	-302	2013	-402	-502	-602	2012-11-01	2012-10-26T02:08:39.345600	2013-10-26T08:09:18	-5.14145	-6.1400000001	-7.1400	row2	line2	09:11:09.567	text2	0xE86F6C6C6F20576F726C67	{"name": "Gaoxin", "age": 18, "city": "ChongQing"}	Option1,Option2	0x2F	0x58676C6C6F00000000000000	0x88656C6C9F	Value3
+203	303	403	503	603	7.14159	8.1415926	9.14159	0	\N	-402	2017	-602	-902	-1102	2012-11-02	\N	2013-10-27T08:11:18	-5.14145	-6.1400000000001	-7.1400	row3	line3	09:11:09.567	text3	0xE86F6C6C6F20576F726C67	{"name": "ChenQi", "age": 24, "city": "ChongQing"}	Option2	0x2F	0x58676C6C6F00000000000000	\N	Value1
+
diff --git a/regression-test/pipeline/p0/conf/regression-conf.groovy b/regression-test/pipeline/p0/conf/regression-conf.groovy
index 890b67a0739..d4a02176993 100644
--- a/regression-test/pipeline/p0/conf/regression-conf.groovy
+++ b/regression-test/pipeline/p0/conf/regression-conf.groovy
@@ -77,7 +77,7 @@ enableBrokerLoad=true
 enableJdbcTest=false
 mysql_57_port=7111
 pg_14_port=7121
-
+mariadb_10_port=3326
 // hive catalog test config
 // To enable jdbc test, you need first start hive container.
 // See `docker/thirdparties/start-thirdparties-docker.sh`
diff --git a/regression-test/suites/external_table_p0/jdbc/test_mariadb_jdbc_catalog.groovy b/regression-test/suites/external_table_p0/jdbc/test_mariadb_jdbc_catalog.groovy
new file mode 100644
index 00000000000..5398263b73d
--- /dev/null
+++ b/regression-test/suites/external_table_p0/jdbc/test_mariadb_jdbc_catalog.groovy
@@ -0,0 +1,82 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_mariadb_jdbc_catalog", "p0,external,mariadb,external_docker,external_docker_mariadb") {
+    qt_sql """select current_catalog()"""
+
+    String enabled = context.config.otherConfigs.get("enableJdbcTest")
+    String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
+    String s3_endpoint = getS3Endpoint()
+    String bucket = getS3BucketName()
+    String driver_url = "https://${bucket}.${s3_endpoint}/regression/jdbc_driver/mysql-connector-java-8.0.25.jar"
+    if (enabled != null && enabled.equalsIgnoreCase("true")) {
+        String catalog_name = "mariadb_jdbc_catalog";
+        String internal_db_name = "regression_test_jdbc_catalog_p0";
+        String ex_db_name = "doris_test";
+        String mariadb_port = context.config.otherConfigs.get("mariadb_10_port");
+        String inDorisTable = "test_mariadb_jdbc_doris_in_tb";
+        String ex_tb0 = "ex_tb0";
+        String test_insert = "test_insert";
+        String test_insert2 = "test_insert2";
+        String auto_default_t = "auto_default_t";
+        String dt = "dt";
+
+        sql """create database if not exists ${internal_db_name}; """
+
+        sql """drop catalog if exists ${catalog_name} """
+
+        sql """create catalog if not exists ${catalog_name} properties(
+            "type"="jdbc",
+            "user"="root",
+            "password"="123456",
+            "jdbc_url" = "jdbc:mysql://${externalEnvIp}:${mariadb_port}/doris_test?useSSL=false&zeroDateTimeBehavior=convertToNull",
+            "driver_url" = "${driver_url}",
+            "driver_class" = "com.mysql.cj.jdbc.Driver"
+        );"""
+
+        sql """use ${internal_db_name}"""
+        sql  """ drop table if exists ${internal_db_name}.${inDorisTable} """
+        sql  """
+              CREATE TABLE ${internal_db_name}.${inDorisTable} (
+                `id` INT NULL COMMENT "主键id",
+                `name` string NULL COMMENT "名字"
+                ) DISTRIBUTED BY HASH(id) BUCKETS 10
+                PROPERTIES("replication_num" = "1");
+        """
+
+        qt_sql """select current_catalog()"""
+        sql """switch ${catalog_name}"""
+        qt_sql """select current_catalog()"""
+        sql """ use ${ex_db_name}"""
+
+        order_qt_ex_tb0  """ select id, name from ${ex_tb0} order by id; """
+        sql  """ insert into internal.${internal_db_name}.${inDorisTable} select id, name from ${ex_tb0}; """
+        order_qt_in_tb  """ select id, name from internal.${internal_db_name}.${inDorisTable} order by id; """
+
+        order_qt_information_schema """ show tables from information_schema; """
+        order_qt_auto_default_t """insert into ${auto_default_t}(name) values('a'); """
+        order_qt_dt """select * from ${dt}; """
+
+        // test all types supported by Mariadb
+        sql """use doris_test;"""
+        qt_mysql_all_types """select * from all_types order by tinyint_u;"""
+
+        sql """ drop catalog if exists ${catalog_name} """
+
+    }
+}
+


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


[doris] 01/10: [fix](datetime) fix unstable str_to_date function result (#25707)

Posted by kx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 9ed12250f5fb63d85187da7e183da6a7aeacbb4f
Author: zclllyybb <zh...@selectdb.com>
AuthorDate: Mon Oct 23 11:52:08 2023 +0800

    [fix](datetime) fix unstable str_to_date function result (#25707)
    
    fix unstable str_to_date function result
---
 be/src/vec/functions/function_timestamp.cpp           | 16 ++++++++++++----
 be/test/vec/function/function_string_test.cpp         | 19 -------------------
 be/test/vec/function/function_time_test.cpp           | 17 -----------------
 .../java/org/apache/doris/analysis/DateLiteral.java   | 19 +++++++++++++++----
 .../org/apache/doris/analysis/FunctionCallExpr.java   |  6 +++---
 .../trees/expressions/functions/scalar/StrToDate.java |  7 +++++--
 .../java/org/apache/doris/rewrite/FEFunctions.java    |  2 +-
 .../datetime_functions/test_date_function.out         |  4 ++--
 8 files changed, 38 insertions(+), 52 deletions(-)

diff --git a/be/src/vec/functions/function_timestamp.cpp b/be/src/vec/functions/function_timestamp.cpp
index 84f1df086f4..48ceb6cbb4f 100644
--- a/be/src/vec/functions/function_timestamp.cpp
+++ b/be/src/vec/functions/function_timestamp.cpp
@@ -63,16 +63,22 @@
 
 namespace doris::vectorized {
 
+template <typename DateType>
 struct StrToDate {
     static constexpr auto name = "str_to_date";
 
     static bool is_variadic() { return false; }
 
-    static DataTypes get_variadic_argument_types() { return {}; }
+    static DataTypes get_variadic_argument_types() {
+        return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>()};
+    }
 
     static DataTypePtr get_return_type_impl(const DataTypes& arguments) {
-        //TODO: it doesn't matter now. maybe sometime we should find the function signature with return_type together
-        return make_nullable(std::make_shared<DataTypeDateTime>());
+        if constexpr (IsDateType<DateType> || IsDateV2Type<DateType>) {
+            return make_nullable(std::make_shared<DataTypeDateV2>());
+        }
+        //datetimev2
+        return make_nullable(std::make_shared<DataTypeDateTimeV2>(6));
     }
 
     static StringRef rewrite_specific_format(const char* raw_str, size_t str_size) {
@@ -1270,7 +1276,8 @@ public:
     }
 };
 
-using FunctionStrToDate = FunctionOtherTypesToDateType<StrToDate>;
+using FunctionStrToDate = FunctionOtherTypesToDateType<StrToDate<DataTypeDateV2>>;
+using FunctionStrToDatetime = FunctionOtherTypesToDateType<StrToDate<DataTypeDateTimeV2>>;
 using FunctionMakeDate = FunctionOtherTypesToDateType<MakeDateImpl>;
 using FunctionDateTrunc = FunctionOtherTypesToDateType<DateTrunc<VecDateTimeValue, Int64>>;
 using FunctionDateTruncV2 =
@@ -1278,6 +1285,7 @@ using FunctionDateTruncV2 =
 
 void register_function_timestamp(SimpleFunctionFactory& factory) {
     factory.register_function<FunctionStrToDate>();
+    factory.register_function<FunctionStrToDatetime>();
     factory.register_function<FunctionMakeDate>();
     factory.register_function<FromDays>();
     factory.register_function<FunctionDateTrunc>();
diff --git a/be/test/vec/function/function_string_test.cpp b/be/test/vec/function/function_string_test.cpp
index b7ceecd4e0d..48647d7e2d1 100644
--- a/be/test/vec/function/function_string_test.cpp
+++ b/be/test/vec/function/function_string_test.cpp
@@ -1121,25 +1121,6 @@ TEST(function_string_test, function_coalesce_test) {
     }
 }
 
-TEST(function_string_test, function_str_to_date_test) {
-    std::string func_name = "str_to_date";
-    InputTypeSet input_types = {
-            TypeIndex::String,
-            TypeIndex::String,
-    };
-    DataSet data_set = {
-            {{Null(), std::string("%Y-%m-%d %H:%i:%s")}, {Null()}},
-            {{std::string("2014-12-21 12:34:56"), std::string("%Y-%m-%d %H:%i:%s")},
-             str_to_date_time("2014-12-21 12:34:56", false)},
-            {{std::string("2014-12-21 12:34%3A56"), std::string("%Y-%m-%d %H:%i%%3A%s")},
-             str_to_date_time("2014-12-21 12:34:56", false)},
-            {{std::string("11/09/2011"), std::string("%m/%d/%Y")},
-             str_to_date_time("2011-11-09", false)},
-            {{std::string("2020-09-01"), std::string("%Y-%m-%d %H:%i:%s")},
-             str_to_date_time("2020-09-01 00:00:00", false)}};
-    check_function<DataTypeDateTime, true>(func_name, input_types, data_set);
-}
-
 TEST(function_string_test, function_replace) {
     std::string func_name = "replace";
     InputTypeSet input_types = {
diff --git a/be/test/vec/function/function_time_test.cpp b/be/test/vec/function/function_time_test.cpp
index d87fab8b7b4..05600067d73 100644
--- a/be/test/vec/function/function_time_test.cpp
+++ b/be/test/vec/function/function_time_test.cpp
@@ -1379,23 +1379,6 @@ TEST(VTimestampFunctionsTest, yearweek_v2_test) {
     }
 }
 
-TEST(VTimestampFunctionsTest, str_to_date_test) {
-    std::string func_name = "str_to_date";
-
-    InputTypeSet input_types = {TypeIndex::String, TypeIndex::String};
-
-    {
-        DataSet data_set = {{{std::string("2021-01-01"), std::string("%Y-%m-%d")},
-                             str_to_date_time("2021-01-01", false)},
-                            {{std::string("2022-01-03"), std::string("%Y-%m-%d")},
-                             str_to_date_time("2022-01-03", false)},
-                            {{std::string("2021-00-01"), std::string("%Y-%m-%d")}, Null()},
-                            {{std::string("2021-01-00"), std::string("%Y-%m-%d")}, Null()}};
-
-        check_function<DataTypeDate, true>(func_name, input_types, data_set);
-    }
-}
-
 TEST(VTimestampFunctionsTest, from_days_test) {
     std::string func_name = "from_days";
 
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
index 0948353377e..336fd314e0e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
@@ -1276,9 +1276,20 @@ public class DateLiteral extends LiteralExpr {
                         break;
                     // Micro second
                     case 'f':
-                        tmp = vp + Math.min(6, vend - vp);
-                        intValue = strToLong(value.substring(vp, tmp));
-                        this.microsecond = (long) (intValue * Math.pow(10, 6 - Math.min(6, vend - vp)));
+                        // FIXME: fix same with BE
+                        tmp = vp;
+                        // when there's still something to the end, fix the scale of ms.
+                        while (tmp < vend && Character.isDigit(value.charAt(tmp))) {
+                            tmp += 1;
+                        }
+
+                        if (tmp - vp > 6) {
+                            int tmp2 = vp + 6;
+                            intValue = strToLong(value.substring(vp, tmp2));
+                        } else {
+                            intValue = strToLong(value.substring(vp, tmp));
+                        }
+                        this.microsecond = (long) (intValue * Math.pow(10, 6 - Math.min(6, tmp - vp)));
                         timePartUsed = true;
                         microSecondPartUsed = true;
                         vp = tmp;
@@ -1476,7 +1487,7 @@ public class DateLiteral extends LiteralExpr {
         //  we think it's stable enough
         if (datePartUsed) {
             if (microSecondPartUsed) {
-                this.type = Type.DATETIMEV2;
+                this.type = Type.DATETIMEV2_WITH_MAX_SCALAR;
             } else if (timePartUsed) {
                 this.type = ScalarType.getDefaultDateType(Type.DATETIME);
             } else {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
index c3e0bd84381..e4cb2c2ef2f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
@@ -1893,12 +1893,12 @@ public class FunctionCallExpr extends Expr {
             Expr child1Result = getChild(1).getResultValue(false);
             if (child1Result instanceof StringLiteral) {
                 if (DateLiteral.hasTimePart(child1Result.getStringValue())) {
-                    this.type = Type.DATETIME;
+                    this.type = Type.DATETIMEV2_WITH_MAX_SCALAR;
                 } else {
-                    this.type = Type.DATE;
+                    this.type = Type.DATEV2;
                 }
             } else {
-                this.type = Type.DATETIME;
+                this.type = Type.DATETIMEV2_WITH_MAX_SCALAR;
             }
         } else if (TIME_FUNCTIONS_WITH_PRECISION.contains(fnName.getFunction().toLowerCase())
                 && fn.getReturnType().isDatetimeV2()) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java
index 4f512ec09fe..1fbf15586d5 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java
@@ -44,9 +44,9 @@ public class StrToDate extends ScalarFunction
         implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable {
 
     public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
-            FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(VarcharType.SYSTEM_DEFAULT,
+            FunctionSignature.ret(DateTimeV2Type.MAX).args(VarcharType.SYSTEM_DEFAULT,
                     VarcharType.SYSTEM_DEFAULT),
-            FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(StringType.INSTANCE, StringType.INSTANCE)
+            FunctionSignature.ret(DateTimeV2Type.MAX).args(StringType.INSTANCE, StringType.INSTANCE)
     );
 
     /**
@@ -95,6 +95,9 @@ public class StrToDate extends ScalarFunction
             }
         } else {
             returnType = DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATETIME));
+            if (returnType.isDateTimeV2Type()) {
+                returnType = DataType.fromCatalogType(Type.DATETIMEV2_WITH_MAX_SCALAR);
+            }
         }
         return signature.withReturnType(returnType);
     }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java
index bce2dd7dfac..a65ca6edb67 100755
--- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java
@@ -150,7 +150,7 @@ public class FEFunctions {
         return new StringLiteral(result);
     }
 
-    @FEFunction(name = "str_to_date", argTypes = { "VARCHAR", "VARCHAR" }, returnType = "DATETIME")
+    @FEFunction(name = "str_to_date", argTypes = { "VARCHAR", "VARCHAR" }, returnType = "DATETIMEV2")
     public static DateLiteral dateParse(StringLiteral date, StringLiteral fmtLiteral) throws AnalysisException {
         DateLiteral dateLiteral = new DateLiteral();
         try {
diff --git a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
index 5c61bfc31d2..9858f809ea0 100644
--- a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
+++ b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
@@ -273,10 +273,10 @@ February
 2014-12-21T12:34:56
 
 -- !sql --
-2014-12-21T12:34:56
+2014-12-21T12:34:56.789
 
 -- !sql --
-2023-07-05T02:09:55
+2023-07-05T02:09:55.880
 
 -- !sql --
 2004-10-18


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


[doris] 09/10: [fix](prefetch-read) make prefetch range correct to accelerate S3 load and fix its speed unbalance (#25775)

Posted by kx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit b58f1a68c7c4ca6c43cd54a46cdd88656e35580e
Author: Siyang Tang <82...@users.noreply.github.com>
AuthorDate: Mon Oct 23 20:02:24 2023 +0800

    [fix](prefetch-read) make prefetch range correct to accelerate S3 load and fix its speed unbalance  (#25775)
---
 be/src/vec/exec/format/csv/csv_reader.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/be/src/vec/exec/format/csv/csv_reader.cpp b/be/src/vec/exec/format/csv/csv_reader.cpp
index 70a691f5d66..46bb5540e4b 100644
--- a/be/src/vec/exec/format/csv/csv_reader.cpp
+++ b/be/src/vec/exec/format/csv/csv_reader.cpp
@@ -304,7 +304,7 @@ Status CsvReader::init_reader(bool is_load) {
         RETURN_IF_ERROR(io::DelegateReader::create_file_reader(
                 _profile, _system_properties, _file_description, reader_options, &_file_system,
                 &_file_reader, io::DelegateReader::AccessMode::SEQUENTIAL, _io_ctx,
-                io::PrefetchRange(_range.start_offset, _range.size)));
+                io::PrefetchRange(_range.start_offset, _range.start_offset + _range.size)));
     }
     if (_file_reader->size() == 0 && _params.file_type != TFileType::FILE_STREAM &&
         _params.file_type != TFileType::FILE_BROKER) {


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


[doris] 03/10: [Fix](segment) need to rebuild col_id_to_predicates when true predicates encountered (#25685)

Posted by kx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit dd2cc616c179725d78e149ca0befb63a04cd2b2b
Author: airborne12 <ai...@gmail.com>
AuthorDate: Mon Oct 23 10:26:52 2023 +0800

    [Fix](segment) need to rebuild col_id_to_predicates when true predicates encountered (#25685)
---
 be/src/olap/rowset/segment_v2/segment.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/be/src/olap/rowset/segment_v2/segment.cpp b/be/src/olap/rowset/segment_v2/segment.cpp
index 0f41844434b..791c666d307 100644
--- a/be/src/olap/rowset/segment_v2/segment.cpp
+++ b/be/src/olap/rowset/segment_v2/segment.cpp
@@ -190,6 +190,18 @@ Status Segment::new_iterator(SchemaSPtr schema, const StorageReadOptions& read_o
         if (pruned) {
             auto options_with_pruned_predicates = read_options;
             options_with_pruned_predicates.column_predicates = pruned_predicates;
+            //because column_predicates is changed, we need to rebuild col_id_to_predicates so that inverted index will not go through it.
+            options_with_pruned_predicates.col_id_to_predicates.clear();
+            for (auto* pred : options_with_pruned_predicates.column_predicates) {
+                if (!options_with_pruned_predicates.col_id_to_predicates.contains(
+                            pred->column_id())) {
+                    options_with_pruned_predicates.col_id_to_predicates.insert(
+                            {pred->column_id(), std::make_shared<AndBlockColumnPredicate>()});
+                }
+                auto* single_column_block_predicate = new SingleColumnBlockPredicate(pred);
+                options_with_pruned_predicates.col_id_to_predicates[pred->column_id()]
+                        ->add_column_predicate(single_column_block_predicate);
+            }
             LOG(INFO) << "column_predicates pruned from " << read_options.column_predicates.size()
                       << " to " << pruned_predicates.size();
             return iter->get()->init(options_with_pruned_predicates);


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