LuciferYang commented on code in PR #40355: URL: https://github.com/apache/spark/pull/40355#discussion_r1133912368
########## connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/PlanGenerationTestSuite.scala: ########## @@ -2065,6 +2065,48 @@ class PlanGenerationTestSuite fn.lit(Array(new CalendarInterval(2, 20, 100L), new CalendarInterval(2, 21, 200L)))) } + test("function typedLit") { + simple.select( + fn.typedLit(fn.col("id")), + fn.typedLit('id), + fn.typedLit(1), + fn.typedLit[String](null), + fn.typedLit(true), + fn.typedLit(68.toByte), + fn.typedLit(9872.toShort), + fn.typedLit(-8726532), + fn.typedLit(7834609328726532L), + fn.typedLit(Math.E), + fn.typedLit(-0.8f), + fn.typedLit(BigDecimal(8997620, 5)), + fn.typedLit(BigDecimal(898897667231L, 7).bigDecimal), + fn.typedLit("connect!"), + fn.typedLit('T'), + fn.typedLit(Array.tabulate(10)(i => ('A' + i).toChar)), + fn.typedLit(Array.tabulate(23)(i => (i + 120).toByte)), + fn.typedLit(mutable.WrappedArray.make(Array[Byte](8.toByte, 6.toByte))), + fn.typedLit(null), + fn.typedLit(java.time.LocalDate.of(2020, 10, 10)), + fn.typedLit(Decimal.apply(BigDecimal(8997620, 6))), + fn.typedLit(java.time.Instant.ofEpochMilli(1677155519808L)), + fn.typedLit(new java.sql.Timestamp(12345L)), + fn.typedLit(java.time.LocalDateTime.of(2023, 2, 23, 20, 36)), + fn.typedLit(java.sql.Date.valueOf("2023-02-23")), + fn.typedLit(java.time.Duration.ofSeconds(200L)), + fn.typedLit(java.time.Period.ofDays(100)), + fn.typedLit(new CalendarInterval(2, 20, 100L)), + + // Handle parameterized scala types e.g.: List, Seq and Map. + fn.typedLit(Some(1)), + fn.typedLit(Seq(1, 2, 3)), + fn.typedLit(Map("a" -> 1, "b" -> 2)), + fn.typedLit(("a", 2, 1.0)), + fn.typedLit(Seq(Seq(1, 2, 3), Seq(4, 5, 6), Seq(7, 8, 9))), + fn.typedLit(Seq(Map("a" -> 1, "b" -> 2), Map("a" -> 3, "b" -> 4), Map("a" -> 5, "b" -> 6))), + fn.typedLit(Map(1 -> Map("a" -> 1, "b" -> 2), 2 -> Map("a" -> 3, "b" -> 4))), + fn.typedLit((Seq(1, 2, 3), Map("a" -> 1, "b" -> 2), ("a", Map(1 -> "a", 2 -> "b"))))) Review Comment: ``` functions.typedlit[mutable.Map[Int, Option[Int]]](mutable.Map(1 -> None)) ``` in sql module return `MAP(1, CAST(NULL AS INT))` in connect client module throw UnsupportedOperationException: ``` literal Map(1 -> None) not supported (yet). java.lang.UnsupportedOperationException: literal Map(1 -> None) not supported (yet). at org.apache.spark.sql.connect.common.LiteralValueProtoConverter$.toLiteralProtoBuilder(LiteralValueProtoConverter.scala:100) at org.apache.spark.sql.connect.common.LiteralValueProtoConverter$.$anonfun$create$2(LiteralValueProtoConverter.scala:151) at scala.util.Failure.getOrElse(Try.scala:222) at org.apache.spark.sql.connect.common.LiteralValueProtoConverter$.create(LiteralValueProtoConverter.scala:151) at org.apache.spark.sql.functions$.typedlit(functions.scala:138) at org.apache.spark.sql.PlanGenerationTestSuite.$anonfun$new$441(PlanGenerationTestSuite.scala:2112) at org.apache.spark.sql.PlanGenerationTestSuite.$anonfun$test$1(PlanGenerationTestSuite.scala:115) ``` -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org