Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-48776] Fix timestamp formatting for json, xml and csv #47177

Closed

Conversation

milastdbx
Copy link
Contributor

What changes were proposed in this pull request?

In this pull request i propose to change default ISO pattern we use for formatting timestamps when we are writing to json,xml and/or csv as well as when to_(xml|json|csv) is used.

Older timestamps sometimes have offsets that contain seconds part as well. Current default formatting used is omitting seconds hence providing wrong results.

e.g.

sql("SET spark.sql.session.timeZone=America/Los_Angeles")
sql("SELECT to_json(struct(CAST('1800-01-01T00:00:00+00:00' AS TIMESTAMP) AS ts))").show(false)
{"ts":"1799-12-31T16:07:02.000-07:52"}

Why are the changes needed?

This is correctness issue.

Does this PR introduce any user-facing change?

Yes, users will now see different results for older timestamps (correct ones).

How was this patch tested?

Tests

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

No

@github-actions github-actions bot added the SQL label Jul 2, 2024
@milastdbx milastdbx changed the title Fix timestamp formatting for json, xml and csv [SPARK-48776] Fix timestamp formatting for json, xml and csv Jul 2, 2024
@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in c4085f1 Jul 8, 2024
ericm-db pushed a commit to ericm-db/spark that referenced this pull request Jul 10, 2024
### What changes were proposed in this pull request?

In this pull request i propose to change default ISO pattern we use for formatting timestamps when we are writing to json,xml and/or csv as well as when to_(xml|json|csv) is used.

Older timestamps sometimes have offsets that contain seconds part as well. Current default formatting used is omitting seconds hence providing wrong results.

e.g.
```
sql("SET spark.sql.session.timeZone=America/Los_Angeles")
sql("SELECT to_json(struct(CAST('1800-01-01T00:00:00+00:00' AS TIMESTAMP) AS ts))").show(false)
{"ts":"1799-12-31T16:07:02.000-07:52"}
```

### Why are the changes needed?

This is correctness issue.

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

Yes, users will now see different results for older timestamps (correct ones).

### How was this patch tested?

Tests

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

No

Closes apache#47177 from milastdbx/dev/milast/fixJsonTimestampHandling.

Authored-by: milastdbx <milan.stefanovic@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
jingz-db pushed a commit to jingz-db/spark that referenced this pull request Jul 22, 2024
### What changes were proposed in this pull request?

In this pull request i propose to change default ISO pattern we use for formatting timestamps when we are writing to json,xml and/or csv as well as when to_(xml|json|csv) is used.

Older timestamps sometimes have offsets that contain seconds part as well. Current default formatting used is omitting seconds hence providing wrong results.

e.g.
```
sql("SET spark.sql.session.timeZone=America/Los_Angeles")
sql("SELECT to_json(struct(CAST('1800-01-01T00:00:00+00:00' AS TIMESTAMP) AS ts))").show(false)
{"ts":"1799-12-31T16:07:02.000-07:52"}
```

### Why are the changes needed?

This is correctness issue.

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

Yes, users will now see different results for older timestamps (correct ones).

### How was this patch tested?

Tests

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

No

Closes apache#47177 from milastdbx/dev/milast/fixJsonTimestampHandling.

Authored-by: milastdbx <milan.stefanovic@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
attilapiros pushed a commit to attilapiros/spark that referenced this pull request Oct 4, 2024
### What changes were proposed in this pull request?

In this pull request i propose to change default ISO pattern we use for formatting timestamps when we are writing to json,xml and/or csv as well as when to_(xml|json|csv) is used.

Older timestamps sometimes have offsets that contain seconds part as well. Current default formatting used is omitting seconds hence providing wrong results.

e.g.
```
sql("SET spark.sql.session.timeZone=America/Los_Angeles")
sql("SELECT to_json(struct(CAST('1800-01-01T00:00:00+00:00' AS TIMESTAMP) AS ts))").show(false)
{"ts":"1799-12-31T16:07:02.000-07:52"}
```

### Why are the changes needed?

This is correctness issue.

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

Yes, users will now see different results for older timestamps (correct ones).

### How was this patch tested?

Tests

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

No

Closes apache#47177 from milastdbx/dev/milast/fixJsonTimestampHandling.

Authored-by: milastdbx <milan.stefanovic@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
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.

4 participants