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

adapter: correctly report custom types in mz_columns #27318

Merged
merged 1 commit into from
May 28, 2024

Conversation

benesch
Copy link
Member

@benesch benesch commented May 27, 2024

For columns with a type of list, map, or record, the mz_columns table was incorrectly reporting the generic psuedotype for the column, even when the type was a named type in the catalog.

For example, given the following objects:

CREATE TYPE my_rec AS (x int, y int);
CREATE TABLE my_tab (f1 my_rec);

the mz_columns table would incorrectly report that column f1 had type record (OID 2249), rather than type my_rec with a dynamic OID determined at envd boot.

This commit is a surgical fix that fixes the immediate issue.

In the future, we may want to consider a deeper fix that makes the conversion between a ScalarType and a pg_repr::Type less prone to this sort of bug. That is a much larger refactor, however.

We'll also want to deprecate mz_columns.type in the future, for the reasons noted in the comment in the patch. That too is left to future work for expediency.

Motivation

  • This PR fixes a previously unreported bug.

    This is preventing the dbt-materialize adapter from properly enforcing contracts against custom record, list, and map types.

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).
  • This PR includes the following user-facing behavior changes:
    • Correct mz_columns.type and mz_columns.type_oid when the column's type is a custom named record, list, or map. Previously, Materialize reported the generic psuedotype (record, list, or map, respectively); now Materialize reports the specific name of the custom named type.

@benesch benesch requested a review from a team as a code owner May 27, 2024 22:51
..
} => {
let entry = self.get_entry(custom_id);
// NOTE(benesch): the `mz_columns.type text` field is
Copy link
Contributor

Choose a reason for hiding this comment

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

fwiw regtype should resolve the OID to the right entry

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, and you can join mz_columns.type_oid against mz_types.oid by hand! It's just at odds with the rest of the mz_catalog tables that you have to do the join with OID compatibility layer instead of being able to do it with Materialize's native global IDs.

@benesch
Copy link
Member Author

benesch commented May 28, 2024

Got a little spooked that no tests failed, so pushed up a new test file with some cases that would have failed before this change.

Copy link
Contributor

@morsapaes morsapaes left a comment

Choose a reason for hiding this comment

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

Thanks, @benesch!

src/adapter/src/catalog/builtin_table_updates.rs Outdated Show resolved Hide resolved
src/adapter/src/catalog/builtin_table_updates.rs Outdated Show resolved Hide resolved
For columns with a type of list, map, or record, the mz_columns table
was incorrectly reporting the generic psuedotype for the column, even
when the type was a named type in the catalog.

For example, given the following objects:

    CREATE TYPE my_rec AS (x int, y int);
    CREATE TABLE my_tab (f1 my_rec);

the mz_columns table would incorrectly report that column f1 had type
record (OID 2249), rather than type my_rec with a dynamic OID determined
at envd boot.

This commit is a surgical fix that fixes the immediate issue.

In the future, we may want to consider a deeper fix that makes the
conversion between a `ScalarType` and a `pg_repr::Type` less prone to
this sort of bug. That is a much larger refactor, however.

We'll also want to deprecate `mz_columns.type` in the future, for the
reasons noted in the comment in the patch. That too is left to future
work for expediency.
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.

3 participants