close
Skip to content

[Fix][Connector-v2] Add DateMilliConvertor to Convert DateMilliVector into Default Timezone#8736

Merged
hailin0 merged 5 commits into
apache:devfrom
TongchengOpenSource:arrow_localdatetime
Feb 18, 2025
Merged

[Fix][Connector-v2] Add DateMilliConvertor to Convert DateMilliVector into Default Timezone#8736
hailin0 merged 5 commits into
apache:devfrom
TongchengOpenSource:arrow_localdatetime

Conversation

@xiaochen-zhou

Copy link
Copy Markdown
Contributor

Purpose of this pull request

Does this PR introduce any user-facing change?

The DateMilliVector type in Apache Arrow stores timestamps in UTC,Add DateMilliConvertor to Convert DateMilliVector into Default Timezone.

How was this patch tested?

exist tests

Check list

@xiaochen-zhou xiaochen-zhou changed the title [Fix][Zeta] Add DateMilliConvertor to Convert DateMilliVector into Default Timezone [Fix][Connector-v2] Add DateMilliConvertor to Convert DateMilliVector into Default Timezone Feb 14, 2025

@Hisoka-X Hisoka-X left a comment

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.

Could you add a test case to cover it?

@xiaochen-zhou

Copy link
Copy Markdown
Contributor Author

Could you add a test case to cover it?

There is already this test case: ArrowToSeatunnelRowReaderTest#testSeatunnelRow(). If this conversion is not added, it may cause this test case to fail, for example, before 8 a.m.

@xiaochen-zhou

Copy link
Copy Markdown
Contributor Author

Could you add a test case to cover it?

Store Timestamp:1739564483396
image

image

@Hisoka-X

Copy link
Copy Markdown
Member

Could you add a test case to cover it?

There is already this test case: ArrowToSeatunnelRowReaderTest#testSeatunnelRow(). If this conversion is not added, it may cause this test case to fail, for example, before 8 a.m.

I think we can use a fixed datetime (not use system time now()) to reproduce this bug.

@Hisoka-X

Copy link
Copy Markdown
Member

If this conversion is not added, it may cause this test case to fail, for example, before 8 a.m.

Any test case failed link?

@xiaochen-zhou

Copy link
Copy Markdown
Contributor Author

If this conversion is not added, it may cause this test case to fail, for example, before 8 a.m.

Any test case failed link?

No, I discovered this during local debugging. This test case is likely to reproduce the issue if run before 8 a.m.

@xiaochen-zhou

Copy link
Copy Markdown
Contributor Author

Could you add a test case to cover it?

Store Timestamp:1739564483396 image

image

@Hisoka-X

@Hisoka-X

Copy link
Copy Markdown
Member

If this conversion is not added, it may cause this test case to fail, for example, before 8 a.m.

Any test case failed link?

No, I discovered this during local debugging. This test case is likely to reproduce the issue if run before 8 a.m.

OK, please add test case.

@xiaochen-zhou

Copy link
Copy Markdown
Contributor Author

Could you add a test case to cover it?

There is already this test case: ArrowToSeatunnelRowReaderTest#testSeatunnelRow(). If this conversion is not added, it may cause this test case to fail, for example, before 8 a.m.

I think we can use a fixed datetime (not use system time now()) to reproduce this bug.

Ok, I will refer to this to add the test case. @Hisoka-X

* on windows The test case uses TimeStampMicroVector to test the timestamp, thus truncating the
* timestamp accuracy to ChronoUnit.MILLIS
*/
private static final LocalDateTime localDateTime =

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.

Suggested change
private static final LocalDateTime localDateTime =
private static final LocalDateTime localDateTime =
LocalDateTime.parse(
"2025-02-15 02:21:23", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

@@ -172,13 +178,7 @@ private static VectorSchemaRoot buildVectorSchemaRoot(
}
// allocate storage
vectors.forEach(FieldVector::allocateNew);

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.

Suggested change
vectors.forEach(FieldVector::allocateNew);
vectors.forEach(FieldVector::allocateNew);
long epochMilli = localDateTime.atZone(zoneId).toInstant().toEpochMilli();

.setSafe(i, (stringValue).getBytes(StandardCharsets.UTF_8));
} else if (vector instanceof TimeStampMicroVector) {
((TimeStampMicroVector) vector).setSafe(i, epochMilli * 1000);
((TimeStampMicroVector) vector).setSafe(i, testEpochMilli);

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.

Suggested change
((TimeStampMicroVector) vector).setSafe(i, testEpochMilli);
((TimeStampMicroVector) vector).setSafe(i, epochMilli * 1000);

.setSafe(i, (stringValue).getBytes(StandardCharsets.UTF_8));
} else if (vector instanceof TimeStampMilliTZVector) {
((TimeStampMilliTZVector) vector).setSafe(i, epochMilli);
((TimeStampMilliTZVector) vector).setSafe(i, testEpochMilli);

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.

Suggested change
((TimeStampMilliTZVector) vector).setSafe(i, testEpochMilli);
((TimeStampMilliTZVector) vector).setSafe(i, epochMilli);

((TimeStampMilliTZVector) vector).setSafe(i, testEpochMilli);
} else if (vector instanceof TimeMicroVector) {
((TimeMicroVector) vector).setSafe(i, epochMilli);
((TimeMicroVector) vector).setSafe(i, testEpochMilli);

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.

ditto

((TimeMicroVector) vector).setSafe(i, testEpochMilli);
} else if (vector instanceof DateMilliVector) {
((DateMilliVector) vector).setSafe(i, epochMilli);
((DateMilliVector) vector).setSafe(i, testEpochMilli);

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.

ditto

List<LocalDateTime> dateTimeList = new ArrayList<>();
for (int j = 0; j < 5; j++) {
writer.writeTimeStampMilliTZ(epochMilli);
writer.writeTimeStampMilliTZ(testEpochMilli);

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.

ditto

@xiaochen-zhou

Copy link
Copy Markdown
Contributor Author

@Hisoka-X @hawk9821 done.

@Hisoka-X Hisoka-X requested a review from hawk9821 February 18, 2025 06:09

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

LGTM. Thanks @xiaochen-zhou

@hailin0 hailin0 merged commit 7b8298a into apache:dev Feb 18, 2025
@xiaochen-zhou xiaochen-zhou deleted the arrow_localdatetime branch February 22, 2025 16:53
zax1314157 pushed a commit to zax1314157/seatunnel that referenced this pull request Feb 24, 2025
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