Skip to content

Conversation

@karim-ramadan
Copy link

@karim-ramadan karim-ramadan commented Nov 20, 2024

What changes were proposed in this pull request?

In this Pull request, I propose to add a LocalDateTime serializer to the Row.jsonValue method

    case (d: LocalDateTime, _) => JString(timestampFormatter.format(d))

In order to enable JSON serialization of TimestampNTZType columns

Why are the changes needed?

Currently trying to serialize a Row containing a TimestampNTZType column results in an error:

[FAILED_ROW_TO_JSON] Failed to convert the row value '2018-05-14T12:13' of the class class java.time.LocalDateTime to the target SQL type "TIMESTAMPNTZTYPE" in the JSON format. SQLSTATE: 2203G
org.apache.spark.SparkIllegalArgumentException: [FAILED_ROW_TO_JSON] Failed to convert the row value '2018-05-14T12:13' of the class class java.time.LocalDateTime to the target SQL type "TIMESTAMPNTZTYPE" in the JSON format. SQLSTATE: 2203G
	at org.apache.spark.sql.Row.toJson$1(Row.scala:663)
	at org.apache.spark.sql.Row.toJson$1(Row.scala:651)
	at org.apache.spark.sql.Row.jsonValue(Row.scala:665)
	at org.apache.spark.sql.Row.jsonValue$(Row.scala:598)
	at org.apache.spark.sql.catalyst.expressions.GenericRow.jsonValue(rows.scala:28)
	at org.apache.spark.sql.RowJsonSuite.$anonfun$testJson$1(RowJsonSuite.scala:41)

How to reproduce the issue:

import org.apache.spark.sql.Row
import java.time.LocalDateTime
val r = Row.fromSeq(LocalDateTime.of(2024,8,10,12,33) :: Nil)
r.json
r.prettyJson

Does this PR introduce any user-facing change?

No

How was this patch tested?

Tests were added to the already existing RowJsonSuite.scala class

Was this patch authored or co-authored using generative AI tooling?

No

@github-actions github-actions bot added the SQL label Nov 20, 2024
@karim-ramadan
Copy link
Author

Related issue SPARK-50364

@MaxGekk MaxGekk changed the title [SPARK-50364] Implement serialization for LocalDateTime type in Row.jsonValue [SPARK-50364][SQL] Implement serialization for LocalDateTime type in Row.jsonValue Nov 20, 2024
@MaxGekk
Copy link
Member

MaxGekk commented Nov 20, 2024

+1, LGTM. All GAs passed. Merging to master.
Thank you, @karim-ramadan.

@MaxGekk MaxGekk closed this in 30d0b01 Nov 20, 2024
@MaxGekk
Copy link
Member

MaxGekk commented Nov 20, 2024

@karim-ramadan Congratulations with your first contribution to Apache Spark!

@karim-ramadan
Copy link
Author

@MaxGekk thanks for the fast response and review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants