wangyum commented on PR #42376:
URL: https://github.com/apache/spark/pull/42376#issuecomment-1671438383

   @monkeyboy123 Have you enabled 
`spark.sql.optimizer.collapseProjectAlwaysInline`?
   
   ```scala
   Seq("""{"a":1, "b":0.8}""").toDF("s").write.saveAsTable("t")
   val df = sql(
     """
       |SELECT j.*
       |FROM   (SELECT from_json(regexp_replace(s, 'a', 'new_a'), 'new_a INT, b 
DOUBLE') AS j
       |        FROM   t) tmp
       |""".stripMargin)
   df.explain(true)
   ```
   
   `set spark.sql.optimizer.collapseProjectAlwaysInline=false`:
   ```
   == Optimized Logical Plan ==
   Project [j#17.new_a AS new_a#20, j#17.b AS b#21]
   +- Project [from_json(StructField(new_a,IntegerType,true), 
StructField(b,DoubleType,true), regexp_replace(s#18, a, new_a, 1), 
Some(America/Los_Angeles)) AS j#17]
      +- Relation spark_catalog.default.t[s#18] parquet
   
   == Physical Plan ==
   *(2) Project [j#17.new_a AS new_a#20, j#17.b AS b#21]
   +- Project [from_json(StructField(new_a,IntegerType,true), 
StructField(b,DoubleType,true), regexp_replace(s#18, a, new_a, 1), 
Some(America/Los_Angeles)) AS j#17]
      +- *(1) ColumnarToRow
         +- FileScan parquet spark_catalog.default.t[s#18] Batched: true, 
DataFilters: [], Format: Parquet, Location: InMemoryFileIndex(1 
paths)[file:/Users/yumwang/spark/spark-warehouse/org.apache.spark..., 
PartitionFilters: [], PushedFilters: [], ReadSchema: struct<s:string>
   ```
   `set spark.sql.optimizer.collapseProjectAlwaysInline=true`:
   ```
   == Optimized Logical Plan ==
   Project [from_json(StructField(new_a,IntegerType,true), regexp_replace(s#18, 
a, new_a, 1), Some(America/Los_Angeles)).new_a AS new_a#20, 
from_json(StructField(b,DoubleType,true), regexp_replace(s#18, a, new_a, 1), 
Some(America/Los_Angeles)).b AS b#21]
   +- Relation spark_catalog.default.t[s#18] parquet
   
   == Physical Plan ==
   Project [from_json(StructField(new_a,IntegerType,true), regexp_replace(s#18, 
a, new_a, 1), Some(America/Los_Angeles)).new_a AS new_a#20, 
from_json(StructField(b,DoubleType,true), regexp_replace(s#18, a, new_a, 1), 
Some(America/Los_Angeles)).b AS b#21]
   +- *(1) ColumnarToRow
      +- FileScan parquet spark_catalog.default.t[s#18] Batched: true, 
DataFilters: [], Format: Parquet, Location: InMemoryFileIndex(1 
paths)[file:/Users/yumwang/spark/spark-warehouse/org.apache.spark..., 
PartitionFilters: [], PushedFilters: [], ReadSchema: struct<s:string>
   ```


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