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/12/01 07:00:21 UTC
[doris] 06/10: [bug](jsonb) fix be core at insert invalid json to JSONB column (#14686)
This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch branch-1.2-unstable
in repository https://gitbox.apache.org/repos/asf/doris.git
commit e2424ff805f34fef351068af2b077415cfbe4892
Author: Kang <kx...@gmail.com>
AuthorDate: Wed Nov 30 14:00:50 2022 +0800
[bug](jsonb) fix be core at insert invalid json to JSONB column (#14686)
---
be/src/runtime/jsonb_value.h | 5 ++-
.../jsonb_p0/test_jsonb_load_and_function.groovy | 43 +++++++++++++++++++++-
2 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/be/src/runtime/jsonb_value.h b/be/src/runtime/jsonb_value.h
index 5e99979a5c..bdb5ba4976 100644
--- a/be/src/runtime/jsonb_value.h
+++ b/be/src/runtime/jsonb_value.h
@@ -35,8 +35,9 @@ namespace doris {
struct JsonBinaryValue {
static const int MAX_LENGTH = (1 << 30);
- const char* ptr;
- size_t len;
+ // default nullprt and size 0 for invalid or NULL value
+ const char* ptr = nullptr;
+ size_t len = 0;
JsonbParser parser;
JsonBinaryValue() : ptr(nullptr), len(0) {}
diff --git a/regression-test/suites/jsonb_p0/test_jsonb_load_and_function.groovy b/regression-test/suites/jsonb_p0/test_jsonb_load_and_function.groovy
index 07e75ee26b..b410251cc4 100644
--- a/regression-test/suites/jsonb_p0/test_jsonb_load_and_function.groovy
+++ b/regression-test/suites/jsonb_p0/test_jsonb_load_and_function.groovy
@@ -88,9 +88,50 @@ suite("test_jsonb_load_and_function", "p0") {
// check result
qt_select "SELECT * FROM ${testTable} ORDER BY id"
- // insert into 1 row and then check result
+ // insert into valid json rows
sql """INSERT INTO ${testTable} VALUES(26, NULL)"""
sql """INSERT INTO ${testTable} VALUES(27, '{"k1":"v1", "k2": 200}')"""
+
+ // insert into invalid json rows with enable_insert_strict=true
+ // expect excepiton and no rows not changed
+ sql """ set enable_insert_strict = true """
+ success = true
+ try {
+ sql """INSERT INTO ${testTable} VALUES(26, '')"""
+ } catch(Exception ex) {
+ logger.info("""INSERT INTO ${testTable} invalid json failed: """ + ex)
+ success = false
+ }
+ assertEquals(false, success)
+ success = true
+ try {
+ sql """INSERT INTO ${testTable} VALUES(26, 'abc')"""
+ } catch(Exception ex) {
+ logger.info("""INSERT INTO ${testTable} invalid json failed: """ + ex)
+ success = false
+ }
+ assertEquals(false, success)
+
+ // insert into invalid json rows with enable_insert_strict=false
+ // expect no excepiton but no rows not changed
+ sql """ set enable_insert_strict = false """
+ success = true
+ try {
+ sql """INSERT INTO ${testTable} VALUES(26, '')"""
+ } catch(Exception ex) {
+ logger.info("""INSERT INTO ${testTable} invalid json failed: """ + ex)
+ success = false
+ }
+ assertEquals(true, success)
+ success = true
+ try {
+ sql """INSERT INTO ${testTable} VALUES(26, 'abc')"""
+ } catch(Exception ex) {
+ logger.info("""INSERT INTO ${testTable} invalid json failed: """ + ex)
+ success = false
+ }
+ assertEquals(true, success)
+
qt_select "SELECT * FROM ${testTable} ORDER BY id"
// jsonb_extract
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org