CuteChuanChuan opened a new pull request, #20412:
URL: https://github.com/apache/datafusion/pull/20412

   ## Which issue does this PR close?
   
   - Part of #15914
   - Related comet issue: https://github.com/apache/datafusion-comet/issues/3160
   
   ## Rationale for this change
   
   - Apache Spark's `json_tuple` extracts top-level fields from a JSON string.
   - This function is used in Spark SQL and needed for DataFusion-Comet 
compatibility.
   - Reference: 
https://spark.apache.org/docs/latest/api/sql/index.html#json_tuple
   
   ## What changes are included in this PR?
   
   - Add Spark-compatible `json_tuple` function in `datafusion-spark` crate
   - Function signature: `json_tuple(json_string, key1, key2, ...) -> 
Struct<c0: Utf8, c1: Utf8, ...>`
     - `json_string`: The JSON string to extract fields from
     - `key1, key2, ...`: Top-level field names to extract
     - Returns a Struct because DataFusion ScalarUDFs return one value per row; 
caller (Comet) destructures the fields
   
   ### Examples
   
   ```sql
   SELECT json_tuple('{"f1":"value1","f2":"value2","f3":3}', 'f1', 'f2', 'f3');
   -- {c0: value1, c1: value2, c2: 3}
   
   SELECT json_tuple('{"f1":"value1"}', 'f1', 'f2');
   -- {c0: value1, c1: NULL}
   
   SELECT json_tuple(NULL, 'f1');
   -- NULL
   ```
   
   ## Are these changes tested?
   
   - Unit tests: return_field_from_args shape validation and too-few-args error
   - sqllogictest: test_files/spark/json/json_tuple.slt, test cases derived from
   Spark JsonExpressionsSuite
   
   ## Are there any user-facing changes?
   Yes.


-- 
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]

Reply via email to