Skip to content

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

Open
OldTruckDriver wants to merge 1 commit into
apache:mainfrom
OldTruckDriver:parse-time-tz-validate-timezone
Open

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

Conversation

@OldTruckDriver
Copy link
Copy Markdown

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.

}
}

@Test void testTimeWithTimeZone() {
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.

You'd better add jira link here which show Jira this test is trying to solve.

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.

yes, please see other examples for the formatting used for JIRA test cases.

} 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.

Copy link
Copy Markdown
Contributor

@mihaibudiu mihaibudiu left a comment

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
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