-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapter: correctly report custom types in mz_columns
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.
- Loading branch information
Showing
2 changed files
with
81 additions
and
3 deletions.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright Materialize, Inc. and contributors. All rights reserved. | ||
# | ||
# Use of this software is governed by the Business Source License | ||
# included in the LICENSE file at the root of this repository. | ||
# | ||
# As of the Change Date specified in that file, in accordance with | ||
# the Business Source License, use of this software will be governed | ||
# by the Apache License, Version 2.0. | ||
|
||
mode cockroach | ||
|
||
statement ok | ||
CREATE TYPE r AS (a int) | ||
|
||
statement ok | ||
CREATE TYPE l AS LIST (ELEMENT TYPE = int) | ||
|
||
statement ok | ||
CREATE TYPE m AS MAP (KEY TYPE = text, VALUE TYPE = int) | ||
|
||
statement ok | ||
CREATE VIEW v AS SELECT | ||
row(1) AS ra, | ||
row(1)::r AS rn, | ||
list[]::int list AS la, | ||
list[]::l AS ln, | ||
map[]::map[text=>int] AS ma, | ||
'{}'::m AS mn | ||
|
||
# We intentionally don't assert on the `c.type_oid` or `t.id` columns, as | ||
# IDs are not stable. Instead, we ensure that the `c.type_oid` column can be | ||
# used to look up the type in the `mz_types` table and that the ID is | ||
# as expected (system or user). | ||
query TTTIT | ||
SELECT | ||
c.position, c.name, c.type, c.type_mod, left(t.id, 1) | ||
FROM mz_columns c | ||
JOIN mz_views v ON c.id = v.id | ||
JOIN mz_types t ON c.type_oid = t.oid | ||
WHERE v.name = 'v' | ||
ORDER BY c.position | ||
---- | ||
1 ra record -1 s | ||
2 rn r -1 u | ||
3 la list -1 s | ||
4 ln l -1 u | ||
5 ma map -1 s | ||
6 mn m -1 u |