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-50795][SQL] Store timestamp as long type in describe LinkedHashMap #49513

Closed
wants to merge 7 commits into from

Conversation

asl3
Copy link
Contributor

@asl3 asl3 commented Jan 15, 2025

What changes were proposed in this pull request?

When storing table metadata in the describe LinkedHashMap object, we retain the timestamp as a longdata type (instead of converting to a formatted date string type) to allow flexibility and extensibility of describe date format. Formatting the date fields is delegated to the caller (e.g. describe table, describe as json, describe column, etc.).

Example date for describe table: Mon Nov 01 12:00:00 UTC 2021

Example date for describe as json: 2021-11-01T12:00:00Z

Why are the changes needed?

Improve extensibility of describe and ensure backwards compatibility

Does this PR introduce any user-facing change?

Affects the describe output date format

How was this patch tested?

Added describe table tests for date format

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

No

@github-actions github-actions bot added the SQL label Jan 15, 2025
@asl3 asl3 changed the title [SPARK-50795][SQL] Store long timestamp type in describe linkedhashmap to improve of date format [SPARK-50795][SQL] Store long timestamp type in describe linkedhashmap Jan 15, 2025
@asl3 asl3 changed the title [SPARK-50795][SQL] Store long timestamp type in describe linkedhashmap [SPARK-50795][SQL] Store long timestamp type in describe LinkedHashMap Jan 15, 2025
@asl3 asl3 changed the title [SPARK-50795][SQL] Store long timestamp type in describe LinkedHashMap [SPARK-50795][SQL] Store timestamp as long type in describe LinkedHashMap Jan 15, 2025
val formattedValue = renamedKey match {
case "created_time" | "last_access" =>
value match {
case JLong(timestamp) if timestamp > 0 =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be negative for dates before 1970-01-01. We should allow it

@@ -80,20 +82,18 @@ trait MetadataMapSupport {
.mkString("[", ", ", "]")
case JInt(value) => value.toString
case JDouble(value) => value.toString
case JLong(value) =>
if (timestampKeys.contains(key)) {
new Date(value).toString
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use Iso8601TimestampFormatter instead of the legacy class Date.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the behavior for DESCRIBE TABLE without AS JSON, see 36d23ef#diff-f2a04f920c41d18a7d387216f86405bfdc6fb09c44ebe1bb09312ba7dde55333L136

Here we just revert it back.

@cloud-fan
Copy link
Contributor

cloud-fan commented Jan 16, 2025

thanks, merging to master/4.0!

@cloud-fan cloud-fan closed this in 8bbec5d Jan 16, 2025
cloud-fan added a commit that referenced this pull request Jan 16, 2025
…dHashMap

### What changes were proposed in this pull request?

When storing table metadata in the `describe` LinkedHashMap object, we retain the timestamp as a `long`data type (instead of converting to a formatted date `string` type) to allow flexibility and extensibility of `describe` date format. Formatting the date fields is delegated to the caller (e.g. describe table, describe as json, describe column, etc.).

Example date for describe table: `Mon Nov 01 12:00:00 UTC 2021`

Example date for describe as json: `2021-11-01T12:00:00Z`

### Why are the changes needed?

Improve extensibility of `describe` and ensure backwards compatibility

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

Affects the `describe` output date format

### How was this patch tested?

Added `describe table` tests for date format

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

No

Closes #49513 from asl3/asl3/describetable-dateplaintext.

Lead-authored-by: Amanda Liu <[email protected]>
Co-authored-by: Wenchen Fan <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
(cherry picked from commit 8bbec5d)
Signed-off-by: Wenchen Fan <[email protected]>
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