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

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


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new fefc8a8efbe branch-2.1: [fix](new_json_reader)fix new_json_reader core 
(#43188)
fefc8a8efbe is described below

commit fefc8a8efbef69a69a3de26c2ce2cfea6ab68e03
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sat Nov 9 12:33:34 2024 +0800

    branch-2.1: [fix](new_json_reader)fix new_json_reader core (#43188)
    
    Cherry-picked from #41290
    
    Co-authored-by: amory <wangqian...@selectdb.com>
---
 be/src/vec/exec/format/json/new_json_reader.cpp    |  5 ++
 .../test_json_reader_without_object.groovy         | 57 ++++++++++++++++++++++
 2 files changed, 62 insertions(+)

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 40dc6dda5f9..0850f5c0286 100644
--- a/be/src/vec/exec/format/json/new_json_reader.cpp
+++ b/be/src/vec/exec/format/json/new_json_reader.cpp
@@ -331,6 +331,11 @@ Status 
NewJsonReader::get_parsed_schema(std::vector<std::string>* col_names,
         objectValue = _json_doc;
     }
 
+    if (!objectValue->IsObject()) {
+        return Status::DataQualityError("JSON data is not an object. but: {}",
+                                        objectValue->GetType());
+    }
+
     // use jsonpaths to col_names
     if (!_parsed_jsonpaths.empty()) {
         for (auto& _parsed_jsonpath : _parsed_jsonpaths) {
diff --git 
a/regression-test/suites/jsonb_p0/test_json_reader_without_object.groovy 
b/regression-test/suites/jsonb_p0/test_json_reader_without_object.groovy
new file mode 100644
index 00000000000..ea1ccb3ba55
--- /dev/null
+++ b/regression-test/suites/jsonb_p0/test_json_reader_without_object.groovy
@@ -0,0 +1,57 @@
+// 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.
+
+import org.codehaus.groovy.runtime.IOGroovyMethods
+
+suite("test_json_reader_without_object", "p0") {
+    String ak = getS3AK()
+    String sk = getS3SK()
+    String s3_endpoint = getS3Endpoint()
+    String bucket = context.config.otherConfigs.get("s3BucketName");
+
+    sql """ set enable_nereids_timeout=false; """
+    sql """ set max_scan_key_num = 48 """
+    sql """ set max_pushdown_conditions_per_column=1024 """
+
+    def dataFilePath = 
"https://"+"${bucket}"+"."+"${s3_endpoint}"+"/regression/jsondata";
+    def dataSimpleNumber = "json_reader_without_object.json"
+    def dataSimpleArray = "json_reader_without_object_array.json"
+
+    // select expect error
+    test {
+        sql """ select * from s3(
+                                "uri" = "${dataFilePath}/${dataSimpleNumber}",
+                                    "s3.access_key"= "${ak}",
+                                    "s3.secret_key" = "${sk}",
+                                    "format" = "json",
+                                    "provider" = "${getS3Provider()}",
+                                    "read_json_by_line"="true"); """
+        exception "DATA_QUALITY_ERROR"
+    }
+
+    test {
+        sql """ select * from s3(
+                                "uri" = "${dataFilePath}/${dataSimpleArray}",
+                                    "s3.access_key"= "${ak}",
+                                    "s3.secret_key" = "${sk}",
+                                    "format" = "json",
+                                    "provider" = "${getS3Provider()}",
+                                    "strip_outer_array" = "true",
+                                    "read_json_by_line"="true"); """
+        exception "DATA_QUALITY_ERROR"
+    }
+}


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

Reply via email to