cloud-fan commented on code in PR #41568:
URL: https://github.com/apache/spark/pull/41568#discussion_r1233765343
##########
sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala:
##########
@@ -249,4 +417,73 @@ class ParametersSuite extends QueryTest with
SharedSparkSession {
.toInstant) :: Nil)
}
}
+
+ test("literal argument of positional parameter in `sql()`") {
+ val sqlText =
+ """SELECT s FROM VALUES ('Jeff /*__*/ Green'), ('E\'Twaun Moore'),
('Vander Blue') AS t(s)
+ |WHERE s = ?""".stripMargin
+ checkAnswer(
+ spark.sql(sqlText, args = Seq(lit("E'Twaun Moore"))),
+ Row("E'Twaun Moore") :: Nil)
+ checkAnswer(
+ spark.sql(sqlText, args = Seq(lit("Vander Blue--comment"))),
+ Nil)
+ checkAnswer(
+ spark.sql(sqlText, args = Seq(lit("Jeff /*__*/ Green"))),
+ Row("Jeff /*__*/ Green") :: Nil)
+
+ withSQLConf(SQLConf.DATETIME_JAVA8API_ENABLED.key -> "true") {
+ checkAnswer(
+ spark.sql(
+ sqlText = """
+ |SELECT d
+ |FROM VALUES (DATE'1970-01-01'), (DATE'2023-12-31') AS
t(d)
+ |WHERE d < ?
+ |""".stripMargin,
+ args = Seq(lit(LocalDate.of(2023, 4, 1)))),
+ Row(LocalDate.of(1970, 1, 1)) :: Nil)
+ checkAnswer(
+ spark.sql(
+ sqlText = """
+ |SELECT d
+ |FROM VALUES (TIMESTAMP_LTZ'1970-01-01 01:02:03
Europe/Amsterdam'),
+ | (TIMESTAMP_LTZ'2023-12-31 04:05:06
America/Los_Angeles') AS t(d)
+ |WHERE d < ?
+ |""".stripMargin,
+ args = Seq(lit(Instant.parse("2023-04-01T00:00:00Z")))),
+ Row(LocalDateTime.of(1970, 1, 1, 1, 2, 3)
+ .atZone(ZoneId.of("Europe/Amsterdam"))
+ .toInstant) :: Nil)
+ }
+ }
+
+ test("unused positional arguments") {
+ checkAnswer(
+ spark.sql("SELECT ?, ?", Seq(1, "abc", 3.14f)),
+ Row(1, "abc"))
+ }
+
+ test("mixing of positional and named parameters") {
+ checkError(
+ exception = intercept[AnalysisException] {
+ spark.sql("select :param1, ?", Map("param1" -> 1))
+ },
+ errorClass = "UNBOUND_SQL_PARAMETER",
Review Comment:
shall we throw a better error message, saying that we found positional
parameters while binding named parameters?
--
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]