-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
HIVE-28337: TestMetaStoreUtils fails for invalid timestamps #5309
Open
KiranVelumuri
wants to merge
1
commit into
apache:master
Choose a base branch
from
KiranVelumuri:HIVE-28337
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+43
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,28 +48,52 @@ public class TestMetaStoreUtils { | |
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss"); | ||
private final TimeZone timezone; | ||
private final String date; | ||
private final String timestamp; | ||
private final String timestampString; | ||
private final Timestamp timestamp; | ||
|
||
public TestMetaStoreUtils(String zoneId, LocalDateTime timestamp) { | ||
this.timezone = TimeZone.getTimeZone(zoneId); | ||
this.timestamp = timestamp.format(FORMATTER); | ||
this.timestampString = timestamp.format(FORMATTER); | ||
this.date = timestamp.toLocalDate().format(DateTimeFormatter.ISO_LOCAL_DATE); | ||
|
||
TimeZone.setDefault(TimeZone.getTimeZone("UTC")); | ||
this.timestamp = Timestamp.valueOf(timestamp); | ||
TimeZone.setDefault(DEFAULT); | ||
} | ||
|
||
@Parameterized.Parameters(name = "zoneId={0}, timestamp={1}") | ||
public static Collection<Object[]> generateZoneTimestampPairs() { | ||
List<Object[]> params = new ArrayList<>(); | ||
long minDate = LocalDate.of(0, 1, 1).atStartOfDay().toEpochSecond(ZoneOffset.UTC); | ||
long minDate = LocalDate.of(1, 1, 1).atStartOfDay().toEpochSecond(ZoneOffset.UTC); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the data type specification of DATE |
||
long maxDate = LocalDate.of(9999, 12, 31).atStartOfDay().toEpochSecond(ZoneOffset.UTC); | ||
new Random(23).longs(500, minDate, maxDate).forEach(i -> { | ||
LocalDateTime datetime = LocalDateTime.ofEpochSecond(i, 0, ZoneOffset.UTC); | ||
for (String zone : ZoneId.SHORT_IDS.values()) { | ||
params.add(new Object[] { zone, datetime }); | ||
} | ||
}); | ||
generateDaylightSavingTimestampPairs(params); | ||
return params; | ||
} | ||
|
||
public static void generateDaylightSavingTimestampPairs(List<Object[]> params) { | ||
// For U.S timezones, the timestamp 2024-03-10 02:01:00 falls between the transition from 02:00 AM to 03:00 AM for daylight savings | ||
params.add(new Object[] {"America/Anchorage", LocalDateTime.ofEpochSecond(1710036060L, 0, ZoneOffset.UTC)}); | ||
params.add(new Object[] {"America/St_Johns", LocalDateTime.ofEpochSecond(1710036060L, 0, ZoneOffset.UTC)}); | ||
params.add(new Object[] {"America/Chicago", LocalDateTime.ofEpochSecond(1710036060L, 0, ZoneOffset.UTC)}); | ||
params.add(new Object[] {"America/Indiana/Indianapolis", LocalDateTime.ofEpochSecond(1710036060L, 0, ZoneOffset.UTC)}); | ||
params.add(new Object[] {"America/Los_Angeles", LocalDateTime.ofEpochSecond(1710036060L, 0, ZoneOffset.UTC)}); | ||
|
||
// For Paris timezone, the timestamp 2024-03-31 02:02:02 falls between the transition from 02:00 AM to 03:00 AM for daylight savings | ||
params.add(new Object[] {"Europe/Paris", LocalDateTime.ofEpochSecond(1711850522L, 0, ZoneOffset.UTC)}); | ||
|
||
// For New Zealand timezone, the timestamp 2024-09-29 02:03:04 falls between the transition from 02:00 AM to 03:00 AM for daylight savings | ||
params.add(new Object[] {"Pacific/Auckland", LocalDateTime.ofEpochSecond(1727575384L, 0, ZoneOffset.UTC)}); | ||
|
||
// For Sydney timezone, the timestamp 2024-10-06 02:04:06 falls between the transition from 02:00 AM to 03:00 AM for daylight savings | ||
params.add(new Object[] {"Australia/Sydney", LocalDateTime.ofEpochSecond(1728180246L, 0, ZoneOffset.UTC)}); | ||
} | ||
|
||
@Before | ||
public void setup() { | ||
TimeZone.setDefault(timezone); | ||
|
@@ -82,7 +106,7 @@ public void testDateToString() { | |
|
||
@Test | ||
public void testTimestampToString() { | ||
assertEquals(timestamp, MetaStoreUtils.convertTimestampToString(Timestamp.valueOf(timestamp))); | ||
assertEquals(timestampString, MetaStoreUtils.convertTimestampToString(timestamp)); | ||
} | ||
|
||
@Test | ||
|
@@ -92,7 +116,7 @@ public void testStringToDate() { | |
|
||
@Test | ||
public void testStringToTimestamp() { | ||
assertEquals(Timestamp.valueOf(timestamp), MetaStoreUtils.convertStringToTimestamp(timestamp)); | ||
assertEquals(timestamp, MetaStoreUtils.convertStringToTimestamp(timestampString)); | ||
} | ||
|
||
@AfterClass | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TimeZone.setDefault changes the zone for the whole application. In Hive, many things are happening in parallel so this is not something that should be done in utility APIs. It can unpredictable side effects and hard to diagnose race conditions.