From 4d4fb70ffe0166ecc434863c5b364147106a19ac Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Sat, 5 Oct 2024 15:48:53 +1000 Subject: [PATCH] Support Array(Struct(Array)) cases --- .../spark/daria/sql/DataFrameExt.scala | 3 +- .../spark/daria/sql/DataFrameExtTest.scala | 59 +++++++++++-------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/main/scala/com/github/mrpowers/spark/daria/sql/DataFrameExt.scala b/src/main/scala/com/github/mrpowers/spark/daria/sql/DataFrameExt.scala index 4f0b12f..e61c177 100644 --- a/src/main/scala/com/github/mrpowers/spark/daria/sql/DataFrameExt.scala +++ b/src/main/scala/com/github/mrpowers/spark/daria/sql/DataFrameExt.scala @@ -447,7 +447,6 @@ object DataFrameExt { * }}} */ def sortColumnsBy[A](f: StructField => A)(implicit ord: Ordering[A]): DataFrame = - df - .select(df.schema.toSortedSelectExpr(f): _*) + df.select(df.schema.toSortedSelectExpr(f): _*) } } diff --git a/src/test/scala/com/github/mrpowers/spark/daria/sql/DataFrameExtTest.scala b/src/test/scala/com/github/mrpowers/spark/daria/sql/DataFrameExtTest.scala index 3623d63..abcfcf4 100644 --- a/src/test/scala/com/github/mrpowers/spark/daria/sql/DataFrameExtTest.scala +++ b/src/test/scala/com/github/mrpowers/spark/daria/sql/DataFrameExtTest.scala @@ -1185,14 +1185,14 @@ object DataFrameExtTest extends TestSuite with DataFrameComparer with SparkSessi Seq( Row("yVal", "xVal"), Row("yVal1", "xVal1") + ), + Seq( + Row( + Seq( + Row("x4Val", "x3Val") + ) + ) ) -// Seq( -// Row( -// Seq( -// Row("x4Val", "x3Val") -// ) -// ) -// ) ) ) @@ -1220,12 +1220,16 @@ object DataFrameExtTest extends TestSuite with DataFrameComparer with SparkSessi "w", ArrayType(StructType(Seq(StructField("y", StringType, true), StructField("x", StringType, true)))), true + ), + StructField( + "x", + ArrayType( + StructType( + Seq(StructField("x1", ArrayType(StructType(Seq(StructField("b", StringType, true), StructField("a", StringType, true)))), true)) + ) + ), + true ) -// StructField( -// "x", -// ArrayType(StructType(Seq(StructField("x1", ArrayType(StructType(Seq(StructField("x4", StringType, true), StructField("x3", StringType, true)))), true)))), -// true -// ), ) ) @@ -1252,14 +1256,14 @@ object DataFrameExtTest extends TestSuite with DataFrameComparer with SparkSessi Seq( Row("xVal", "yVal"), Row("xVal1", "yVal1") + ), + Seq( + Row( + Seq( + Row("x3Val", "x4Val") + ) + ) ) -// Seq( -// Row( -// Seq( -// Row("x3Val", "x4Val") -// ) -// ) -// ) ) ) @@ -1287,12 +1291,19 @@ object DataFrameExtTest extends TestSuite with DataFrameComparer with SparkSessi "w", ArrayType(StructType(Seq(StructField("x", StringType, true), StructField("y", StringType, true))), false), true + ), + StructField( + "x", + ArrayType( + StructType( + Seq( + StructField("x1", ArrayType(StructType(Seq(StructField("a", StringType, true), StructField("b", StringType, true))), false), true) + ) + ), + false + ), + true ) -// StructField( -// "x", -// ArrayType(StructType(Seq(StructField("x1", ArrayType(StructType(Seq(StructField("x3", StringType, true), StructField("x4", StringType, true)))), true)))), -// true -// ) ) )