|
17 | 17 |
|
18 | 18 | package org.apache.spark.sql.execution
|
19 | 19 |
|
20 |
| -import java.time.{Duration, Period} |
| 20 | +import java.time.{Duration, Period, Year} |
21 | 21 |
|
| 22 | +import org.apache.spark.sql.YearUDT |
22 | 23 | import org.apache.spark.sql.catalyst.util.DateTimeTestUtils
|
23 | 24 | import org.apache.spark.sql.connector.catalog.InMemoryTableCatalog
|
24 | 25 | import org.apache.spark.sql.execution.HiveResult._
|
25 | 26 | import org.apache.spark.sql.internal.SQLConf
|
26 | 27 | import org.apache.spark.sql.test.{ExamplePoint, ExamplePointUDT, SharedSparkSession}
|
27 |
| -import org.apache.spark.sql.types.{YearMonthIntervalType => YM} |
28 |
| -import org.apache.spark.sql.types.YearMonthIntervalType |
| 28 | +import org.apache.spark.sql.types.{YearMonthIntervalType, YearMonthIntervalType => YM} |
29 | 29 |
|
30 | 30 |
|
31 | 31 | class HiveResultSuite extends SharedSparkSession {
|
@@ -172,4 +172,18 @@ class HiveResultSuite extends SharedSparkSession {
|
172 | 172 | val plan2 = df.selectExpr("array(i)").queryExecution.executedPlan
|
173 | 173 | assert(hiveResultString(plan2) === Seq("[5 00:00:00.010000000]"))
|
174 | 174 | }
|
| 175 | + |
| 176 | + test("SPARK-52650: Use stringifyValue to get UDT string representation") { |
| 177 | + val year = Year.of(18) |
| 178 | + val tpe = new YearUDT() |
| 179 | + assert(toHiveString((year, tpe), |
| 180 | + nested = false, getTimeFormatters, getBinaryFormatter) === "18") |
| 181 | + val tpe2 = new YearUDT() { |
| 182 | + override def stringifyValue(obj: Any): String = { |
| 183 | + f"${obj.asInstanceOf[Year].getValue}%04d" |
| 184 | + } |
| 185 | + } |
| 186 | + assert(toHiveString((year, tpe2), |
| 187 | + nested = false, getTimeFormatters, getBinaryFormatter) === "0018") |
| 188 | + } |
175 | 189 | }
|
0 commit comments