Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,24 @@ public static SqlTimeTzLiteral parseTimeTzLiteral(
final String timeZone = s.substring(lastSpace + 1);
final String time = s.substring(0, lastSpace);

final TimeZone tz = TimeZone.getTimeZone(timeZone);
if (tz != null) {
try {
ZoneId zoneId = ZoneId.of(timeZone);
TimeZone tz = TimeZone.getTimeZone(zoneId);
pt =
DateTimeUtils.parsePrecisionDateTimeLiteral(time, Format.get().time, tz, -1);
} 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

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

}
}
if (pt == null) {
throw SqlUtil.newContextException(pos,
RESOURCE.illegalLiteral("TIME WITH TIME ZONE", s,
RESOURCE.badFormat(DateTimeUtils.TIME_FORMAT_STRING).str()));
RESOURCE.badFormat(DateTimeUtils.TIME_FORMAT_STRING + " zone").str()));
}
final TimeWithTimeZoneString t = TimeWithTimeZoneString.fromCalendarFields(pt.getCalendar())
.withFraction(pt.getFraction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.calcite.avatica.util.TimeUnit;
import org.apache.calcite.runtime.CalciteContextException;
import org.apache.calcite.sql.SqlIntervalQualifier;
import org.apache.calcite.sql.SqlTimeTzLiteral;
import org.apache.calcite.sql.SqlTimestampTzLiteral;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -94,6 +95,33 @@ public class SqlParserUtilTest {
}
}

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

SqlParserPos pos = new SqlParserPos(2, 3);
SqlTimeTzLiteral lit =
SqlParserUtil.parseTimeTzLiteral("10:10:10 GMT", pos);
assertThat(lit, hasToString("TIME WITH TIME ZONE '10:10:10 UTC'"));

// Like parseTimestampTzLiteral, parseTimeTzLiteral should reject unknown
// time zones instead of silently falling back to GMT.
try {
SqlParserUtil.parseTimeTzLiteral("10:10:10 incorrect_zone", pos);
fail("Should be unreachable");
} catch (CalciteContextException ex) {
assertThat(
ex.getMessage(), is("At line 2, column 3: Illegal TIME WITH TIME ZONE literal "
+ "'10:10:10 incorrect_zone': Unknown time-zone ID: incorrect_zone"));
}

try {
SqlParserUtil.parseTimeTzLiteral("10:10:10", pos);
fail("Should be unreachable");
} catch (CalciteContextException ex) {
assertThat(
ex.getMessage(), is("At line 2, column 3: Illegal TIME WITH TIME ZONE literal "
+ "'10:10:10': not in format 'HH:mm:ss zone'"));
}
}

@Test void testMinuteToSecondIntervalToMillis() {
final SqlIntervalQualifier qualifier =
new SqlIntervalQualifier(TimeUnit.MINUTE, TimeUnit.SECOND, POSITION);
Expand Down
Loading