MaxGekk opened a new pull request #27797: [SPARK-31044][SQL] Support foldable JSON strings by `schema_of_json` URL: https://github.com/apache/spark/pull/27797 ### What changes were proposed in this pull request? In the PR, I propose to change checking of the input parameter in the `SchemaOfJson` expression, and allow foldable `child` expression. ### Why are the changes needed? To improve user experience with Spark SQL. Currently, only string literals are acceptable as JSON examples by `schema_of_json`: ```sql spark-sql> select schema_of_json(regexp_replace('{"item_id": 1, "item_price": 0.1}', 'item_', '')); Error in query: cannot resolve 'schema_of_json(regexp_replace('{"item_id": 1, "item_price": 0.1}', 'item_', ''))' due to data type mismatch: The input json should be a string literal and not null; however, got regexp_replace('{"item_id": 1, "item_price": 0.1}', 'item_', '').; line 1 pos 7; 'Project [unresolvedalias(schema_of_json(regexp_replace({"item_id": 1, "item_price": 0.1}, item_, )), None)] +- OneRowRelation ``` ### Does this PR introduce any user-facing change? Yes, after change the `schema_of_json` accepts foldable expressions, for example: ```sql spark-sql> select schema_of_json(regexp_replace('{"item_id": 1, "item_price": 0.1}', 'item_', '')); struct<id:bigint,price:double> ``` ### How was this patch tested? - By existing test suites `JsonFunctionsSuite` and `JsonExpressionsSuite`. - Added new test to `JsonFunctionsSuite` to check foldable input.
---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
