Copilot commented on code in PR #64281:
URL: https://github.com/apache/doris/pull/64281#discussion_r3378591595
##########
be/src/util/json/json_parser.cpp:
##########
@@ -36,6 +37,29 @@
namespace doris {
+namespace {
+
+constexpr size_t JSON_KEY_ERROR_PREVIEW_BYTES = 128;
+
+std::string json_key_length_error(std::string_view key, size_t max_key_length,
+ std::string_view parent_path = {}) {
+ std::string_view key_preview =
+ key.substr(0, std::min(key.size(), JSON_KEY_ERROR_PREVIEW_BYTES));
+ std::string truncated_suffix;
+ if (key_preview.size() != key.size()) {
+ truncated_suffix = "...";
+ }
+ std::string path_msg;
+ if (!parent_path.empty()) {
+ path_msg = fmt::format(" parent path: '{}'.", parent_path);
+ }
+ return fmt::format(
+ "Key length exceeds maximum allowed size of {} bytes. key length:
{}, key: '{}{}'.{}",
+ max_key_length, key.size(), key_preview, truncated_suffix,
path_msg);
Review Comment:
`json_key_length_error()` will produce a double period when `parent_path` is
non-empty because `path_msg` already ends with "." and the returned format
string also injects an extra "." before `path_msg`. This makes the error
message look like `... parent path: '... '..`.
Consider constructing the suffix so punctuation is only added once.
##########
regression-test/suites/variant_p0/test_variant_stream_load_key_error_url.groovy:
##########
@@ -0,0 +1,64 @@
+// 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_variant_stream_load_key_error_url", "variant_type,p0") {
+ sql "DROP TABLE IF EXISTS test_variant_stream_load_key_error_url"
+ sql """
+ CREATE TABLE test_variant_stream_load_key_error_url (
+ k INT,
+ v VARIANT
+ )
+ DUPLICATE KEY(k)
+ DISTRIBUTED BY HASH(k) BUCKETS 1
+ PROPERTIES("replication_num" = "1");
+ """
+
+ String longKey = "a" * 256
+ File dataFile = new
File("/tmp/test_variant_stream_load_key_error_url.json")
+ dataFile.withWriter { writer ->
+ writer.writeLine('{"k":1,"v":{"short_key":1}}')
+ writer.writeLine("""{"k":2,"v":{"${longKey}":2}}""")
+ }
Review Comment:
This test writes to a fixed filename under `/tmp` and never cleans it up.
That can cause cross-test interference (e.g., parallel runs or reruns) and
leaves artifacts on the test host.
Prefer a unique temp file (and ensure it gets deleted).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]