Skip to content

Commit

Permalink
[SPARK-44783][SQL][TESTS] Checks arrays as named and positional param…
Browse files Browse the repository at this point in the history
…eters

### What changes were proposed in this pull request?
In the PR, I propose to add new test which checks arrays as named and positional parameters.

### Why are the changes needed?
To improve test coverage.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
By running the modified test suite:
```
$ build/sbt "test:testOnly *ParametersSuite"
```

Closes #42470 from MaxGekk/sql-parameterized-by-array.

Authored-by: Max Gekk <max.gekk@gmail.com>
Signed-off-by: Kent Yao <yao@apache.org>
  • Loading branch information
MaxGekk authored and yaooqinn committed Aug 14, 2023
1 parent a50170b commit 0fc85a2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,31 @@ class ParametersSuite extends QueryTest with SharedSparkSession {
start = 24,
stop = 36))
}

test("SPARK-44783: arrays as parameters") {
checkAnswer(
spark.sql("SELECT array_position(:arrParam, 'abc')", Map("arrParam" -> Array.empty[String])),
Row(0))
checkAnswer(
spark.sql("SELECT array_position(?, 0.1D)", Array(Array.empty[Double])),
Row(0))
checkAnswer(
spark.sql("SELECT array_contains(:arrParam, 10)", Map("arrParam" -> Array(10, 20, 30))),
Row(true))
checkAnswer(
spark.sql("SELECT array_contains(?, ?)", Array(Array("a", "b", "c"), "b")),
Row(true))
checkAnswer(
spark.sql("SELECT :arr[1]", Map("arr" -> Array(10, 20, 30))),
Row(20))
checkAnswer(
spark.sql("SELECT ?[?]", Array(Array(1f, 2f, 3f), 0)),
Row(1f))
checkAnswer(
spark.sql("SELECT :arr[0][1]", Map("arr" -> Array(Array(1, 2), Array(20), Array.empty[Int]))),
Row(2))
checkAnswer(
spark.sql("SELECT ?[?][?]", Array(Array(Array(1f, 2f), Array.empty[Float], Array(3f)), 0, 1)),
Row(2f))
}
}

0 comments on commit 0fc85a2

Please sign in to comment.