-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[FLINK-26810][connectors/elasticsearch] Use local timezone for TIMESTAMP_WITH_LOCAL_TIMEZONE fields in dynamic index #19302
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,11 +35,14 @@ | |
| import java.time.LocalDate; | ||
| import java.time.LocalDateTime; | ||
| import java.time.LocalTime; | ||
| import java.time.ZoneId; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.time.temporal.UnsupportedTemporalTypeException; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.jupiter.api.Assumptions.assumingThat; | ||
|
|
||
| /** Suite tests for {@link IndexGenerator}. */ | ||
| public class IndexGeneratorTest { | ||
|
|
||
|
|
@@ -54,6 +57,7 @@ public class IndexGeneratorTest { | |
| "local_datetime", | ||
| "local_date", | ||
| "local_time", | ||
| "local_timestamp", | ||
| "note", | ||
| "status"); | ||
|
|
||
|
|
@@ -68,6 +72,7 @@ public class IndexGeneratorTest { | |
| DataTypes.TIMESTAMP().bridgedTo(LocalDateTime.class), | ||
| DataTypes.DATE().bridgedTo(LocalDate.class), | ||
| DataTypes.TIME().bridgedTo(LocalTime.class), | ||
| DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(), | ||
| DataTypes.STRING(), | ||
| DataTypes.BOOLEAN()); | ||
|
|
||
|
|
@@ -86,6 +91,10 @@ public class IndexGeneratorTest { | |
| LocalDateTime.of(2020, 3, 18, 12, 12, 14, 1000)), | ||
| (int) LocalDate.of(2020, 3, 18).toEpochDay(), | ||
| (int) (LocalTime.of(12, 13, 14, 2000).toNanoOfDay() / 1_000_000L), | ||
| TimestampData.fromInstant( | ||
| LocalDateTime.of(2020, 3, 18, 3, 12, 14, 1000) | ||
| .atZone(ZoneId.of("Asia/Shanghai")) | ||
| .toInstant()), | ||
| "test1", | ||
| true), | ||
| GenericRowData.of( | ||
|
|
@@ -101,9 +110,44 @@ public class IndexGeneratorTest { | |
| LocalDateTime.of(2020, 3, 19, 12, 22, 14, 1000)), | ||
| (int) LocalDate.of(2020, 3, 19).toEpochDay(), | ||
| (int) (LocalTime.of(12, 13, 14, 2000).toNanoOfDay() / 1_000_000L), | ||
| TimestampData.fromInstant( | ||
| LocalDateTime.of(2020, 3, 19, 20, 22, 14, 1000) | ||
| .atZone(ZoneId.of("America/Los_Angeles")) | ||
| .toInstant()), | ||
| "test2", | ||
| false)); | ||
|
|
||
| @Test | ||
| public void testDynamicIndexFromTimestampTzUTC() { | ||
| assumingThat( | ||
| ZoneId.systemDefault().equals(ZoneId.of("UTC")), | ||
| () -> { | ||
| IndexGenerator indexGenerator = | ||
| IndexGeneratorFactory.createIndexGenerator( | ||
| "{local_timestamp|yyyy_MM_dd_HH-ss}_index", | ||
| fieldNames, | ||
| dataTypes); | ||
| indexGenerator.open(); | ||
| Assertions.assertEquals( | ||
| "2020_03_17_19-14_index", indexGenerator.generate(rows.get(0))); | ||
| Assertions.assertEquals( | ||
| "2020_03_20_03-14_index", indexGenerator.generate(rows.get(1))); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDynamicIndexFromTimestampTzWithSpecificTimezone() { | ||
| IndexGenerator indexGenerator = | ||
| IndexGeneratorFactory.createIndexGenerator( | ||
|
Contributor
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. Also here you're using the were you can pass a custom zone, or also the UTC and be independent of the CI's system default for example. |
||
| "{local_timestamp|yyyy_MM_dd_HH-ss}_index", | ||
| fieldNames, | ||
| dataTypes, | ||
| ZoneId.of("Europe/Berlin")); | ||
| indexGenerator.open(); | ||
alpreu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Assertions.assertEquals("2020_03_17_20-14_index", indexGenerator.generate(rows.get(0))); | ||
| Assertions.assertEquals("2020_03_20_04-14_index", indexGenerator.generate(rows.get(1))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDynamicIndexFromTimestamp() { | ||
| IndexGenerator indexGenerator = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,16 +32,19 @@ | |
| import org.junit.Test; | ||
|
|
||
| import java.sql.Timestamp; | ||
| import java.time.Instant; | ||
| import java.time.LocalDate; | ||
| import java.time.LocalDateTime; | ||
| import java.time.LocalTime; | ||
| import java.time.ZoneId; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.time.temporal.UnsupportedTemporalTypeException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assume.assumeThat; | ||
|
|
||
| /** Tests for {@link IndexGeneratorFactory}. */ | ||
| public class IndexGeneratorFactoryTest extends TestLogger { | ||
|
|
||
|
|
@@ -71,7 +74,10 @@ public void prepareData() { | |
| (int) LocalDate.parse("2020-03-18").toEpochDay(), | ||
| (int) (LocalTime.parse("12:12:14").toNanoOfDay() / 1_000_000L), | ||
| TimestampData.fromLocalDateTime(LocalDateTime.parse("2020-03-18T12:12:14")), | ||
| TimestampData.fromInstant(Instant.parse("2020-03-18T12:12:14Z")), | ||
| TimestampData.fromInstant( | ||
| LocalDateTime.of(2020, 3, 18, 3, 12, 14, 1000) | ||
| .atZone(ZoneId.of("Asia/Shanghai")) | ||
| .toInstant()), | ||
| true)); | ||
| rows.add( | ||
| GenericRowData.of( | ||
|
|
@@ -81,7 +87,10 @@ public void prepareData() { | |
| (int) LocalDate.parse("2020-03-19").toEpochDay(), | ||
| (int) (LocalTime.parse("12:22:21").toNanoOfDay() / 1_000_000L), | ||
| TimestampData.fromLocalDateTime(LocalDateTime.parse("2020-03-19T12:22:14")), | ||
| TimestampData.fromInstant(Instant.parse("2020-03-19T12:12:14Z")), | ||
| TimestampData.fromInstant( | ||
| LocalDateTime.of(2020, 3, 19, 20, 22, 14, 1000) | ||
| .atZone(ZoneId.of("America/Los_Angeles")) | ||
| .toInstant()), | ||
| false)); | ||
| } | ||
|
|
||
|
|
@@ -193,12 +202,26 @@ public void testDynamicIndexFromSystemTime() { | |
| } | ||
|
|
||
| @Test | ||
| public void testDynamicIndexDefaultFormatTimestampWithLocalTimeZone() { | ||
| public void testDynamicIndexDefaultFormatTimestampWithLocalTimeZoneUTC() { | ||
| assumeThat(ZoneId.systemDefault(), is(ZoneId.of("UTC"))); | ||
|
Contributor
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. Why not use the same scheme with
Contributor
Author
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. The tests under
Contributor
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. No, then it's fine as is, no need to change. |
||
|
|
||
| IndexGenerator indexGenerator = | ||
| IndexGeneratorFactory.createIndexGenerator("my-index-{local_timestamp|}", schema); | ||
| indexGenerator.open(); | ||
| Assert.assertEquals("my-index-2020_03_18_12_12_14Z", indexGenerator.generate(rows.get(0))); | ||
| Assert.assertEquals("my-index-2020_03_19_12_12_14Z", indexGenerator.generate(rows.get(1))); | ||
| Assert.assertEquals("my-index-2020_03_17_19_12_14Z", indexGenerator.generate(rows.get(0))); | ||
| Assert.assertEquals("my-index-2020_03_20_03_22_14Z", indexGenerator.generate(rows.get(1))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDynamicIndexDefaultFormatTimestampWithLocalTimeZoneWithSpecificTimeZone() { | ||
| IndexGenerator indexGenerator = | ||
| IndexGeneratorFactory.createIndexGenerator( | ||
| "my-index-{local_timestamp|}", schema, ZoneId.of("Europe/Berlin")); | ||
| indexGenerator.open(); | ||
| Assert.assertEquals( | ||
| "my-index-2020_03_17_20_12_14+01", indexGenerator.generate(rows.get(0))); | ||
| Assert.assertEquals( | ||
| "my-index-2020_03_20_04_22_14+01", indexGenerator.generate(rows.get(1))); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
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.
nice!