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 2023/02/08 16:32:31 UTC
[doris] 03/12: [bugfix](array) fix element revert on error in DataTypeArray::from_string (#16434)
This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git
commit f94f14ef6219be8ae0b688742ef9c49ba3cf24f7
Author: Kang <kx...@gmail.com>
AuthorDate: Mon Feb 6 18:27:36 2023 +0800
[bugfix](array) fix element revert on error in DataTypeArray::from_string (#16434)
* fix array from_string element revert on error
* add testcase
---
be/src/vec/data_types/data_type_array.cpp | 6 +-
.../load/insert/test_array_insert_into_select.out | 13 +++++
.../insert/test_array_insert_into_select.groovy | 65 ++++++++++++++++++++++
3 files changed, 82 insertions(+), 2 deletions(-)
diff --git a/be/src/vec/data_types/data_type_array.cpp b/be/src/vec/data_types/data_type_array.cpp
index 6827cb3779..97af5ac720 100644
--- a/be/src/vec/data_types/data_type_array.cpp
+++ b/be/src/vec/data_types/data_type_array.cpp
@@ -267,6 +267,8 @@ Status DataTypeArray::from_string(ReadBuffer& rb, IColumn* column) const {
StringRef element(rb.position(), rb.count());
bool has_quota = false;
if (!next_element_from_string(rb, element, has_quota)) {
+ // we should do array element column revert if error
+ nested_column.pop_back(element_num);
return Status::InvalidArgument("Cannot read array element from text '{}'",
element.to_string());
}
@@ -294,8 +296,8 @@ Status DataTypeArray::from_string(ReadBuffer& rb, IColumn* column) const {
ReadBuffer read_buffer(const_cast<char*>(element.data), element.size);
auto st = nested->from_string(read_buffer, &nested_column);
if (!st.ok()) {
- // we should do revert if error
- array_column->pop_back(element_num);
+ // we should do array element column revert if error
+ nested_column.pop_back(element_num);
return st;
}
++element_num;
diff --git a/regression-test/data/load/insert/test_array_insert_into_select.out b/regression-test/data/load/insert/test_array_insert_into_select.out
new file mode 100644
index 0000000000..2dcf990314
--- /dev/null
+++ b/regression-test/data/load/insert/test_array_insert_into_select.out
@@ -0,0 +1,13 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !select_string --
+0 [{"a":"1","b":"2","c":"3",}, {"a":"1","b":"2"}]
+1 ['{"a":"1","b":"2","c":"3",}', '{"a":"1","b":"2"}']
+2 [{"a":"1","b":"2"}]
+3 []
+
+-- !select_array --
+0 \N
+1 ['{"a":"1","b":"2","c":"3",}', '{"a":"1","b":"2"}']
+2 \N
+3 []
+
diff --git a/regression-test/suites/load/insert/test_array_insert_into_select.groovy b/regression-test/suites/load/insert/test_array_insert_into_select.groovy
new file mode 100644
index 0000000000..f171ae3220
--- /dev/null
+++ b/regression-test/suites/load/insert/test_array_insert_into_select.groovy
@@ -0,0 +1,65 @@
+// 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_array_insert_into_select", "load") {
+ // create table with string
+ sql "DROP TABLE IF EXISTS tstring"
+ sql """
+ CREATE TABLE `tstring` (
+ `id` INT,
+ `data` STRING
+ ) ENGINE=OLAP
+ DUPLICATE KEY(`id`)
+ COMMENT 'OLAP'
+ DISTRIBUTED BY HASH(`id`) BUCKETS 1
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1");
+ """
+
+ // insert invalid row 0
+ sql """INSERT INTO tstring VALUES (0, '[{"a":"1","b":"2","c":"3",}, {"a":"1","b":"2"}]')"""
+ // insert valid row 1
+ sql """INSERT INTO tstring VALUES (1, '[\\'{"a":"1","b":"2","c":"3",}\\', \\'{"a":"1","b":"2"}\\']')"""
+ // insert invalid row 2
+ sql """INSERT INTO tstring VALUES (2, '[{"a":"1","b":"2"}]')"""
+ // insert valid row 3
+ sql """INSERT INTO tstring VALUES (3, '[]')"""
+
+ // check data in tstring
+ qt_select_string "SELECT * FROM tstring ORDER BY id"
+
+
+ // create table with array
+ sql "DROP TABLE IF EXISTS tarray"
+ sql """
+ CREATE TABLE `tarray` (
+ `id` INT,
+ `data` ARRAY<STRING>
+ ) ENGINE=OLAP
+ DUPLICATE KEY(`id`)
+ COMMENT 'OLAP'
+ DISTRIBUTED BY HASH(`id`) BUCKETS 1
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1");
+ """
+
+ // insert rows to tarray
+ sql "INSERT INTO tarray SELECT * FROM tstring"
+
+ // check data in tarray
+ qt_select_array "SELECT * FROM tarray ORDER BY id"
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org