Skip to content

[CALCITE-7559] SqlParserUtil.parseTimeTzLiteral should reject unknown…#4986

Merged
mihaibudiu merged 1 commit into
apache:mainfrom
OldTruckDriver:parse-time-tz-validate-timezone
Jun 4, 2026
Merged

[CALCITE-7559] SqlParserUtil.parseTimeTzLiteral should reject unknown…#4986
mihaibudiu merged 1 commit into
apache:mainfrom
OldTruckDriver:parse-time-tz-validate-timezone

Conversation

@OldTruckDriver

Copy link
Copy Markdown
Contributor

SqlParserUtil.parseTimeTzLiteral(...) used TimeZone.getTimeZone(String), which silently falls back to GMT for unknown zone IDs, so invalid TIME WITH TIME ZONE literals were accepted instead of rejected. The sibling parseTimestampTzLiteral(...) already validates the zone via ZoneId.of(...).

This applies the same pattern as CALCITE-7527: validate the zone with ZoneId.of(...) and throw a CalciteContextException on an invalid zone, making the two paths consistent.

Added SqlParserUtilTest.testTimeWithTimeZone covering a valid zone, an unknown zone, and a missing zone.

} catch (DateTimeException e) {
String message = e.getMessage();
if (message == null) {
message = "Error parsing TIME ZONE";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Improper capitalization => "Error parsing timezone"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I actually think this is fine, since this is how the SQL type is spelled

message = "Error parsing TIME ZONE";
}
throw SqlUtil.newContextException(pos,
RESOURCE.illegalLiteral("TIME WITH TIME ZONE", s, message));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also here.

@mihaibudiu mihaibudiu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is good, but please add the JIRA link as suggested. No need for a new commit, since this is a small PR, we'll just merge once you update.

@mihaibudiu mihaibudiu added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Jun 3, 2026
@OldTruckDriver
OldTruckDriver force-pushed the parse-time-tz-validate-timezone branch from 906fec2 to a500dda Compare June 4, 2026 08:56
@OldTruckDriver

Copy link
Copy Markdown
Contributor Author

Thanks! Added the JIRA link to the test case in the format used elsewhere. Amended into the existing commit.

@sonarqubecloud

sonarqubecloud Bot commented Jun 4, 2026

Copy link
Copy Markdown

@mihaibudiu
mihaibudiu merged commit 4bb736f into apache:main Jun 4, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LGTM-will-merge-soon Overall PR looks OK. Only minor things left.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants