-
Notifications
You must be signed in to change notification settings - Fork 71
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
fix: Fix SQL type merging for pre-existing target tables #898
fix: Fix SQL type merging for pre-existing target tables #898
Conversation
…exiting-table-merge-sql-types
Codecov Report
@@ Coverage Diff @@
## main #898 +/- ##
==========================================
- Coverage 81.25% 81.18% -0.08%
==========================================
Files 36 36
Lines 3543 3555 +12
Branches 712 718 +6
==========================================
+ Hits 2879 2886 +7
- Misses 489 492 +3
- Partials 175 177 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Hi @BuzzCutNorman, this came up while working on #904. This seems like an important bug so thanks for tackling it! Your patch does seem to work, so let me know when it's ready for the team to review 😄 cc @aaronsteers |
Hi @edgarrmondragon, Yay!!! I am glad to hear it worked for you. 🥳 I found after some testing there is some code I need to remove. I won't be able to get to it today but am planning to clean it up Monday. cc @aaronsteers |
…exiting-table-merge-sql-types
I like what you did better than my idea! Took me a second to understand it. I'll play with this fix in |
Yes, please test a ton. I did some checks with the StackOverflow database but that doesn't have that many column types. I just removed the |
Tried running this with a test on |
@edgarrmondragon @aaronsteers Looks like there are still issues with this approach. I am going to put this back to draft until I can look at the areas @visch highlighted. |
…exiting-table-merge-sql-types
Reviewing
SetupMy source is 5000 row version of the User table from the StackOverflow database on a mssql server 2019 server I ran a
The newly created table in postgres looks like this.
I added the following logging in the
TestingFirst thing I noticed is the table when created is not copying over the length of varchar columns present in the source to the target. I will truncate the
The majority of matches where Lets pick on the
They were a
It is still seen as a
On the target I dropped the
Everything was a
Since it failed the
Again the initial I am going to change to a single string to string check ( |
@edgarrmondragon I have completed reviewing the comments @visch made during his review and made changes to address them. I also attempted a refresh of I also have a couple of questions:
|
…exiting-table-merge-sql-types
…exiting-table-merge-sql-types
…exiting-table-merge-sql-types
…exiting-table-merge-sql-types
@BuzzCutNorman - re:
I think there may be cases where the column types might be the same, or at least equivalent with each other. Equivalence is probably more likely than equality but just to be safe, I think an equality check probably does make sense within the method. Some types are not 'identical' even though they are 'equivalent'. For instance, in Redshift,
I'm not sure I fully understand the question, but in case it helps, I do think the SDK should (eventually) know how to auto-expand from A bit of a tangent, but it could also nice if the developer can choose to always bias towards larger data types if they prefer, something like
I think the goal here with What do you think? |
@aaronsteers I agree. Once developers start filing bugs and feature requests, we can start figuring what parts make sense to abstract away from them and which to expose in the "public" API. I think that's been the general approach for the trickier or more niche features in the SDK. For now, as rule of thumb, we could be contempt with supporting SQLite and Postgres DDL. |
@aaronsteers, @edgarrmondragon Thank you for answering my questions. Yes, you did help me understand better how you want to shape target table columns to match a source, how developers should interact and extend this process, and the dialects you initially want to support. This all sounds great to me. The only item not touch on was sql enginge conversions. Examples are integers inserted into a varchar column or integers inserted into a numeric column. The conversions that happen automagically when working with sql. Please let me know if you want to move forward with the code as it is now and work on the items above in subsequent PRs or would you like me to attempt to incorporate all or some of the items you mentioned into this PR? |
🙌 🙏
Agreed, this part is pretty hard. Generally, I think of this as This more advanced accommodation though, is not something we have to tackle right away. And arguably, there are strong benefits to keeping all historic data in the same column even if it makes for some awkward type casing.
I love what you have so far and I don't think we can/should try to solve every case at once. @edgarrmondragon - I'll look to you for the code signoff/approval side. If this is working and provides and improvement over what we had previously, it seems to be to be is a valuable + stable increment. |
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.
@BuzzCutNorman this looks great! Thanks for taking the time to contribute 😄. Codecov's complaining about a couple of branches not being covered but they're alright to me.
This is a attempt at fixing issue 374. The solution looks to see if the current table column type can accommodate the new type and if it can't it calls the
merge_sql_type()
function and alters the table as before.closes #374