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

mysql: add support for invisible columns #31239

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

martykulma
Copy link

@martykulma martykulma commented Jan 29, 2025

To support invisible columns in MySQL, explicitly request columns in snapshot select statement. And while I'm here, I corrected the glob root path in mzcompose.py to get the tests to run.

Motivation

Adds support for invisible columns in mysql

Tips for reviewer

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered. (trigger-ci for additional test/nightly runs)
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).
  • If this PR includes major user-facing behavior changes, I have pinged the relevant PM to schedule a changelog post.

Copy link

github-actions bot commented Jan 29, 2025

All contributors have signed the CLA.
Posted by the CLA Assistant Lite bot.

@martykulma
Copy link
Author

I have read the Contributor License Agreement (CLA) and I hereby sign the CLA.

@martykulma martykulma force-pushed the maz-mysql-invisible-cols branch from f1ec013 to bb7369e Compare January 30, 2025 12:16
@martykulma martykulma marked this pull request as ready for review January 30, 2025 15:01
@martykulma martykulma requested a review from a team as a code owner January 30, 2025 15:01
.iter()
.map(|col_info| format!("`{}`", col_info.name))
})
.join(", ");
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I think this might be doing a different thing than what we need. Here you iterate over all outputs and concatenate the name of the columns from each one of them. So if I understand correctly, if the same table is ingested twice in Materialize we will end up with a query like SELECT col1, col2, col1, col2 and transfer twice the amount of data. Am I reading this right?

Copy link
Author

Choose a reason for hiding this comment

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

excellent point - I hadn't considered that case.

Now that I'm looking back at it, this may also run into time-of-check/time-of-use issues. There's no guarantee that the table definition is the same at the time we issue the select. Which means we need to identify the columns in the transaction that we run the query.. I'll make that change.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's no guarantee that the table definition is the same at the time we issue the select.

That's true, but also fine, because Materialize expects a certain schema that has already been committed in the catalog. So we should explicitly request the columns that we expect to be there, and if they aren't we'll get an error from the MySQL client and report it.

Even if we learned the new schema in the dataflow there isn't anything else we can do at that point. If the user has changed the upstream schema after having created the ingestion in Materialize then the only way out is to drop and recreate the tables in Materialize.

I think what we want to do here is collect the set of columns that each output needs (using something like a BTreeSet) and then make sure that we decode and project the columns in the right order downstream

Copy link
Author

@martykulma martykulma Jan 31, 2025

Choose a reason for hiding this comment

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

🤔 When we build MySqlTableDesc.columns, the intention appears to be that all columns will be in the struct. For ignored columns, column_type is set to None, but the name is maintained. So I expect it's possible to use any entry from outputs for the column names in the table description. I'll check if we have test coverage for it, if not, I'll add something.

@@ -99,7 +99,9 @@ def workflow_cdc(c: Composition, parser: WorkflowArgumentParser) -> None:

matching_files = []
for filter in args.filter:
matching_files.extend(glob.glob(filter, root_dir="test/mysql-cdc"))
matching_files.extend(
glob.glob(filter, root_dir=MZ_ROOT / "test" / "mysql-cdc")
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for this fix! I've been bitten by it!

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

Successfully merging this pull request may close these issues.

2 participants