sandeep-katta commented on code in PR #38874:
URL: https://github.com/apache/spark/pull/38874#discussion_r1048130169
##########
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"))
+ },
+ errorClass = "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE",
+ parameters = Map(
+ "sqlExpr" -> """"filter\(a, lambdafunction\(\(x_\d+ IS NOT NULL\),
x_\d+\)\)"""",
Review Comment:
What I understand is if any class extends `InheritAnalysisRules` then
`replacement` object is used for all the analysis rules, so even if I implement
`def checkInputDataTypes(): TypeCheckResult` it will be a dead code.
And also as per the guideline
[here](https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala#L325-L355)
```
// It's much simpler if the SQL function can be implemented with existing
expression(s). There are
// a few cases:
// - The function can be implemented by combining some existing
expressions. We can use
// `RuntimeReplaceable` to define the combination. See `ParseToDate` as
an example.
// To inherit the analysis behavior from the replacement expression
// mix-in `InheritAnalysisRules` with `RuntimeReplaceable`. See `TryAdd`
as an example.
```
So if we want to have analysis rules to applied for `ArrayCompact` then it
should `extends RuntimeReplaceable with UnaryLike[Expression] with
ExpectsInputTypes with NullIntolerant`
--
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]