luchunliang opened a new issue, #12189:
URL: https://github.com/apache/inlong/issues/12189
### Description
`ArrayParser` in Transform SDK is bound to
`net.sf.jsqlparser.expression.ArrayExpression`, i.e. the SQL bracket syntax
`expr[index_or_key]`. Historically it only supported two shapes:
1. `List<?>[Number]` — access a Java list element by numeric index;
2. `JsonArray[Number]` — access a `com.google.gson.JsonArray` element by
numeric index.
However, several very common expressions in real pipelines rely on
**key-based bracket access** rather than numeric indexing, for example:
- `STR_TO_MAP(URL_DECODE(event_value), '&', '=')['HY50']` — pick a value out
of a `str_to_map` result inside `SELECT` / `WHERE`;
- `JSON_TO_STRUCT($root.person)['name']` or a raw `JsonObject` from other
functions — pick a field out of a JSON object by key.
Before this change these expressions returned `null`, forcing users to
introduce intermediate columns or extra function calls (e.g. `PARSE_URL` with
`QUERY`) and making the SQL harder to read and maintain.
This issue proposes extending `ArrayParser` so that `expr[key]` works
uniformly for:
- `List<?>` indexed by a `Number` (existing behavior — unchanged);
- **`Map<?, ?>` indexed by any key type — NEW;**
- `JsonArray` indexed by a `Number` (existing behavior — unchanged);
- **`JsonObject` indexed by a `String` key — NEW.**
For the JSON branches, primitive results are unwrapped to their natural Java
types (`String`, `Boolean`, `Number`); nested `JsonArray` / `JsonObject`
results are preserved so downstream operators can keep drilling in.
### Use case
1. **KV map lookup after `STR_TO_MAP`** — decode a URL-encoded query string
and pluck a specific parameter in one line:
```sql
SELECT
STR_TO_MAP(URL_DECODE(event_value), '&', '=')['HY50'] AS HY50
FROM source
WHERE STR_TO_MAP(URL_DECODE(event_value), '&', '=')['HY50'] =
'welfare_milestone_operations'
AND event_code = 'OnPageEnter';
```
2. **JSON key access** — read fields off a raw `JsonObject` produced by JSON
helper functions using the intuitive `obj['field']` syntax, without additional
casting.
3. **Consistency** — align bracket-access semantics with common SQL /
JSONPath expectations, reduce boilerplate, and remove edge cases where a
valid-looking expression silently returned `null`.
### Are you willing to submit PR?
- [x] Yes, I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of
Conduct](https://www.apache.org/foundation/policies/conduct)
--
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]