Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add explicit test for null and empty arrays with array_remove #1270

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.apache.hadoop.fs.Path
import org.apache.spark.sql.{CometTestBase, DataFrame, Row}
import org.apache.spark.sql.catalyst.optimizer.SimplifyExtractValueOps
import org.apache.spark.sql.comet.{CometColumnarToRowExec, CometProjectExec}
import org.apache.spark.sql.execution.{InputAdapter, ProjectExec, WholeStageCodegenExec}
import org.apache.spark.sql.execution.{InputAdapter, LocalTableScanExec, ProjectExec, WholeStageCodegenExec}
import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper
import org.apache.spark.sql.functions._
import org.apache.spark.sql.internal.SQLConf
Expand Down Expand Up @@ -2545,4 +2545,56 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {
}
}
}

test("array_remove - ints") {
registerIntArray()
withSQLConf(
CometConf.COMET_SPARK_TO_ARROW_ENABLED.key -> "true",
CometConf.COMET_SPARK_TO_ARROW_SUPPORTED_OPERATOR_LIST.key -> "LocalTableScan") {
for (query <- Seq(
"select a, array_remove(a, 2) from int_array",
"select a, array_remove(a, -2) from int_array",
"select a, array_remove(a, null) from int_array")) {
checkSparkAnswerAndOperator(sql(query), classOf[LocalTableScanExec])
}
}
}

test("array_remove - strings") {
registerStringArray()
withSQLConf(
CometConf.COMET_SPARK_TO_ARROW_ENABLED.key -> "true",
CometConf.COMET_SPARK_TO_ARROW_SUPPORTED_OPERATOR_LIST.key -> "LocalTableScan") {
for (query <- Seq(
"select a, array_remove(a, 'two') from string_array",
"select a, array_remove(a, '') from string_array",
"select a, array_remove(a, 'four') from string_array",
"select a, array_remove(a, null) from string_array")) {
checkSparkAnswerAndOperator(sql(query), classOf[LocalTableScanExec])
}
}
}

private def registerIntArray(): Unit = {
val values: Seq[Option[Array[Option[Int]]]] = Seq(
Some(Array(Some(1), Some(2), Some(3))),
Some(Array(Some(1), Some(2), Some(2))),
Some(Array(None, Some(2), Some(2))),
None,
Some(Array()),
Some(Array(None, None)))
values.toDF("a").createOrReplaceTempView("int_array")
}

private def registerStringArray(): Unit = {
val values: Seq[Option[Array[Option[String]]]] = Seq(
Some(Array(Some("one"), Some("two"), Some("three"))),
Some(Array(Some("one"), Some("two"), Some("two"))),
Some(Array(None, Some("two"), Some("two"))),
None,
Some(Array()),
Some(Array(None, None)))
values.toDF("a").createOrReplaceTempView("string_array")
}

}
Loading