-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[source-mysql] 7084 source mysql regression in 39x date parsing errors #49932
Merged
rodireich
merged 7 commits into
master
from
7084-source-mysql--regression-in-39x-date-parsing-errors
Dec 19, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
93d4296
Parse incoming state timestamp with timezone allowing all variations …
rodireich 62b2e04
Parse incoming state timestamp with timezone allowing all variations …
rodireich 6b4f5de
Parse incoming state timestamp with timezone allowing all variations …
rodireich 608bfce
Parse incoming state timestamp with timezone allowing all variations …
rodireich eba5501
Merge branch 'master' into 7084-source-mysql--regression-in-39x-date-…
rodireich d8f8d0b
sanity
rodireich 3ad147f
sanity
rodireich 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 |
---|---|---|
|
@@ -28,8 +28,11 @@ import io.airbyte.cdk.util.Jsons | |
import io.micronaut.context.annotation.Primary | ||
import jakarta.inject.Singleton | ||
import java.time.LocalDateTime | ||
import java.time.OffsetDateTime | ||
import java.time.ZoneOffset.UTC | ||
import java.time.format.DateTimeFormatter | ||
import java.time.format.DateTimeFormatterBuilder | ||
import java.time.format.DateTimeParseException | ||
import java.time.temporal.ChronoField | ||
import java.util.* | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
@@ -350,15 +353,29 @@ class MysqlJdbcPartitionFactory( | |
} | ||
LeafAirbyteSchemaType.TIMESTAMP_WITH_TIMEZONE -> { | ||
val timestampInStatePattern = "yyyy-MM-dd'T'HH:mm:ss" | ||
val formatter = | ||
DateTimeFormatterBuilder() | ||
.appendPattern(timestampInStatePattern) | ||
.optionalStart() | ||
.appendFraction(ChronoField.NANO_OF_SECOND, 1, 9, true) | ||
.optionalEnd() | ||
.optionalStart() | ||
.optionalStart() | ||
.appendLiteral(' ') | ||
.optionalEnd() | ||
.appendOffset("+HH:mm", "Z") | ||
.optionalEnd() | ||
.toFormatter() | ||
|
||
try { | ||
val formatter: DateTimeFormatter = | ||
DateTimeFormatter.ofPattern(timestampInStatePattern) | ||
Jsons.valueToTree( | ||
LocalDateTime.parse(stateValue, formatter) | ||
.minusDays(1) | ||
.atOffset(java.time.ZoneOffset.UTC) | ||
.format(OffsetDateTimeCodec.formatter) | ||
) | ||
val offsetDateTime = | ||
try { | ||
OffsetDateTime.parse(stateValue, formatter) | ||
} catch (_: DateTimeParseException) { | ||
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. If value include no |
||
// if no offset exists, we assume it's UTC | ||
LocalDateTime.parse(stateValue, formatter).atOffset(UTC) | ||
} | ||
Jsons.valueToTree(offsetDateTime.format(OffsetDateTimeCodec.formatter)) | ||
} catch (_: RuntimeException) { | ||
// Resolve to use the new format. | ||
Jsons.valueToTree<JsonNode>(stateValue) | ||
|
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 |
---|---|---|
|
@@ -37,6 +37,8 @@ import kotlin.test.assertNull | |
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.CsvSource | ||
|
||
class MysqlJdbcPartitionFactoryTest { | ||
companion object { | ||
|
@@ -219,13 +221,28 @@ class MysqlJdbcPartitionFactoryTest { | |
assertTrue(jdbcPartition is MysqlJdbcCursorIncrementalPartition) | ||
} | ||
|
||
@Test | ||
fun testResumeFromCompletedCursorBasedReadTimestamp() { | ||
@ParameterizedTest | ||
@CsvSource( | ||
"'2025-09-03T05:23:35', '2025-09-03T05:23:35.000000Z'", | ||
"'2025-09-03T05:23:35.0', '2025-09-03T05:23:35.000000Z'", | ||
"'2025-09-03T05:23:35.1', '2025-09-03T05:23:35.100000Z'", | ||
"'2025-09-03T05:23:35.123', '2025-09-03T05:23:35.123000Z'", | ||
"'2025-09-03T05:23:35.123456789', '2025-09-03T05:23:35.123456Z'", | ||
"'2025-09-03T05:23:35.123+00:00', '2025-09-03T05:23:35.123000Z'", | ||
"'2025-09-03T05:23:35.123+00:00', '2025-09-03T05:23:35.123000Z'", | ||
"'2025-09-03T05:23:35Z', '2025-09-03T05:23:35.000000Z'", | ||
"'2025-09-03T05:23:35 Z', '2025-09-03T05:23:35.000000Z'", | ||
"'2025-09-03T05:23:35.12345 +12:34', '2025-09-03T05:23:35.123450+12:34'", | ||
) | ||
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. excellent |
||
fun testResumeFromCompletedCursorBasedReadTimestamp( | ||
cursorVal: String, | ||
expectedLowerBound: String | ||
) { | ||
val incomingStateValue: OpaqueStateValue = | ||
Jsons.readTree( | ||
""" | ||
{ | ||
"cursor": "2025-09-03T05:23:35", | ||
"cursor": "$cursorVal", | ||
"version": 2, | ||
"state_type": "cursor_based", | ||
"stream_name": "stream2", | ||
|
@@ -245,7 +262,7 @@ class MysqlJdbcPartitionFactoryTest { | |
assertTrue(jdbcPartition is MysqlJdbcCursorIncrementalPartition) | ||
|
||
assertEquals( | ||
Jsons.valueToTree("2025-09-02T05:23:35.000000Z"), | ||
Jsons.valueToTree("$expectedLowerBound"), | ||
(jdbcPartition as MysqlJdbcCursorIncrementalPartition).cursorLowerBound | ||
) | ||
} | ||
|
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
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.
This is painful 😓
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.
I found chatgpt useful for generating this kind of code. Even so, it's still annoying.
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.
It actually gave me wrong advice here, much to my delight
maybe humans still got a chance 🤭
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.
yay humans!