wangyum opened a new pull request, #40419:
URL: https://github.com/apache/spark/pull/40419

   ### What changes were proposed in this pull request?
   
   This PR adds a new rule to rewrite multiple `GetJsonObjects` to one 
`JsonTuple` if their json expressions are the same and the path is `.name`. For 
example:
   ```
   === Applying Rule 
org.apache.spark.sql.catalyst.optimizer.RewriteGetJsonObject ===
   !Project [get_json_object(a#0, $.c1) AS c1#3, get_json_object(a#0, $.c2) AS 
c2#4, get_json_object(b#1, $.c1) AS c3#5, get_json_object(b#1, $.c2) AS c4#6, 
get_json_object(c#2, $.c1) AS c5#7]   Project [c1#13 AS c1#3, c2#14 AS c2#4, 
c1#15 AS c3#5, c2#16 AS c4#6, get_json_object(c#2, $.c1) AS c5#7]
   !+- LocalRelation <empty>, [a#0, b#1, c#2]                                   
                                                                                
                                   +- Generate json_tuple(b#1, c1, c2), false, 
b, [c1#15, c2#16]
   !                                                                            
                                                                                
                                      +- Generate json_tuple(a#0, c1, c2), 
false, a, [c1#13, c2#14]
   !                                                                            
                                                                                
                                         +- LocalRelation <empty>, [a#0, b#1, 
c#2]
   ```
   
   Please note that it needs to rewrite the path, otherwise it will not get the 
correct value. For example:
   ```sql
   spark-sql (default)> SELECT get_json_object('{"name": "alice", "age": 5}', 
'$.name') AS name;
   alice
   spark-sql (default)> SELECT name  lateral view json_tuple('{"name": "alice", 
"age": 5}', '$.name') a AS name;
   NULL
   spark-sql (default)> select name  lateral view json_tuple('{"name": "alice", 
"age": 5}', 'name') a as name;
   alice
   ```
   
   
   ### Why are the changes needed?
   
   Improve query performance.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   Unit test and benchmark test.
   
   Benchmark result:
   
   No. of   GetJsonObjects | Default(ms) | Rewrite to JsonTuple(ms)
   -- | -- | --
   2 | 39026 | 24354
   3 | 54652 | 30702
   4 | 75503 | 26962
   5 | 94923 | 25362
   10 | 157458 | 28296
   20 | 285338 | 31682
   30 | 481691 | 46614
   36 | 576500 | 40461
   
   
   
   </body>
   
   </html>
   


-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to