Skip to content
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 Postgres: allow handling of java sql date #9554

Merged
merged 5 commits into from
Jan 24, 2022

Conversation

shrodingers
Copy link
Contributor

@shrodingers shrodingers commented Jan 17, 2022

What

Had an issue on a Postgres CDC source, where I have some Postgres date columns, and on the initial load, date object types were Java.sql.Date, which weren't handled properly. This caused a warning to be prompted for every row, and the date format conversion to fall on the default string converter.

How

Added a handler for Java.sql.Date type that can be returned by Debeezium, instead of a repetitive warning causing unreadable logs.

Allow for a specific handler and not the default one.

🚨 User Impact 🚨

Should be none, since it just adds a handler instead of the default one for debeezium based sources

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)<
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • docs/SUMMARY.md
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the connector is published, connector added to connector index as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here

Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the new connector version is published, connector version bumped in the seed directory as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here

Connector Generator

  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed.

@CLAassistant
Copy link

CLAassistant commented Jan 17, 2022

CLA assistant check
All committers have signed the CLA.

@shrodingers shrodingers changed the title fix: allow handling of java sql date 🐛 Debeezium based sources: allow handling of java sql date Jan 17, 2022
@marcosmarxm marcosmarxm added the gl label Jan 18, 2022
@marcosmarxm
Copy link
Member

thanks @shrodingers! I requested to the team review the contribution during this week.

@@ -42,7 +43,10 @@ public static String convertDate(final Object input) {
} else if (input instanceof Number) {
return DataTypeUtils.toISO8601String(
new Timestamp(((Number) input).longValue()).toLocalDateTime());
} else if (input instanceof String) {
} else if (input instanceof Date) {
return DataTypeUtils.toISO8601String(input)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The input has Object type and can't be put as input parameter for the DataTypeUtils.toISO8601String without cast.

@@ -42,7 +43,10 @@ public static String convertDate(final Object input) {
} else if (input instanceof Number) {
return DataTypeUtils.toISO8601String(
new Timestamp(((Number) input).longValue()).toLocalDateTime());
} else if (input instanceof String) {
} else if (input instanceof Date) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please specify the case which you are trying to fix with steps to reproduce.
I've tested your change using CDC MySql Source and there is no any issues with Date type.
More over the class java.sql.Date is not used there.
All columns with Date type processed inside the Debezium as class java.time.LocalDate. Example from data type test:
Screenshot from 2022-01-20 14-20-27

Copy link
Contributor Author

@shrodingers shrodingers Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna update the PR description, im using CDC for PostgreSql for this case (thought it was the same case for all dbs thus my initial description).

I had lots of warning while syncing columns with postgres's type Date looking like :
Uncovered date class type java.sql.Date. Use default converter. Which led me to this part of the code (only happened on the initial migration though, not while consuming the slots).

I had a minimal setup to reproduce this :

  • A postgres table with a date column
  • replication and CDC enabled
  • connection that syncs the table in incremental mode

I log the class name inside the convertDate function, and without this update i have the following log :
image
Maybe it is a postgres only issue, or that i didn't understand how everything works around Debezium, but this is the reason i tried to submit this PR

Copy link
Contributor

@DoNotPanicUA DoNotPanicUA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shrodingers ,
You PR looks good for me, but there are few small things left to do.

  1. As this change will effect only Postgres processing and I will only incr. that version, please rename the PR from Debeezium based sources to Source Postgres.
  2. The formatting check is a part of our build. It means that all changes should be in line with it. So, in order not to brake the master build, please make you changes in line with the changes in my technical PR [#9554 PR] Postgres/Mssql Source: Increase version #9753. (Note that sequence of imports also counts)
    All tests are fine, so after that we can merge your PR and I will bump the version.

@shrodingers shrodingers changed the title 🐛 Debeezium based sources: allow handling of java sql date 🐛 Source Postgres: allow handling of java sql date Jan 24, 2022
@shrodingers
Copy link
Contributor Author

Hi @DoNotPanicUA, thanks for your patience in this review !

  • Just changed the PR title, as it indeed only affected Postgres sources
  • Merged your technical Pr inside mine in order to update it with airbyte's master and fix the formatting issues.
    I'll remain available if there is anything else needed here

Copy link
Contributor

@DoNotPanicUA DoNotPanicUA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@DoNotPanicUA DoNotPanicUA merged commit c83d3aa into airbytehq:master Jan 24, 2022
DoNotPanicUA added a commit that referenced this pull request Jan 25, 2022
* #9554 PR

* format

* incr version for Postgres

* Update docs/integrations/sources/postgres.md

Co-authored-by: Marcos Marx <marcosmarxm@users.noreply.github.com>

* test upd

* test upd

* incr ver for mssql as effected source

Co-authored-by: Marcos Marx <marcosmarxm@users.noreply.github.com>
@DoNotPanicUA
Copy link
Contributor

Hi @shrodingers,
Please be informed that 0.4.3 Postgres version is published and now can be used.
Thank you for your input into our project ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants