You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
(Calcite PPL) spath command dynamic columns support #4307
Add auto extract mode to spath (when path is omitted) by rewriting to json_extract_all function, returning a single map column (with the flattening rules above).
Improve map access ergonomics [TBD] (keep element_at(map, key) as baseline; consider bracket access and/or PartiQL-like navigation as follow-ups).
Open Questions
Default output in extract-all mode: when path is omitted and output is not specified, the result currently overwrites input field. @anasalkouz suggested avoiding slient overwrite.
Null handling: json_extract_all currently drops null-valued keys. Needs fix if "nulls preserved" is a requirement.
Ergonomic map access syntax: element_at(map, key) is correct but verbose. Potential UX improvements:
Question, Does map<string, any> works fine with our type coercion implemntation. I suggest rewrite our existing type coercion IT to use spath to validate it.
Activity
[-](Calcite PPL) Spath dynamic columns support[/-][+](Calcite PPL) `spath` command dynamic columns support[/+]penghuo commentedon Dec 12, 2025
@ykmr1224 if we add change requirement of spath as
then PPL does not need to support dynamic columns. does it sounds as workaround?
penghuo commentedon Feb 3, 2026
Proposal - Remove dynamic-column expansion
spaththat flattens JSON into a single map field. Remove dynamic-column expansion entirely.Behavior
spath input=f [output=o] path=p→o = json_extract(f, p); defaultoutput = path.spath input=f output=oorspath input=f→o = json_extract_all(f); defaulto = f.input-only no longer expands columns; it produces a map instead.Flattening & Merging
a.b = 1).{}suffix (list{} = [1,2];list{}.x = [1,2]).a.b: [1,2]).Types
map<string,string>: stringify all values for consistency now.map<string,any>as a future enhancement.Compatibility
spath input=fnow yields a map inf(not dynamic columns). Clearly document removal of dynamic-field expansion and the new default.Corner Cases
spath.Example
{"body": "{\"a\":1, \"b\":2}"}| spath input=body output=body→body = {"a":"1","b":"2"}anasalkouz commentedon Feb 6, 2026
I agree with @penghuo proposal. Let's remove the Dynamic field expansion and use output param. The only concern I have in this proposal is
Because this means it will override input f, which might not be the intent of the customer. I would say let's avoid this default behavior
dai-chen commentedon Feb 10, 2026
Proof of Concept
Summary
Design Decisions
Design decisions made based on the proposal above:
spath input=f path=p) is unchanged and continue to rewrites tojson_extract(f, p).json_extract_all(...), which returnsmap<string, string>.user.age,user.name)tags{},users{}.name)c{}.b = [2, 3])Implementation Plan
High level implementation plan:
spath(whenpathis omitted) by rewriting tojson_extract_allfunction, returning a single map column (with the flattening rules above).element_at(map, key)as baseline; consider bracket access and/or PartiQL-like navigation as follow-ups).Open Questions
pathis omitted andoutputis not specified, the result currently overwrites input field. @anasalkouz suggested avoiding slient overwrite.json_extract_allcurrently drops null-valued keys. Needs fix if "nulls preserved" is a requirement.element_at(map, key)is correct but verbose. Potential UX improvements:source=test_flatten | spath input=doc | eval age = doc['user.age'] + 1;source=test_flatten | spath input=doc | eval age = doc.user.age + 1;Proof of Concept Details
0. Test Data
1. Path-based extraction (unchanged)
2. Extract-all to map (new)
When
pathis omitted,spathflattens the entire JSON into amap<string, any>column instead of expanding dynamic columns.As proposed above, we follow flattening rules as below:
3. Accessing map values after extract-all
Use SQL standard
element_at(map, key)(wraps Calcite'sSqlStdOperatorTable.ITEM) to access individual keys from the map:opensearchsql> source=test_spath .............. | spath input=doc output=result .............. | fields result .............. | eval age = element_at(result, 'user.age') + 1; fetched rows / total rows = 5/5 +-----------------------------------------------------------------------+-------+ | result | age | |-----------------------------------------------------------------------+-------| | {'user.age': 30, 'user.name': 'John', 'active': True} | 31.0 | | {'tags{}': ['java', 'sql', 'opensearch']} | null | | {'users{}.name': ['John', 'Jane'], 'users{}.role': ['admin', 'user']} | null | | {'a.b': 1, 'c{}.b': [2, 3]} | null | | {'x': 1, 'z': 'hello'} | null | +-----------------------------------------------------------------------+-------+For path-based extraction, the existing approach still works and is simpler when you know the target field:
Appendix
Curl commands:
penghuo commentedon Feb 11, 2026
+1 on
eval age = doc.user.ageQuestion, Does map<string, any> works fine with our type coercion implemntation. I suggest rewrite our existing type coercion IT to use spath to validate it.