Skip to content
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