viirya commented on pull request #29645:
URL: https://github.com/apache/spark/pull/29645#issuecomment-687486287


   An example looks like:
   
   ```scala
   private lazy val arrayType = ArrayType(
       StructType(Seq(
         StructField("a", IntegerType, nullable = false),
         StructField("b", IntegerType, nullable = true),
         StructField("c", IntegerType, nullable = false))),
       containsNull = true)
   
   private lazy val arrayStructArrayLevel1: DataFrame = spark.createDataFrame(
       sparkContext.parallelize(Row(Array(Row(Array(Row(1, null, 3)), null, 
3))) :: Nil),
       StructType(
         Seq(StructField("a", ArrayType(
           StructType(Seq(
             StructField("a", arrayType, nullable = false),
             StructField("b", IntegerType, nullable = true),
             StructField("c", IntegerType, nullable = false))),
           containsNull = false)))))
   ```
   
   The data looks like:
   ```
   +---------------------------+
   |a                          |
   +---------------------------+
   |[{[{1, null, 3}], null, 3}]|
   +---------------------------+
   ```
   
   In order to replace deeply nested `b` column, like:
   ```
   +------------------------+
   |a                       |
   +------------------------+
   |[{[{1, 2, 3}], null, 3}]|
   +------------------------+
   ```
   
   Currently by using `transform` +  `withField`, we probably need:
   
   ```scala
   arrayStructArrayLevel1.withColumn("a",
         transform($"a", _.withField("a",
           flatten(transform($"a.a", transform(_, _.withField("b", lit(2))))))))
   ```
   
   Using modified `withField`, we can do it like:
   ```scala
   arrayStructArrayLevel1.withColumn("a", $"a".withField("a.b", lit(2)))
   ```


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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to