beliefer commented on code in PR #38874:
URL: https://github.com/apache/spark/pull/38874#discussion_r1047987567
##########
sql/core/src/test/resources/sql-tests/inputs/array.sql:
##########
@@ -119,3 +119,15 @@ select get(array(1, 2, 3), 0);
select get(array(1, 2, 3), 3);
select get(array(1, 2, 3), null);
select get(array(1, 2, 3), -1);
+
+-- function array_compact
+create temporary view invalid_datatype as select * from values
Review Comment:
The temp view just used once. We can remove it.
##########
sql/core/src/test/resources/sql-tests/inputs/array.sql:
##########
@@ -119,3 +119,15 @@ select get(array(1, 2, 3), 0);
select get(array(1, 2, 3), 3);
select get(array(1, 2, 3), null);
select get(array(1, 2, 3), -1);
+
+-- function array_compact
+create temporary view invalid_datatype as select * from values
+(1), (2), (3)
+as invalid_datatype(id);
+
+select array_compact(id) from invalid_datatype;
Review Comment:
So, just pass one int value here.
##########
sql/core/src/test/resources/sql-tests/inputs/array.sql:
##########
@@ -119,3 +119,15 @@ select get(array(1, 2, 3), 0);
select get(array(1, 2, 3), 3);
select get(array(1, 2, 3), null);
select get(array(1, 2, 3), -1);
+
+-- function array_compact
+create temporary view invalid_datatype as select * from values
+(1), (2), (3)
+as invalid_datatype(id);
+
+select array_compact(id) from invalid_datatype;
+select array_compact(array("1", null, "2", null));
+select array_compact(array("1", null, "2", null));
Review Comment:
The case is duplicated.
##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala:
##########
@@ -5237,6 +5237,53 @@ class DataFrameFunctionsSuite extends QueryTest with
SharedSparkSession {
)
)
}
+
+ test("test array_compact") {
+ val df = Seq(
+ (Array[Integer](null, 1, 2, null, 3, 4),
+ Array("a", null, "b", null, "c", "d"), Array("", "")),
+ (Array.empty[Integer], Array("1.0", "2.2", "3.0"), Array.empty[String]),
+ (Array[Integer](null, null, null), null, null)
+ ).toDF("a", "b", "c")
+
+ checkAnswer(
+ df.select(array_compact($"a"),
+ array_compact($"b"), array_compact($"c")),
+ Seq(Row(Seq(1, 2, 3, 4), Seq("a", "b", "c", "d"), Seq("", "")),
+ Row(Seq.empty[Integer], Seq("1.0", "2.2", "3.0"), Seq.empty[String]),
+ Row(Seq.empty[Integer], null, null))
+ )
+
+ checkAnswer(
+ OneRowRelation().selectExpr("array_compact(array(1.0D, 2.0D, null))"),
+ Seq(
+ Row(Seq(1.0, 2.0))
+ )
+ )
+
+ // complex data type
+ checkAnswer(
+ OneRowRelation().
+ selectExpr("array_compact(array(array(1, null,3), null, array(null, 2,
3)))"),
+ Seq(
+ Row(Seq(Seq(1, null, 3), Seq(null, 2, 3))))
Review Comment:
```suggestion
Seq(Row(Seq(Seq(1, null, 3), Seq(null, 2, 3))))
```
##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala:
##########
@@ -5237,6 +5237,53 @@ class DataFrameFunctionsSuite extends QueryTest with
SharedSparkSession {
)
)
}
+
+ test("test array_compact") {
+ val df = Seq(
+ (Array[Integer](null, 1, 2, null, 3, 4),
+ Array("a", null, "b", null, "c", "d"), Array("", "")),
+ (Array.empty[Integer], Array("1.0", "2.2", "3.0"), Array.empty[String]),
+ (Array[Integer](null, null, null), null, null)
+ ).toDF("a", "b", "c")
+
+ checkAnswer(
+ df.select(array_compact($"a"),
+ array_compact($"b"), array_compact($"c")),
+ Seq(Row(Seq(1, 2, 3, 4), Seq("a", "b", "c", "d"), Seq("", "")),
+ Row(Seq.empty[Integer], Seq("1.0", "2.2", "3.0"), Seq.empty[String]),
+ Row(Seq.empty[Integer], null, null))
+ )
+
+ checkAnswer(
+ OneRowRelation().selectExpr("array_compact(array(1.0D, 2.0D, null))"),
+ Seq(
+ Row(Seq(1.0, 2.0))
+ )
+ )
+
+ // complex data type
+ checkAnswer(
+ OneRowRelation().
+ selectExpr("array_compact(array(array(1, null,3), null, array(null, 2,
3)))"),
+ Seq(
+ Row(Seq(Seq(1, null, 3), Seq(null, 2, 3))))
+ )
+
+ // unsupported data type
+ val invalid_Datatype_df = Seq(1, 2, 3).toDF("a")
+ checkErrorMatchPVals(
+ exception = intercept[AnalysisException] {
+ invalid_Datatype_df.select(array_compact($"a"))
Review Comment:
ditto.
##########
sql/core/src/test/resources/sql-tests/inputs/array.sql:
##########
@@ -119,3 +119,15 @@ select get(array(1, 2, 3), 0);
select get(array(1, 2, 3), 3);
select get(array(1, 2, 3), null);
select get(array(1, 2, 3), -1);
+
+-- function array_compact
+create temporary view invalid_datatype as select * from values
+(1), (2), (3)
+as invalid_datatype(id);
+
+select array_compact(id) from invalid_datatype;
+select array_compact(array("1", null, "2", null));
+select array_compact(array("1", null, "2", null));
+select array_compact(array(1D, null, 2D, null));
+select array_compact(array(array(1, 2, 3, null), null, array(4, null, 6)));
+select array_compact(array(null));
Review Comment:
Could you add a case that the input array without null ?
##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala:
##########
@@ -5237,6 +5237,53 @@ class DataFrameFunctionsSuite extends QueryTest with
SharedSparkSession {
)
)
}
+
+ test("test array_compact") {
+ val df = Seq(
+ (Array[Integer](null, 1, 2, null, 3, 4),
+ Array("a", null, "b", null, "c", "d"), Array("", "")),
+ (Array.empty[Integer], Array("1.0", "2.2", "3.0"), Array.empty[String]),
+ (Array[Integer](null, null, null), null, null)
+ ).toDF("a", "b", "c")
+
+ checkAnswer(
+ df.select(array_compact($"a"),
+ array_compact($"b"), array_compact($"c")),
+ Seq(Row(Seq(1, 2, 3, 4), Seq("a", "b", "c", "d"), Seq("", "")),
+ Row(Seq.empty[Integer], Seq("1.0", "2.2", "3.0"), Seq.empty[String]),
+ Row(Seq.empty[Integer], null, null))
+ )
+
+ checkAnswer(
+ OneRowRelation().selectExpr("array_compact(array(1.0D, 2.0D, null))"),
+ Seq(
+ Row(Seq(1.0, 2.0))
+ )
Review Comment:
```suggestion
Seq(Row(Seq(1.0, 2.0)))
```
##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala:
##########
@@ -5237,6 +5237,53 @@ class DataFrameFunctionsSuite extends QueryTest with
SharedSparkSession {
)
)
}
+
+ test("test array_compact") {
+ val df = Seq(
+ (Array[Integer](null, 1, 2, null, 3, 4),
+ Array("a", null, "b", null, "c", "d"), Array("", "")),
+ (Array.empty[Integer], Array("1.0", "2.2", "3.0"), Array.empty[String]),
+ (Array[Integer](null, null, null), null, null)
+ ).toDF("a", "b", "c")
+
+ checkAnswer(
+ df.select(array_compact($"a"),
+ array_compact($"b"), array_compact($"c")),
+ Seq(Row(Seq(1, 2, 3, 4), Seq("a", "b", "c", "d"), Seq("", "")),
+ Row(Seq.empty[Integer], Seq("1.0", "2.2", "3.0"), Seq.empty[String]),
+ Row(Seq.empty[Integer], null, null))
+ )
+
+ checkAnswer(
+ OneRowRelation().selectExpr("array_compact(array(1.0D, 2.0D, null))"),
+ Seq(
+ Row(Seq(1.0, 2.0))
+ )
+ )
+
+ // complex data type
+ checkAnswer(
+ OneRowRelation().
+ selectExpr("array_compact(array(array(1, null,3), null, array(null, 2,
3)))"),
+ Seq(
+ Row(Seq(Seq(1, null, 3), Seq(null, 2, 3))))
+ )
+
+ // unsupported data type
+ val invalid_Datatype_df = Seq(1, 2, 3).toDF("a")
Review Comment:
```suggestion
val invalidDatatypeDF = Seq(1, 2, 3).toDF("a")
```
--
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]