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

yiguolei 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 3024b82918 [fix](load)Fix wrong default value for char and varchar of 
reading json data (#22626)
3024b82918 is described below

commit 3024b829186c808445255c4caaa130396c8b22fd
Author: Xujian Duan <[email protected]>
AuthorDate: Sat Aug 5 12:47:27 2023 +0800

    [fix](load)Fix wrong default value for char and varchar of reading json 
data (#22626)
    
    If a column is defined as: col VARCHAR/CHAR NULL and no default value. Then 
we load json data which misses column col, the result queried is not correct:
    +------+
    | col |
    +------+
    | 1 |
    +------+
    But expect:
    +------+
    | col |
    +------+
    | NULL |
    +------+
    
    ---------
    
    Co-authored-by: duanxujian <[email protected]>
---
 be/src/vec/exec/format/json/new_json_reader.cpp    |  4 +++
 .../stream_load/test_json_load_default_value.out   | 40 +++++++++++-----------
 .../test_json_load_default_value.groovy            | 11 +++---
 3 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/be/src/vec/exec/format/json/new_json_reader.cpp 
b/be/src/vec/exec/format/json/new_json_reader.cpp
index d10f60f5e9..c7991166b8 100644
--- a/be/src/vec/exec/format/json/new_json_reader.cpp
+++ b/be/src/vec/exec/format/json/new_json_reader.cpp
@@ -1722,6 +1722,10 @@ Status NewJsonReader::_get_column_default_value(
         auto it = col_default_value_ctx.find(slot_desc->col_name());
         if (it != col_default_value_ctx.end() && it->second != nullptr) {
             auto& ctx = it->second;
+            // NULL_LITERAL means no valid value of current column
+            if (ctx->root()->node_type() == TExprNodeType::type::NULL_LITERAL) 
{
+                continue;
+            }
             // empty block to save default value of slot_desc->col_name()
             Block block;
             // If block is empty, some functions will produce no result. So we 
insert a column with
diff --git 
a/regression-test/data/load_p0/stream_load/test_json_load_default_value.out 
b/regression-test/data/load_p0/stream_load/test_json_load_default_value.out
index ade4b09896..c3a604ef59 100644
--- a/regression-test/data/load_p0/stream_load/test_json_load_default_value.out
+++ b/regression-test/data/load_p0/stream_load/test_json_load_default_value.out
@@ -1,30 +1,30 @@
 -- This file is automatically generated. You should know what you did if you 
want to edit this
 -- !select1 --
-1      default_country beijing 2345671
-2      default_country shanghai        2345672
-3      default_country guangzhou       2345673
-4      default_country shenzhen        2345674
-5      default_country hangzhou        2345675
-6      default_country nanjing 2345676
-7      default_country wuhan   2345677
-8      default_country chengdu 2345678
-9      default_country xian    2345679
-10     default_country hefei   23456710
+1      default_country beijing 2345671 \N      \N      \N
+2      default_country shanghai        2345672 \N      \N      \N
+3      default_country guangzhou       2345673 \N      \N      \N
+4      default_country shenzhen        2345674 \N      \N      \N
+5      default_country hangzhou        2345675 \N      \N      \N
+6      default_country nanjing 2345676 \N      \N      \N
+7      default_country wuhan   2345677 \N      \N      \N
+8      default_country chengdu 2345678 \N      \N      \N
+9      default_country xian    2345679 \N      \N      \N
+10     default_country hefei   23456710        \N      \N      \N
 
 -- !select2 --
 10
 
 -- !select3 --
-1      default_country default_city    2345671
-2      default_country shanghai        2345672
-3      default_country beijing 2345673
-4      default_country shenzhen        2345674
-5      default_country hangzhou        2345675
-6      default_country nanjing 2345676
-7      default_country default_city    2345677
-8      default_country chengdu 2345678
-9      default_country default_city    2345679
-10     default_country default_city    23456710
+1      default_country default_city    2345671 \N      \N      \N
+2      default_country shanghai        2345672 \N      \N      \N
+3      default_country beijing 2345673 \N      \N      \N
+4      default_country shenzhen        2345674 \N      \N      \N
+5      default_country hangzhou        2345675 \N      \N      \N
+6      default_country nanjing 2345676 \N      \N      \N
+7      default_country default_city    2345677 \N      \N      \N
+8      default_country chengdu 2345678 \N      \N      \N
+9      default_country default_city    2345679 \N      \N      \N
+10     default_country default_city    23456710        \N      \N      \N
 
 -- !select4 --
 10
diff --git 
a/regression-test/suites/load_p0/stream_load/test_json_load_default_value.groovy
 
b/regression-test/suites/load_p0/stream_load/test_json_load_default_value.groovy
index 221526ad35..979356e597 100644
--- 
a/regression-test/suites/load_p0/stream_load/test_json_load_default_value.groovy
+++ 
b/regression-test/suites/load_p0/stream_load/test_json_load_default_value.groovy
@@ -28,9 +28,12 @@ suite("test_json_load_default_value", "p0") {
                         country VARCHAR(32) NULL DEFAULT 'default_country',
                         city VARCHAR(32) NULL DEFAULT 'default_city',
                         code BIGINT DEFAULT '1111',
-                        date_time DATETIME DEFAULT CURRENT_TIMESTAMP)
+                        date_time DATETIME DEFAULT CURRENT_TIMESTAMP,
+                        flag CHAR,
+                        name VARCHAR(64),
+                        descript STRING)
                         DISTRIBUTED BY RANDOM BUCKETS 10
-                        PROPERTIES("replication_num" = "1");
+                        PROPERTIES("replication_allocation" = 
"tag.location.default: 1");
                         """
         
         // DDL/DML return 1 row and 3 column, the only value is update row 
count
@@ -58,7 +61,7 @@ suite("test_json_load_default_value", "p0") {
         create_test_table.call(testTable)
         load_json_data.call('true', '', 'json', '', 'simple_json.json')
         sql "sync"
-        qt_select1 "select id, country, city, code from ${testTable} order by 
id"
+        qt_select1 "select id, country, city, code, flag, name, descript from 
${testTable} order by id"
         qt_select2 "select count(1) from ${testTable} where date_time is not 
null"
     } finally {
         try_sql("DROP TABLE IF EXISTS ${testTable}")
@@ -69,7 +72,7 @@ suite("test_json_load_default_value", "p0") {
         create_test_table.call(testTable)
         load_json_data.call('true', '', 'json', '', 
'simple_json2_lack_one_column.json')
         sql "sync"
-        qt_select3 "select id, country, city, code from ${testTable} order by 
id"
+        qt_select3 "select id, country, city, code, flag, name, descript from 
${testTable} order by id"
         qt_select4 "select count(1) from ${testTable} where date_time is not 
null"
     } finally {
         try_sql("DROP TABLE IF EXISTS ${testTable}")


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

Reply via email to