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) | Relative
-- | -- | -- | --
2 | 37914 | 24887 | 1.5X
3 | 52862 | 26752 | 2.0X
4 | 71680 | 28452 | 2.5X
5 | 108479 | 36830 | 2.9X
10 | 153952 | 32436 | 4.7X
15 | 224950 | 34806 | 6.5X
20 | 293155 | 38148 | 7.7X
25 | 366037 | 45725 | 8.0X
30 | 439567 | 52949 | 8.3X
35 | 526481 | 60586 | 8.7X
--
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]