Baymine opened a new pull request, #44897:
URL: https://github.com/apache/doris/pull/44897
### What problem does this PR solve?
Issue Number: #44565
Related PR: <!-- If there are no related PRs, you can leave this empty -->
Problem Summary:
When using `JSON_ARRAY` and `JSON_OBJECT` functions with nested JSON
structures, the nested objects were being converted to strings instead of
preserving their JSON structure. This caused `JSON_EXTRACT` to return NULL when
trying to access nested fields.
For example:
```sql
SELECT JSON_EXTRACT(JSON_ARRAY(JSON_OBJECT("name", "Adam"),
JSON_OBJECT("name", "Kent")), '$.[0].name');
-- Returns NULL instead of "Adam"
SELECT JSON_EXTRACT(
JSON_OBJECT("user", JSON_OBJECT("name", "Adam", "age", 30)),
'$.user.name'
);
-- Returns NULL instead of "Adam"
```
### Release note
None
### Check List (For Author)
- Test
- [ ] Regression test
- [ ] Unit Test
- [x] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason
Manual Test Cases:
1. Basic JSON array with objects:
```sql
SELECT JSON_EXTRACT(JSON_ARRAY(JSON_OBJECT("name", "Adam"),
JSON_OBJECT("name", 'Kent')), '$.[0].name');
-- Now returns: "Adam" as expected
```
2. Nested objects:
```sql
SELECT
JSON_EXTRACT (
JSON_ARRAY (
JSON_OBJECT ("user", JSON_OBJECT ("name", "Adam", "age", 30)),
JSON_OBJECT ("user", JSON_OBJECT ("name", "Kent", "age", 25))
),
'$.[0].user.name'
);
-- Now returns: "Adam" as expected
```
3. Complex nested structures:
```sql
SELECT
JSON_EXTRACT (
JSON_OBJECT (
'users',
JSON_ARRAY (
JSON_OBJECT ('name', 'Adam', 'scores', JSON_ARRAY (10, 20, 30)),
JSON_OBJECT ('name', 'Kent', 'scores', JSON_ARRAY (15, 25, 35))
)
),
'$.users[0].scores[1]'
);
-- Now returns: 20 as expected
```
- Behavior changed:
- [ ] No.
- [x] Yes. <!-- Explain the behavior change -->
The behavior of `JSON_ARRAY` and `JSON_OBJECT` functions has been fixed
to properly preserve nested JSON structures instead of converting them to
strings. This change makes the functions work as expected according to SQL
standard and common JSON processing practices.
- Does this need documentation?
- [x] No.
- [ ] Yes.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR should
merge into -->
--
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]