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

mrhhsg 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 a0685f450d3 [doc](be) Document JSONB path compatibility (#63364)
a0685f450d3 is described below

commit a0685f450d38d16b8f28991964bd06e1e0c579a0
Author: Jerry Hu <[email protected]>
AuthorDate: Wed May 20 11:52:04 2026 +0800

    [doc](be) Document JSONB path compatibility (#63364)
    
    ### What problem does this PR solve?
    
    Related PR: None
    
    Problem Summary: JSONB paths such as `$[1.5]`, `$[Last]`, `$[LAST]`, and
    `$.[0]` are accepted even though they differ from stricter MySQL-style
    path syntax. After evaluation, these forms are treated as existing Doris
    JSONB compatibility behavior/feature because rejecting them would be a
    behavior change and could impact existing users. This PR keeps the
    current behavior and adds comments to document the intentional
    compatibility.
    
    ### Release note
    
    None
    
    ### Check List (For Author)
    
    - Test:
    - No need to test (comment-only compatibility documentation; no runtime
    behavior change)
    - Behavior changed: No
    - Does this need documentation: No
---
 be/src/util/jsonb_document.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/be/src/util/jsonb_document.h b/be/src/util/jsonb_document.h
index cb9425744ff..3ee00709ec0 100644
--- a/be/src/util/jsonb_document.h
+++ b/be/src/util/jsonb_document.h
@@ -1285,6 +1285,8 @@ inline bool JsonbPath::parsePath(Stream* stream, 
JsonbPath* path) {
         return parse_array(stream, path);
     }
     // $.a or $.[0]
+    // Keep $.[0] for backward compatibility: although the dot before an array
+    // leg is non-standard, existing JSONB users may rely on it.
     else if (stream->peek() == BEGIN_MEMBER) {
         // advance past the .
         stream->skip(1);
@@ -1327,7 +1329,8 @@ inline bool JsonbPath::parsePath(Stream* stream, 
JsonbPath* path) {
                 return false;
             }
 
-            // $.[0]
+            // $**.[0]
+            // Keep the dot-array form compatible with the root path behavior.
             if (stream->peek() == BEGIN_ARRAY) {
                 return parse_array(stream, path);
             }
@@ -1390,6 +1393,8 @@ inline bool JsonbPath::parse_array(Stream* stream, 
JsonbPath* path) {
     std::string_view idx_string(stream->get_leg_ptr(), stream->get_leg_len());
     int index = 0;
 
+    // Match "last" case-insensitively for compatibility with existing JSONB
+    // paths such as [Last] and [LAST].
     if (stream->get_leg_len() >= 4 &&
         std::equal(LAST, LAST + 4, stream->get_leg_ptr(),
                    [](char c1, char c2) { return std::tolower(c1) == 
std::tolower(c2); })) {
@@ -1408,6 +1413,8 @@ inline bool JsonbPath::parse_array(Stream* stream, 
JsonbPath* path) {
             idx_string = idx_string.substr(pos + 1);
             idx_string = trim(idx_string);
 
+            // Keep numeric-prefix parsing for last-N offsets as existing JSONB
+            // path behavior.
             auto result = std::from_chars(idx_string.data(), idx_string.data() 
+ idx_string.size(),
                                           index);
             if (result.ec != std::errc()) {
@@ -1425,6 +1432,9 @@ inline bool JsonbPath::parse_array(Stream* stream, 
JsonbPath* path) {
         return true;
     }
 
+    // Preserve legacy numeric-prefix parsing for array indexes. 
std::from_chars
+    // may stop before the end (for example [1.5] is parsed as index 1), and
+    // current JSONB path semantics treat that as supported behavior.
     auto result = std::from_chars(idx_string.data(), idx_string.data() + 
idx_string.size(), index);
 
     if (result.ec != std::errc()) {


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

Reply via email to