1use std::collections::BTreeMap;
13use std::sync::LazyLock;
14
15use mz_catalog_protos::objects::CatalogItemType;
16use mz_pgrepr::oid;
17use mz_repr::namespaces::MZ_CATALOG_SCHEMA;
18use mz_repr::{RelationDesc, SemanticType, SqlScalarType};
19use mz_sql::catalog::{
20 CatalogType, CatalogTypeDetails, CatalogTypePgMetadata, NameReference, ObjectType,
21};
22use mz_sql::rbac;
23use mz_sql::session::user::{MZ_SYSTEM_ROLE_ID, SUPPORT_USER_NAME, SYSTEM_USER_NAME};
24use mz_storage_client::controller::IntrospectionType;
25
26use super::builtin::gid_mapping_object_type;
27use super::{
28 BuiltinIndex, BuiltinMaterializedView, BuiltinSource, BuiltinTable, BuiltinType, BuiltinView,
29 Cardinality, LinkProperties, Ontology, OntologyLink, PUBLIC_SELECT,
30};
31
32pub const TYPE_LIST: BuiltinType<NameReference> = BuiltinType {
33 name: "list",
34 schema: MZ_CATALOG_SCHEMA,
35 oid: mz_pgrepr::oid::TYPE_LIST_OID,
36 details: CatalogTypeDetails {
37 typ: CatalogType::Pseudo,
38 array_id: None,
39 pg_metadata: None,
40 },
41};
42
43pub const TYPE_MAP: BuiltinType<NameReference> = BuiltinType {
44 name: "map",
45 schema: MZ_CATALOG_SCHEMA,
46 oid: mz_pgrepr::oid::TYPE_MAP_OID,
47 details: CatalogTypeDetails {
48 typ: CatalogType::Pseudo,
49 array_id: None,
50 pg_metadata: None,
51 },
52};
53
54pub const TYPE_ANYCOMPATIBLELIST: BuiltinType<NameReference> = BuiltinType {
55 name: "anycompatiblelist",
56 schema: MZ_CATALOG_SCHEMA,
57 oid: mz_pgrepr::oid::TYPE_ANYCOMPATIBLELIST_OID,
58 details: CatalogTypeDetails {
59 typ: CatalogType::Pseudo,
60 array_id: None,
61 pg_metadata: None,
62 },
63};
64
65pub const TYPE_ANYCOMPATIBLEMAP: BuiltinType<NameReference> = BuiltinType {
66 name: "anycompatiblemap",
67 schema: MZ_CATALOG_SCHEMA,
68 oid: mz_pgrepr::oid::TYPE_ANYCOMPATIBLEMAP_OID,
69 details: CatalogTypeDetails {
70 typ: CatalogType::Pseudo,
71 array_id: None,
72 pg_metadata: None,
73 },
74};
75
76pub const TYPE_UINT2: BuiltinType<NameReference> = BuiltinType {
77 name: "uint2",
78 schema: MZ_CATALOG_SCHEMA,
79 oid: mz_pgrepr::oid::TYPE_UINT2_OID,
80 details: CatalogTypeDetails {
81 typ: CatalogType::UInt16,
82 array_id: None,
83 pg_metadata: None,
84 },
85};
86
87pub const TYPE_UINT2_ARRAY: BuiltinType<NameReference> = BuiltinType {
88 name: "_uint2",
89 schema: MZ_CATALOG_SCHEMA,
90 oid: mz_pgrepr::oid::TYPE_UINT2_ARRAY_OID,
91 details: CatalogTypeDetails {
92 typ: CatalogType::Array {
93 element_reference: TYPE_UINT2.name,
94 },
95 array_id: None,
96 pg_metadata: None,
97 },
98};
99
100pub const TYPE_UINT4: BuiltinType<NameReference> = BuiltinType {
101 name: "uint4",
102 schema: MZ_CATALOG_SCHEMA,
103 oid: mz_pgrepr::oid::TYPE_UINT4_OID,
104 details: CatalogTypeDetails {
105 typ: CatalogType::UInt32,
106 array_id: None,
107 pg_metadata: None,
108 },
109};
110
111pub const TYPE_UINT4_ARRAY: BuiltinType<NameReference> = BuiltinType {
112 name: "_uint4",
113 schema: MZ_CATALOG_SCHEMA,
114 oid: mz_pgrepr::oid::TYPE_UINT4_ARRAY_OID,
115 details: CatalogTypeDetails {
116 typ: CatalogType::Array {
117 element_reference: TYPE_UINT4.name,
118 },
119 array_id: None,
120 pg_metadata: None,
121 },
122};
123
124pub const TYPE_UINT8: BuiltinType<NameReference> = BuiltinType {
125 name: "uint8",
126 schema: MZ_CATALOG_SCHEMA,
127 oid: mz_pgrepr::oid::TYPE_UINT8_OID,
128 details: CatalogTypeDetails {
129 typ: CatalogType::UInt64,
130 array_id: None,
131 pg_metadata: None,
132 },
133};
134
135pub const TYPE_UINT8_ARRAY: BuiltinType<NameReference> = BuiltinType {
136 name: "_uint8",
137 schema: MZ_CATALOG_SCHEMA,
138 oid: mz_pgrepr::oid::TYPE_UINT8_ARRAY_OID,
139 details: CatalogTypeDetails {
140 typ: CatalogType::Array {
141 element_reference: TYPE_UINT8.name,
142 },
143 array_id: None,
144 pg_metadata: None,
145 },
146};
147
148pub const TYPE_MZ_TIMESTAMP: BuiltinType<NameReference> = BuiltinType {
149 name: "mz_timestamp",
150 schema: MZ_CATALOG_SCHEMA,
151 oid: mz_pgrepr::oid::TYPE_MZ_TIMESTAMP_OID,
152 details: CatalogTypeDetails {
153 typ: CatalogType::MzTimestamp,
154 array_id: None,
155 pg_metadata: None,
156 },
157};
158
159pub const TYPE_MZ_TIMESTAMP_ARRAY: BuiltinType<NameReference> = BuiltinType {
160 name: "_mz_timestamp",
161 schema: MZ_CATALOG_SCHEMA,
162 oid: mz_pgrepr::oid::TYPE_MZ_TIMESTAMP_ARRAY_OID,
163 details: CatalogTypeDetails {
164 typ: CatalogType::Array {
165 element_reference: TYPE_MZ_TIMESTAMP.name,
166 },
167 array_id: None,
168 pg_metadata: None,
169 },
170};
171
172pub const TYPE_MZ_ACL_ITEM: BuiltinType<NameReference> = BuiltinType {
173 name: "mz_aclitem",
174 schema: MZ_CATALOG_SCHEMA,
175 oid: mz_pgrepr::oid::TYPE_MZ_ACL_ITEM_OID,
176 details: CatalogTypeDetails {
177 typ: CatalogType::MzAclItem,
178 array_id: None,
179 pg_metadata: None,
180 },
181};
182
183pub const TYPE_MZ_ACL_ITEM_ARRAY: BuiltinType<NameReference> = BuiltinType {
184 name: "_mz_aclitem",
185 schema: MZ_CATALOG_SCHEMA,
186 oid: mz_pgrepr::oid::TYPE_MZ_ACL_ITEM_ARRAY_OID,
187 details: CatalogTypeDetails {
188 typ: CatalogType::Array {
189 element_reference: TYPE_MZ_ACL_ITEM.name,
190 },
191 array_id: None,
192 pg_metadata: Some(CatalogTypePgMetadata {
193 typinput_oid: 750,
194 typreceive_oid: 2400,
195 typsend_oid: 2401,
196 }),
197 },
198};
199
200pub static MZ_ICEBERG_SINKS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
201 BuiltinMaterializedView {
202 name: "mz_iceberg_sinks",
203 schema: MZ_CATALOG_SCHEMA,
204 oid: oid::MV_MZ_ICEBERG_SINKS_OID,
205 desc: RelationDesc::builder()
206 .with_column("id", SqlScalarType::String.nullable(false))
207 .with_column("namespace", SqlScalarType::String.nullable(false))
208 .with_column("table", SqlScalarType::String.nullable(false))
209 .finish(),
210 column_comments: BTreeMap::from_iter([
211 ("id", "The ID of the sink."),
212 (
213 "namespace",
214 "The namespace of the Iceberg table into which the sink is writing.",
215 ),
216 ("table", "The Iceberg table into which the sink is writing."),
217 ]),
218 sql: "
220IN CLUSTER mz_catalog_server
221WITH (
222 ASSERT NOT NULL id,
223 ASSERT NOT NULL namespace,
224 ASSERT NOT NULL \"table\"
225) AS
226SELECT
227 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
228 parsed->>'namespace' AS namespace,
229 parsed->>'table' AS \"table\"
230FROM
231 mz_internal.mz_catalog_raw
232 CROSS JOIN LATERAL (
233 SELECT mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')
234 ) AS l(parsed)
235WHERE
236 data->>'kind' = 'Item' AND
237 parsed->>'sink_type' = 'iceberg'",
238 is_retained_metrics_object: false,
239 access: vec![PUBLIC_SELECT],
240 ontology: Some(Ontology {
241 entity_name: "iceberg_sink",
242 description: "Iceberg-specific sink configuration (namespace, table)",
243 links: &const {
244 [OntologyLink {
245 name: "details_of",
246 target: "sink",
247 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
248 }]
249 },
250 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
251 }),
252 }
253});
254
255pub static MZ_KAFKA_SINKS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
256 BuiltinMaterializedView {
257 name: "mz_kafka_sinks",
258 schema: MZ_CATALOG_SCHEMA,
259 oid: oid::MV_MZ_KAFKA_SINKS_OID,
260 desc: RelationDesc::builder()
261 .with_column("id", SqlScalarType::String.nullable(false))
262 .with_column("topic", SqlScalarType::String.nullable(false))
263 .with_key(vec![0])
264 .finish(),
265 column_comments: BTreeMap::from_iter([
266 ("id", "The ID of the sink."),
267 (
268 "topic",
269 "The name of the Kafka topic into which the sink is writing.",
270 ),
271 ]),
272 sql: "
274IN CLUSTER mz_catalog_server
275WITH (
276 ASSERT NOT NULL id,
277 ASSERT NOT NULL topic
278) AS
279SELECT
280 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
281 parsed->>'topic' AS topic
282FROM
283 mz_internal.mz_catalog_raw
284 CROSS JOIN LATERAL (
285 SELECT mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')
286 ) AS l(parsed)
287WHERE
288 data->>'kind' = 'Item' AND
289 parsed->>'sink_type' = 'kafka'",
290 is_retained_metrics_object: false,
291 access: vec![PUBLIC_SELECT],
292 ontology: Some(Ontology {
293 entity_name: "kafka_sink",
294 description: "Kafka-specific sink configuration (topic)",
295 links: &const {
296 [OntologyLink {
297 name: "details_of",
298 target: "sink",
299 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
300 }]
301 },
302 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
303 }),
304 }
305});
306pub static MZ_KAFKA_CONNECTIONS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
313 BuiltinMaterializedView {
314 name: "mz_kafka_connections",
315 schema: MZ_CATALOG_SCHEMA,
316 oid: oid::MV_MZ_KAFKA_CONNECTIONS_OID,
317 desc: RelationDesc::builder()
318 .with_column("id", SqlScalarType::String.nullable(false))
319 .with_column(
320 "brokers",
321 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
322 )
323 .with_column("sink_progress_topic", SqlScalarType::String.nullable(false))
324 .with_key(vec![0])
325 .finish(),
326 column_comments: BTreeMap::from_iter([
327 ("id", "The ID of the connection."),
328 (
329 "brokers",
330 "The addresses of the Kafka brokers to connect to.",
331 ),
332 (
333 "sink_progress_topic",
334 "The name of the Kafka topic where any sinks associated with this connection will track their progress information and other metadata. The contents of this topic are unspecified.",
335 ),
336 ]),
337 sql: "
341IN CLUSTER mz_catalog_server
342WITH (
343 ASSERT NOT NULL id,
344 ASSERT NOT NULL brokers,
345 ASSERT NOT NULL sink_progress_topic
346) AS
347SELECT
348 mz_internal.parse_catalog_id(r.data->'key'->'gid') AS id,
349 ARRAY(
350 SELECT b.value
351 FROM jsonb_array_elements_text(details->'brokers')
352 WITH ORDINALITY AS b(value, ord)
353 ORDER BY b.ord
354 ) AS brokers,
355 COALESCE(
356 details->>'progress_topic',
357 '_materialize-progress-' || mz_environment_id() || '-'
358 || mz_internal.parse_catalog_id(r.data->'key'->'gid')
359 ) AS sink_progress_topic
360FROM
361 mz_internal.mz_catalog_raw r,
362 LATERAL (
363 SELECT mz_internal.parse_connection_details(
364 r.data->'value'->'definition'->'V1'->>'create_sql')
365 ) AS d(details)
366WHERE
367 r.data->>'kind' = 'Item' AND
368 -- The connection_type filter selects the kind. A non-matching row yields a
369 -- NULL connection_type and is dropped here, so no `details IS NOT NULL` is
370 -- needed (parse_connection_details returns jsonb null, which passes it).
371 mz_internal.parse_catalog_create_sql(
372 r.data->'value'->'definition'->'V1'->>'create_sql')->>'connection_type' = 'kafka'",
373 is_retained_metrics_object: false,
374 access: vec![PUBLIC_SELECT],
375 ontology: Some(Ontology {
376 entity_name: "kafka_connection",
377 description: "Kafka-specific connection configuration (brokers, progress topic)",
378 links: &const {
379 [OntologyLink {
380 name: "details_of",
381 target: "connection",
382 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
383 }]
384 },
385 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
386 }),
387 }
388});
389pub static MZ_KAFKA_SOURCES: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
390 BuiltinMaterializedView {
391 name: "mz_kafka_sources",
392 schema: MZ_CATALOG_SCHEMA,
393 oid: oid::MV_MZ_KAFKA_SOURCES_OID,
394 desc: RelationDesc::builder()
395 .with_column("id", SqlScalarType::String.nullable(false))
396 .with_column("group_id_prefix", SqlScalarType::String.nullable(false))
397 .with_column("topic", SqlScalarType::String.nullable(false))
398 .with_key(vec![0])
399 .finish(),
400 column_comments: BTreeMap::from_iter([
401 (
402 "id",
403 "The ID of the Kafka source. Corresponds to `mz_catalog.mz_sources.id`.",
404 ),
405 (
406 "group_id_prefix",
407 "The value of the `GROUP ID PREFIX` connection option.",
408 ),
409 (
410 "topic",
411 "The name of the Kafka topic the source is reading from.",
412 ),
413 ]),
414 sql: "
419IN CLUSTER mz_catalog_server
420WITH (
421 ASSERT NOT NULL id,
422 ASSERT NOT NULL group_id_prefix,
423 ASSERT NOT NULL topic
424) AS
425SELECT
426 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
427 COALESCE(details->>'group_id_prefix', '')
428 || 'materialize-' || mz_environment_id()
429 || '-' || (details->>'connection_id')
430 || '-' || mz_internal.parse_catalog_id(data->'value'->'global_id')
431 AS group_id_prefix,
432 details->>'topic' AS topic
433FROM
434 mz_internal.mz_catalog_raw,
435 LATERAL (
436 SELECT mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')
437 ) AS l(parsed),
438 LATERAL (
439 SELECT mz_internal.parse_kafka_source_details(data->'value'->'definition'->'V1'->>'create_sql')
440 ) AS d(details)
441WHERE
442 data->>'kind' = 'Item' AND
443 parsed->>'source_type' = 'kafka'",
444 is_retained_metrics_object: false,
445 access: vec![PUBLIC_SELECT],
446 ontology: Some(Ontology {
447 entity_name: "kafka_source",
448 description: "Kafka-specific source configuration (topic, group ID)",
449 links: &const {
450 [OntologyLink {
451 name: "details_of",
452 target: "source",
453 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
454 }]
455 },
456 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
457 }),
458 }
459});
460
461pub static MZ_DATABASES: LazyLock<BuiltinMaterializedView> =
462 LazyLock::new(|| BuiltinMaterializedView {
463 name: "mz_databases",
464 schema: MZ_CATALOG_SCHEMA,
465 oid: oid::MV_MZ_DATABASES_OID,
466 desc: RelationDesc::builder()
467 .with_column("id", SqlScalarType::String.nullable(false))
468 .with_column("oid", SqlScalarType::Oid.nullable(false))
469 .with_column("name", SqlScalarType::String.nullable(false))
470 .with_column("owner_id", SqlScalarType::String.nullable(false))
471 .with_column(
472 "privileges",
473 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
474 )
475 .with_key(vec![0])
476 .with_key(vec![1])
477 .finish(),
478 column_comments: BTreeMap::from_iter([
479 ("id", "Materialize's unique ID for the database."),
480 ("oid", "A PostgreSQL-compatible OID for the database."),
481 ("name", "The name of the database."),
482 (
483 "owner_id",
484 "The role ID of the owner of the database. Corresponds to `mz_roles.id`.",
485 ),
486 ("privileges", "The privileges belonging to the database."),
487 ]),
488 sql: "
489IN CLUSTER mz_catalog_server
490WITH (
491 ASSERT NOT NULL id,
492 ASSERT NOT NULL oid,
493 ASSERT NOT NULL name,
494 ASSERT NOT NULL owner_id,
495 ASSERT NOT NULL privileges
496) AS
497SELECT
498 mz_internal.parse_catalog_id(data->'key'->'id') AS id,
499 (data->'value'->>'oid')::oid AS oid,
500 data->'value'->>'name' AS name,
501 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
502 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges
503FROM mz_internal.mz_catalog_raw
504WHERE data->>'kind' = 'Database'",
505 is_retained_metrics_object: false,
506 access: vec![PUBLIC_SELECT],
507 ontology: Some(Ontology {
508 entity_name: "database",
509 description: "A top-level namespace that contains schemas",
510 links: &const {
511 [OntologyLink {
512 name: "owned_by",
513 target: "role",
514 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
515 }]
516 },
517 column_semantic_types: &const {
518 [
519 ("id", SemanticType::DatabaseId),
520 ("oid", SemanticType::OID),
521 ("owner_id", SemanticType::RoleId),
522 ]
523 },
524 }),
525 });
526
527pub static MZ_SCHEMAS: LazyLock<BuiltinMaterializedView> =
528 LazyLock::new(|| BuiltinMaterializedView {
529 name: "mz_schemas",
530 schema: MZ_CATALOG_SCHEMA,
531 oid: oid::MV_MZ_SCHEMAS_OID,
532 desc: RelationDesc::builder()
533 .with_column("id", SqlScalarType::String.nullable(false))
534 .with_column("oid", SqlScalarType::Oid.nullable(false))
535 .with_column("database_id", SqlScalarType::String.nullable(true))
536 .with_column("name", SqlScalarType::String.nullable(false))
537 .with_column("owner_id", SqlScalarType::String.nullable(false))
538 .with_column(
539 "privileges",
540 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
541 )
542 .with_key(vec![0])
543 .with_key(vec![1])
544 .finish(),
545 column_comments: BTreeMap::from_iter([
546 ("id", "Materialize's unique ID for the schema."),
547 ("oid", "A PostgreSQL-compatible oid for the schema."),
548 (
549 "database_id",
550 "The ID of the database containing the schema. Corresponds to `mz_databases.id`.",
551 ),
552 ("name", "The name of the schema."),
553 (
554 "owner_id",
555 "The role ID of the owner of the schema. Corresponds to `mz_roles.id`.",
556 ),
557 ("privileges", "The privileges belonging to the schema."),
558 ]),
559 sql: "
560IN CLUSTER mz_catalog_server
561WITH (
562 ASSERT NOT NULL id,
563 ASSERT NOT NULL oid,
564 ASSERT NOT NULL name,
565 ASSERT NOT NULL owner_id,
566 ASSERT NOT NULL privileges
567) AS
568SELECT
569 mz_internal.parse_catalog_id(data->'key'->'id') AS id,
570 (data->'value'->>'oid')::oid AS oid,
571 CASE WHEN data->'value'->'database_id' != 'null'
572 THEN mz_internal.parse_catalog_id(data->'value'->'database_id')
573 END AS database_id,
574 data->'value'->>'name' AS name,
575 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
576 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges
577FROM mz_internal.mz_catalog_raw
578WHERE data->>'kind' = 'Schema'",
579 is_retained_metrics_object: false,
580 access: vec![PUBLIC_SELECT],
581 ontology: Some(Ontology {
582 entity_name: "schema",
583 description: "A namespace within a database that contains objects",
584 links: &const {
585 [
586 OntologyLink {
587 name: "in_database",
588 target: "database",
589 properties: LinkProperties::fk_nullable(
590 "database_id",
591 "id",
592 Cardinality::ManyToOne,
593 ),
594 },
595 OntologyLink {
596 name: "owned_by",
597 target: "role",
598 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
599 },
600 ]
601 },
602 column_semantic_types: &const {
603 [
604 ("id", SemanticType::SchemaId),
605 ("oid", SemanticType::OID),
606 ("database_id", SemanticType::DatabaseId),
607 ("owner_id", SemanticType::RoleId),
608 ]
609 },
610 }),
611 });
612
613pub static MZ_COLUMNS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
614 let sql = format!(
636 "
637IN CLUSTER mz_catalog_server
638WITH (
639 ASSERT NOT NULL id,
640 ASSERT NOT NULL name,
641 ASSERT NOT NULL position,
642 ASSERT NOT NULL nullable,
643 ASSERT NOT NULL type,
644 ASSERT NOT NULL type_oid,
645 ASSERT NOT NULL type_mod
646) AS
647WITH
648 items AS (
649 SELECT
650 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
651 data->'value'->>'name' AS name,
652 (data->'value'->>'oid')::oid AS oid,
653 -- A table's column defaults as an array in column order
654 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->'column_defaults' AS column_defaults
655 FROM mz_internal.mz_catalog_raw
656 WHERE data->>'kind' = 'Item'
657 ),
658 -- An item's columns are one row whose value lists them in position order.
659 item_columns AS (
660 SELECT
661 mz_internal.parse_catalog_id(data->'key'->'id') AS id,
662 data->'value'->'columns' AS columns
663 FROM mz_internal.mz_catalog_raw
664 WHERE data->>'kind' = 'ItemColumns'
665 ),
666 defaults AS (
667 SELECT i.id, d.ordinality, d.value AS default
668 FROM
669 items AS i,
670 jsonb_array_elements_text(i.column_defaults) WITH ORDINALITY AS d(value, ordinality)
671 ),
672 cols AS (
673 SELECT
674 c.id,
675 col.ordinality,
676 col.value->>'name' AS name,
677 (col.value->>'nullable')::bool AS nullable,
678 (col.value->>'type_oid')::oid AS type_oid,
679 (col.value->>'type_mod')::int4 AS type_mod,
680 -- A column may have a custom type from a `CREATE TYPE` item of a list, map or record type.
681 -- We store the catalog ID of the custom type in the catalog and join on items to get its type
682 -- name and OID
683 CASE
684 WHEN jsonb_typeof(col.value->'custom_type') = 'object'
685 THEN mz_internal.parse_catalog_id(col.value->'custom_type')
686 END AS custom_type
687 FROM
688 item_columns AS c
689 CROSS JOIN LATERAL jsonb_array_elements(c.columns) WITH ORDINALITY AS col(value, ordinality)
690 ),
691 user_columns AS (
692 SELECT
693 c.id,
694 c.name,
695 -- WITH ORDINALITY numbers the list from one, which is what position reports
696 c.ordinality::uint8 AS position,
697 c.nullable,
698 coalesce(custom.name, mz_internal.mz_type_name(c.type_oid), 'unknown') AS type,
699 d.default,
700 coalesce(custom.oid, c.type_oid) AS type_oid,
701 c.type_mod
702 FROM
703 cols AS c
704 JOIN items AS i ON i.id = c.id
705 LEFT JOIN items AS custom ON custom.id = c.custom_type
706 LEFT JOIN defaults AS d ON d.id = c.id AND d.ordinality = c.ordinality
707 ),
708 builtin_relations AS (
709 SELECT
710 's' || (data->'value'->>'catalog_id') AS id,
711 data->'key'->>'schema_name' AS schema_name,
712 data->'key'->>'object_name' AS name
713 FROM mz_internal.mz_catalog_raw
714 WHERE
715 data->>'kind' = 'GidMapping' AND
716 data->'key'->>'object_type' IN ({table}, {source}, {view}, {materialized_view})
717 ),
718 builtin_columns AS (
719 SELECT
720 r.id,
721 b.name,
722 b.position,
723 b.nullable,
724 b.type,
725 b.default,
726 b.type_oid,
727 b.type_mod
728 FROM mz_internal.mz_builtin_columns b
729 JOIN builtin_relations r ON r.schema_name = b.schema_name AND r.name = b.relation_name
730 )
731SELECT * FROM user_columns
732UNION ALL
733SELECT * FROM builtin_columns",
734 table = gid_mapping_object_type(CatalogItemType::Table),
735 source = gid_mapping_object_type(CatalogItemType::Source),
736 view = gid_mapping_object_type(CatalogItemType::View),
737 materialized_view = gid_mapping_object_type(CatalogItemType::MaterializedView),
738 );
739 BuiltinMaterializedView {
740 name: "mz_columns",
741 schema: MZ_CATALOG_SCHEMA,
742 oid: oid::MV_MZ_COLUMNS_OID,
743 desc: RelationDesc::builder()
744 .with_column("id", SqlScalarType::String.nullable(false)) .with_column("name", SqlScalarType::String.nullable(false))
746 .with_column("position", SqlScalarType::UInt64.nullable(false))
747 .with_column("nullable", SqlScalarType::Bool.nullable(false))
748 .with_column("type", SqlScalarType::String.nullable(false))
749 .with_column("default", SqlScalarType::String.nullable(true))
750 .with_column("type_oid", SqlScalarType::Oid.nullable(false))
751 .with_column("type_mod", SqlScalarType::Int32.nullable(false))
752 .finish(),
753 column_comments: BTreeMap::from_iter([
754 (
755 "id",
756 "The unique ID of the table, source, or view containing the column.",
757 ),
758 ("name", "The name of the column."),
759 (
760 "position",
761 "The 1-indexed position of the column in its containing table, source, or view.",
762 ),
763 ("nullable", "Can the column contain a `NULL` value?"),
764 ("type", "The data type of the column."),
765 (
766 "default",
767 "The default expression of the column, or `NULL` if it has none.",
768 ),
769 (
770 "type_oid",
771 "The OID of the type of the column (references `mz_types`).",
772 ),
773 ("type_mod", "The packed type identifier of the column."),
774 ]),
775 sql: Box::leak(sql.into_boxed_str()),
776 is_retained_metrics_object: false,
777 access: vec![PUBLIC_SELECT],
778 ontology: Some(Ontology {
779 entity_name: "column",
780 description: "A column of a relation, with its name, position, type, and nullability",
781 links: &const {
782 [OntologyLink {
783 name: "belongs_to_relation",
784 target: "object",
785 properties: LinkProperties::ForeignKey {
786 source_column: "id",
787 target_column: "id",
788 cardinality: Cardinality::ManyToOne,
789 source_id_type: None,
790 requires_mapping: None,
791 nullable: false,
792 note: Some("id in mz_columns is the relation ID, not a unique column ID"),
793 extra_key_columns: None,
794 },
795 }]
796 },
797 column_semantic_types: &const {
798 [
799 ("id", SemanticType::CatalogItemId),
800 ("type_oid", SemanticType::OID),
801 ]
802 },
803 }),
804 }
805});
806
807const USER_INDEXES_CTE: &str = "\
810 user_indexes AS (
811 SELECT
812 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
813 (data->'value'->>'oid')::oid AS oid,
814 data->'value'->>'name' AS name,
815 parsed->>'on_id' AS on_id,
816 parsed->>'cluster_id' AS cluster_id,
817 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
818 data->'value'->'definition'->'V1'->>'create_sql' AS create_sql,
819 mz_internal.redact_sql(data->'value'->'definition'->'V1'->>'create_sql') AS redacted_create_sql
820 FROM
821 mz_internal.mz_catalog_raw
822 CROSS JOIN LATERAL (
823 SELECT mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')
824 ) AS l(parsed)
825 WHERE
826 data->>'kind' = 'Item' AND
827 parsed->>'type' = 'index'
828 )";
829
830const CATALOG_SERVER_CLUSTER_CTE: &str = "\
833 catalog_server_cluster AS (
834 SELECT mz_internal.parse_catalog_id(data->'key'->'id') AS id
835 FROM mz_internal.mz_catalog_raw
836 WHERE data->>'kind' = 'Cluster' AND data->'value'->>'name' = 'mz_catalog_server'
837 )";
838
839const BUILTIN_INDEX_GID_MAPPINGS_CTE: &str = "\
842 builtin_index_gid_mappings AS (
843 SELECT
844 's' || (data->'value'->>'catalog_id') AS id,
845 data->'key'->>'object_name' AS name
846 FROM mz_internal.mz_catalog_raw
847 WHERE
848 data->>'kind' = 'GidMapping' AND
849 data->'key'->>'object_type' = '6'
850 )";
851
852const ON_GID_MAPPINGS_CTE: &str = "\
855 on_gid_mappings AS (
856 SELECT
857 's' || (data->'value'->>'catalog_id') AS id,
858 data->'key'->>'schema_name' AS schema_name,
859 data->'key'->>'object_name' AS object_name
860 FROM mz_internal.mz_catalog_raw
861 WHERE data->>'kind' = 'GidMapping'
862 )";
863
864static GID_MAPPING_CTES: LazyLock<String> =
870 LazyLock::new(|| format!("{BUILTIN_INDEX_GID_MAPPINGS_CTE},\n {ON_GID_MAPPINGS_CTE}"));
871
872pub static MZ_INDEXES: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
873 let builtin_indexes_cte = format!("\
877 builtin_indexes AS (
878 SELECT *, mz_internal.redact_sql(create_sql) AS redacted_create_sql
879 FROM (
880 SELECT
881 bigm.id AS id,
882 biv.oid AS oid,
883 biv.name AS name,
884 om.id AS on_id,
885 csc.id AS cluster_id,
886 '{MZ_SYSTEM_ROLE_ID}' AS owner_id,
887 'CREATE INDEX \"' || biv.name || '\" IN CLUSTER [' || csc.id || '] ON [' || om.id || ' AS \"' || biv.on_schema_name || '\".\"' || biv.on_name || '\"] (' || biv.key_exprs || ')' AS create_sql
888 FROM mz_internal.mz_builtin_indexes biv
889 JOIN builtin_index_gid_mappings bigm ON bigm.name = biv.name
890 JOIN on_gid_mappings om ON om.schema_name = biv.on_schema_name AND om.object_name = biv.on_name
891 CROSS JOIN catalog_server_cluster csc
892 ) AS t
893 )");
894
895 let introspection_source_indexes_cte = format!("\
896 introspection_source_indexes AS (
897 SELECT *, mz_internal.redact_sql(create_sql) AS redacted_create_sql
898 FROM (
899 SELECT
900 'si' || (isi.data->'value'->>'catalog_id') AS id,
901 (isi.data->'value'->>'oid')::oid AS oid,
902 idx_name || '_' || cluster_id || '_primary_idx' AS name,
903 's' || (gm.data->'value'->>'catalog_id') AS on_id,
904 cluster_id,
905 '{MZ_SYSTEM_ROLE_ID}' AS owner_id,
906 'CREATE INDEX \"' || idx_name || '_' || cluster_id || '_primary_idx\" IN CLUSTER [' || cluster_id || '] ON \"mz_introspection\".\"' || idx_name || '\" (' || bli.col_list || ')' AS create_sql
907 FROM mz_internal.mz_catalog_raw AS isi
908 CROSS JOIN LATERAL (
909 SELECT isi.data->'key'->>'name', mz_internal.parse_catalog_id(isi.data->'key'->'cluster_id')
910 ) AS l(idx_name, cluster_id)
911 JOIN mz_internal.mz_catalog_raw AS gm ON
912 gm.data->>'kind' = 'GidMapping' AND
913 gm.data->'key'->>'object_type' = '2' AND
914 gm.data->'key'->>'schema_name' = 'mz_introspection' AND
915 gm.data->'key'->>'object_name' = idx_name
916 JOIN mz_internal.mz_builtin_log_indexes AS bli ON bli.name = idx_name
917 WHERE isi.data->>'kind' = 'ClusterIntrospectionSourceIndex'
918 ) AS t
919 )");
920
921 let gid_mapping_ctes: &str = &GID_MAPPING_CTES;
922 let sql = format!(
923 "
924IN CLUSTER mz_catalog_server
925WITH (
926 ASSERT NOT NULL id,
927 ASSERT NOT NULL oid,
928 ASSERT NOT NULL name,
929 ASSERT NOT NULL on_id,
930 ASSERT NOT NULL cluster_id,
931 ASSERT NOT NULL owner_id,
932 ASSERT NOT NULL create_sql,
933 ASSERT NOT NULL redacted_create_sql
934) AS
935WITH
936{USER_INDEXES_CTE},
937{CATALOG_SERVER_CLUSTER_CTE},
938{gid_mapping_ctes},
939{builtin_indexes_cte},
940{introspection_source_indexes_cte}
941SELECT * FROM user_indexes
942UNION ALL
943SELECT * FROM builtin_indexes
944UNION ALL
945SELECT * FROM introspection_source_indexes
946"
947 );
948
949 BuiltinMaterializedView {
950 name: "mz_indexes",
951 schema: MZ_CATALOG_SCHEMA,
952 oid: oid::MV_MZ_INDEXES_OID,
953 desc: RelationDesc::builder()
954 .with_column("id", SqlScalarType::String.nullable(false))
955 .with_column("oid", SqlScalarType::Oid.nullable(false))
956 .with_column("name", SqlScalarType::String.nullable(false))
957 .with_column("on_id", SqlScalarType::String.nullable(false))
958 .with_column("cluster_id", SqlScalarType::String.nullable(false))
959 .with_column("owner_id", SqlScalarType::String.nullable(false))
960 .with_column("create_sql", SqlScalarType::String.nullable(false))
961 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
962 .with_key(vec![0])
963 .with_key(vec![1])
964 .finish(),
965 column_comments: BTreeMap::from_iter([
966 ("id", "Materialize's unique ID for the index."),
967 ("oid", "A PostgreSQL-compatible OID for the index."),
968 ("name", "The name of the index."),
969 (
970 "on_id",
971 "The ID of the relation on which the index is built.",
972 ),
973 (
974 "cluster_id",
975 "The ID of the cluster in which the index is built.",
976 ),
977 (
978 "owner_id",
979 "The role ID of the owner of the index. Corresponds to `mz_roles.id`.",
980 ),
981 ("create_sql", "The `CREATE` SQL statement for the index."),
982 (
983 "redacted_create_sql",
984 "The redacted `CREATE` SQL statement for the index.",
985 ),
986 ]),
987 sql: Box::leak(sql.into_boxed_str()),
988 is_retained_metrics_object: false,
989 access: vec![PUBLIC_SELECT],
990 ontology: Some(Ontology {
991 entity_name: "index",
992 description: "An in-memory index on a relation for fast lookups",
993 links: &const {
994 [
995 OntologyLink {
996 name: "owned_by",
997 target: "role",
998 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
999 },
1000 OntologyLink {
1001 name: "runs_on_cluster",
1002 target: "cluster",
1003 properties: LinkProperties::fk("cluster_id", "id", Cardinality::ManyToOne),
1004 },
1005 OntologyLink {
1006 name: "indexes_relation",
1007 target: "relation",
1008 properties: LinkProperties::fk("on_id", "id", Cardinality::ManyToOne),
1009 },
1010 ]
1011 },
1012 column_semantic_types: &const {
1013 [
1014 ("id", SemanticType::CatalogItemId),
1015 ("oid", SemanticType::OID),
1016 ("on_id", SemanticType::CatalogItemId),
1017 ("cluster_id", SemanticType::ClusterId),
1018 ("owner_id", SemanticType::RoleId),
1019 ("create_sql", SemanticType::SqlDefinition),
1020 ("redacted_create_sql", SemanticType::RedactedSqlDefinition),
1021 ]
1022 },
1023 }),
1024 }
1025});
1026pub static MZ_INDEX_COLUMNS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
1027 let sql = format!(
1028 "
1029IN CLUSTER mz_catalog_server
1030WITH (
1031 ASSERT NOT NULL index_id,
1032 ASSERT NOT NULL index_position,
1033 ASSERT NOT NULL nullable
1034) AS
1035WITH
1036 -- An index's keys are one row whose value lists them in key order.
1037 index_keys AS (
1038 SELECT
1039 mz_internal.parse_catalog_id(k.data->'key'->'id') AS index_id,
1040 k.data->'value'->'columns' AS columns,
1041 mz_internal.parse_catalog_create_sql(i.data->'value'->'definition'->'V1'->>'create_sql')->'key_parts' AS key_parts
1042 FROM
1043 mz_internal.mz_catalog_raw AS k
1044 -- Filter to index items so the join arranges only their rows. A
1045 -- persisted index's create_sql always starts with `CREATE INDEX`
1046 JOIN mz_internal.mz_catalog_raw AS i ON
1047 i.data->>'kind' = 'Item' AND
1048 i.data->'value'->'definition'->'V1'->>'create_sql' LIKE 'CREATE INDEX %' AND
1049 i.data->'key'->'gid' = k.data->'key'->'id'
1050 WHERE k.data->>'kind' = 'IndexColumns'
1051 ),
1052 key_parts AS (
1053 SELECT k.index_id, p.ordinality, p.value AS expression
1054 FROM
1055 index_keys AS k,
1056 jsonb_array_elements_text(k.key_parts) WITH ORDINALITY AS p(value, ordinality)
1057 ),
1058 user_index_columns AS (
1059 SELECT
1060 k.index_id,
1061 -- WITH ORDINALITY numbers the list from one, which is what index_position reports
1062 ik.ordinality::uint8 AS index_position,
1063 (ik.value->>'column')::uint8 + 1::uint8 AS on_position,
1064 -- Either on_position is null or on_expression is, thus we use a case
1065 CASE
1066 WHEN ik.value->>'column' IS NULL
1067 THEN p.expression
1068 END AS on_expression,
1069 (ik.value->>'nullable')::bool AS nullable
1070 FROM
1071 index_keys AS k
1072 CROSS JOIN LATERAL jsonb_array_elements(k.columns) WITH ORDINALITY AS ik(value, ordinality)
1073 LEFT JOIN key_parts AS p ON p.index_id = k.index_id AND p.ordinality = ik.ordinality
1074 ),
1075{BUILTIN_INDEX_GID_MAPPINGS_CTE},
1076 builtin_index_columns AS (
1077 SELECT
1078 bigm.id AS index_id,
1079 bic.index_position,
1080 bic.on_position,
1081 NULL::text AS on_expression,
1082 bic.nullable
1083 FROM mz_internal.mz_builtin_index_columns AS bic
1084 JOIN builtin_index_gid_mappings AS bigm ON bigm.name = bic.name
1085 WHERE bic.type = 'index'
1086 ),
1087 introspection_source_index_columns AS (
1088 SELECT
1089 'si' || (isi.data->'value'->>'catalog_id') AS index_id,
1090 bic.index_position,
1091 bic.on_position,
1092 NULL::text AS on_expression,
1093 bic.nullable
1094 FROM mz_internal.mz_catalog_raw AS isi
1095 JOIN mz_internal.mz_builtin_index_columns AS bic ON bic.name = isi.data->'key'->>'name'
1096 WHERE
1097 isi.data->>'kind' = 'ClusterIntrospectionSourceIndex' AND
1098 bic.type = 'log'
1099 )
1100SELECT * FROM user_index_columns
1101UNION ALL
1102SELECT * FROM builtin_index_columns
1103UNION ALL
1104SELECT * FROM introspection_source_index_columns"
1105 );
1106
1107 BuiltinMaterializedView {
1108 name: "mz_index_columns",
1109 schema: MZ_CATALOG_SCHEMA,
1110 oid: oid::MV_MZ_INDEX_COLUMNS_OID,
1111 desc: RelationDesc::builder()
1112 .with_column("index_id", SqlScalarType::String.nullable(false))
1113 .with_column("index_position", SqlScalarType::UInt64.nullable(false))
1114 .with_column("on_position", SqlScalarType::UInt64.nullable(true))
1115 .with_column("on_expression", SqlScalarType::String.nullable(true))
1116 .with_column("nullable", SqlScalarType::Bool.nullable(false))
1117 .finish(),
1118 column_comments: BTreeMap::from_iter([
1119 (
1120 "index_id",
1121 "The ID of the index which contains this column. Corresponds to `mz_indexes.id`.",
1122 ),
1123 (
1124 "index_position",
1125 "The 1-indexed position of this column within the index. (The order of columns in an index does not necessarily match the order of columns in the relation on which the index is built.)",
1126 ),
1127 (
1128 "on_position",
1129 "If not `NULL`, specifies the 1-indexed position of a column in the relation on which this index is built that determines the value of this index column.",
1130 ),
1131 (
1132 "on_expression",
1133 "If not `NULL`, specifies a SQL expression that is evaluated to compute the value of this index column. The expression may contain references to any of the columns of the relation.",
1134 ),
1135 (
1136 "nullable",
1137 "Can this column of the index evaluate to `NULL`?",
1138 ),
1139 ]),
1140 sql: Box::leak(sql.into_boxed_str()),
1141 is_retained_metrics_object: false,
1142 access: vec![PUBLIC_SELECT],
1143 ontology: Some(Ontology {
1144 entity_name: "index_column",
1145 description: "A column or expression in an index, with its position",
1146 links: &const {
1147 [OntologyLink {
1148 name: "belongs_to_index",
1149 target: "index",
1150 properties: LinkProperties::fk("index_id", "id", Cardinality::ManyToOne),
1151 }]
1152 },
1153 column_semantic_types: &[("index_id", SemanticType::CatalogItemId)],
1154 }),
1155 }
1156});
1157pub static MZ_TABLES: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
1158 BuiltinMaterializedView {
1159 name: "mz_tables",
1160 schema: MZ_CATALOG_SCHEMA,
1161 oid: oid::MV_MZ_TABLES_OID,
1162 desc: RelationDesc::builder()
1163 .with_column("id", SqlScalarType::String.nullable(false))
1164 .with_column("oid", SqlScalarType::Oid.nullable(false))
1165 .with_column("schema_id", SqlScalarType::String.nullable(false))
1166 .with_column("name", SqlScalarType::String.nullable(false))
1167 .with_column("owner_id", SqlScalarType::String.nullable(false))
1168 .with_column(
1169 "privileges",
1170 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
1171 )
1172 .with_column("create_sql", SqlScalarType::String.nullable(true))
1173 .with_column("redacted_create_sql", SqlScalarType::String.nullable(true))
1174 .with_column("source_id", SqlScalarType::String.nullable(true))
1175 .with_key(vec![0])
1176 .with_key(vec![1])
1177 .finish(),
1178 column_comments: BTreeMap::from_iter([
1179 ("id", "Materialize's unique ID for the table."),
1180 ("oid", "A PostgreSQL-compatible OID for the table."),
1181 (
1182 "schema_id",
1183 "The ID of the schema to which the table belongs. Corresponds to `mz_schemas.id`.",
1184 ),
1185 ("name", "The name of the table."),
1186 (
1187 "owner_id",
1188 "The role ID of the owner of the table. Corresponds to `mz_roles.id`.",
1189 ),
1190 ("privileges", "The privileges belonging to the table."),
1191 ("create_sql", "The `CREATE` SQL statement for the table."),
1192 (
1193 "redacted_create_sql",
1194 "The redacted `CREATE` SQL statement for the table.",
1195 ),
1196 (
1197 "source_id",
1198 "The ID of the source associated with the table, if any. Corresponds to `mz_sources.id`.",
1199 ),
1200 ]),
1201 sql: Box::leak(format!("
1205IN CLUSTER mz_catalog_server
1206WITH (
1207 ASSERT NOT NULL id,
1208 ASSERT NOT NULL oid,
1209 ASSERT NOT NULL schema_id,
1210 ASSERT NOT NULL name,
1211 ASSERT NOT NULL owner_id,
1212 ASSERT NOT NULL privileges
1213) AS
1214WITH
1215 user_tables AS (
1216 SELECT
1217 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
1218 (data->'value'->>'oid')::oid AS oid,
1219 CASE WHEN data->'value'->>'ephemeral_owner_session' IS NULL
1220 THEN mz_internal.parse_catalog_id(data->'value'->'schema_id')
1221 ELSE '0'
1222 END AS schema_id,
1223 data->'value'->>'name' AS name,
1224 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
1225 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges,
1226 data->'value'->'definition'->'V1'->>'create_sql' AS create_sql,
1227 mz_internal.redact_sql(data->'value'->'definition'->'V1'->>'create_sql') AS redacted_create_sql,
1228 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'source_id' AS source_id
1229 FROM mz_internal.mz_catalog_raw
1230 WHERE
1231 data->>'kind' = 'Item' AND
1232 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'type' = 'table'
1233 ),
1234 builtin_mappings AS (
1235 SELECT
1236 data->'key'->>'schema_name' AS schema_name,
1237 data->'key'->>'object_name' AS name,
1238 's' || (data->'value'->>'catalog_id') AS id
1239 FROM mz_internal.mz_catalog_raw
1240 WHERE
1241 data->>'kind' = 'GidMapping' AND
1242 data->'key'->>'object_type' = '1'
1243 ),
1244 builtin_tables AS (
1245 SELECT
1246 m.id,
1247 t.oid,
1248 s.id AS schema_id,
1249 t.name,
1250 '{MZ_SYSTEM_ROLE_ID}' AS owner_id,
1251 t.privileges,
1252 NULL::text AS create_sql,
1253 NULL::text AS redacted_create_sql,
1254 NULL::text AS source_id
1255 FROM mz_internal.mz_builtin_tables t
1256 JOIN builtin_mappings m USING (schema_name, name)
1257 JOIN mz_schemas s ON s.name = t.schema_name
1258 WHERE s.database_id IS NULL
1259 )
1260SELECT * FROM user_tables
1261UNION ALL
1262SELECT * FROM builtin_tables").into_boxed_str()),
1263 is_retained_metrics_object: true,
1264 access: vec![PUBLIC_SELECT],
1265 ontology: Some(Ontology {
1266 entity_name: "table",
1267 description: "A user-writable table that can be inserted into and updated",
1268 links: &const {
1269 [
1270 OntologyLink {
1271 name: "in_schema",
1272 target: "schema",
1273 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
1274 },
1275 OntologyLink {
1276 name: "owned_by",
1277 target: "role",
1278 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
1279 },
1280 OntologyLink {
1281 name: "created_by_source",
1282 target: "source",
1283 properties: LinkProperties::fk_nullable(
1284 "source_id",
1285 "id",
1286 Cardinality::ManyToOne,
1287 ),
1288 },
1289 ]
1290 },
1291 column_semantic_types: &const {
1292 [
1293 ("id", SemanticType::CatalogItemId),
1294 ("oid", SemanticType::OID),
1295 ("schema_id", SemanticType::SchemaId),
1296 ("owner_id", SemanticType::RoleId),
1297 ("create_sql", SemanticType::SqlDefinition),
1298 ("redacted_create_sql", SemanticType::RedactedSqlDefinition),
1299 ("source_id", SemanticType::CatalogItemId),
1300 ]
1301 },
1302 }),
1303}
1304});
1305
1306pub static MZ_CONNECTIONS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
1307 BuiltinMaterializedView {
1308 name: "mz_connections",
1309 schema: MZ_CATALOG_SCHEMA,
1310 oid: oid::MV_MZ_CONNECTIONS_OID,
1311 desc: RelationDesc::builder()
1312 .with_column("id", SqlScalarType::String.nullable(false))
1313 .with_column("oid", SqlScalarType::Oid.nullable(false))
1314 .with_column("schema_id", SqlScalarType::String.nullable(false))
1315 .with_column("name", SqlScalarType::String.nullable(false))
1316 .with_column("type", SqlScalarType::String.nullable(false))
1317 .with_column("owner_id", SqlScalarType::String.nullable(false))
1318 .with_column(
1319 "privileges",
1320 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
1321 )
1322 .with_column("create_sql", SqlScalarType::String.nullable(false))
1323 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
1324 .with_key(vec![0])
1325 .with_key(vec![1])
1326 .finish(),
1327 column_comments: BTreeMap::from_iter([
1328 ("id", "The unique ID of the connection."),
1329 ("oid", "A PostgreSQL-compatible OID for the connection."),
1330 (
1331 "schema_id",
1332 "The ID of the schema to which the connection belongs. Corresponds to `mz_schemas.id`.",
1333 ),
1334 ("name", "The name of the connection."),
1335 (
1336 "type",
1337 "The type of the connection: `confluent-schema-registry`, `kafka`, `postgres`, or `ssh-tunnel`.",
1338 ),
1339 (
1340 "owner_id",
1341 "The role ID of the owner of the connection. Corresponds to `mz_roles.id`.",
1342 ),
1343 ("privileges", "The privileges belonging to the connection."),
1344 (
1345 "create_sql",
1346 "The `CREATE` SQL statement for the connection.",
1347 ),
1348 (
1349 "redacted_create_sql",
1350 "The redacted `CREATE` SQL statement for the connection.",
1351 ),
1352 ]),
1353 sql: "
1354IN CLUSTER mz_catalog_server
1355WITH (
1356 ASSERT NOT NULL id,
1357 ASSERT NOT NULL oid,
1358 ASSERT NOT NULL schema_id,
1359 ASSERT NOT NULL name,
1360 ASSERT NOT NULL type,
1361 ASSERT NOT NULL owner_id,
1362 ASSERT NOT NULL privileges,
1363 ASSERT NOT NULL create_sql,
1364 ASSERT NOT NULL redacted_create_sql
1365) AS
1366SELECT
1367 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
1368 (data->'value'->>'oid')::oid AS oid,
1369 mz_internal.parse_catalog_id(data->'value'->'schema_id') AS schema_id,
1370 data->'value'->>'name' AS name,
1371 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'connection_type' AS type,
1372 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
1373 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges,
1374 data->'value'->'definition'->'V1'->>'create_sql' AS create_sql,
1375 mz_internal.redact_sql(data->'value'->'definition'->'V1'->>'create_sql') AS redacted_create_sql
1376FROM mz_internal.mz_catalog_raw
1377WHERE
1378 data->>'kind' = 'Item' AND
1379 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'type' = 'connection'",
1380 is_retained_metrics_object: false,
1381 access: vec![PUBLIC_SELECT],
1382 ontology: Some(Ontology {
1383 entity_name: "connection",
1384 description: "A reusable connection configuration to an external system",
1385 links: &const { [
1386 OntologyLink {
1387 name: "in_schema",
1388 target: "schema",
1389 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
1390 },
1391 OntologyLink {
1392 name: "owned_by",
1393 target: "role",
1394 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
1395 },
1396 ] },
1397 column_semantic_types: &const {[("id", SemanticType::CatalogItemId), ("oid", SemanticType::OID), ("schema_id", SemanticType::SchemaId), ("type", SemanticType::ConnectionType), ("owner_id", SemanticType::RoleId), ("create_sql", SemanticType::SqlDefinition), ("redacted_create_sql", SemanticType::RedactedSqlDefinition)]},
1398 }),
1399 }
1400});
1401
1402pub static MZ_SSH_TUNNEL_CONNECTIONS: LazyLock<BuiltinMaterializedView> =
1407 LazyLock::new(|| BuiltinMaterializedView {
1408 name: "mz_ssh_tunnel_connections",
1409 schema: MZ_CATALOG_SCHEMA,
1410 oid: oid::MV_MZ_SSH_TUNNEL_CONNECTIONS_OID,
1411 desc: RelationDesc::builder()
1412 .with_column("id", SqlScalarType::String.nullable(false))
1413 .with_column("public_key_1", SqlScalarType::String.nullable(false))
1414 .with_column("public_key_2", SqlScalarType::String.nullable(false))
1415 .with_key(vec![0])
1416 .finish(),
1417 column_comments: BTreeMap::from_iter([
1418 ("id", "The ID of the connection."),
1419 (
1420 "public_key_1",
1421 "The first public key associated with the SSH tunnel.",
1422 ),
1423 (
1424 "public_key_2",
1425 "The second public key associated with the SSH tunnel.",
1426 ),
1427 ]),
1428 sql: "
1429IN CLUSTER mz_catalog_server
1430WITH (
1431 ASSERT NOT NULL id,
1432 ASSERT NOT NULL public_key_1,
1433 ASSERT NOT NULL public_key_2
1434) AS
1435SELECT
1436 mz_internal.parse_catalog_id(r.data->'key'->'gid') AS id,
1437 details->>'public_key_1' AS public_key_1,
1438 details->>'public_key_2' AS public_key_2
1439FROM
1440 mz_internal.mz_catalog_raw r,
1441 LATERAL (
1442 SELECT mz_internal.parse_connection_details(
1443 r.data->'value'->'definition'->'V1'->>'create_sql')
1444 ) AS d(details)
1445WHERE
1446 r.data->>'kind' = 'Item' AND
1447 -- The connection_type filter selects the kind. A non-matching row yields a
1448 -- NULL connection_type and is dropped here, so no `details IS NOT NULL` is
1449 -- needed (parse_connection_details returns jsonb null, which passes it).
1450 mz_internal.parse_catalog_create_sql(
1451 r.data->'value'->'definition'->'V1'->>'create_sql')->>'connection_type' = 'ssh-tunnel'",
1452 is_retained_metrics_object: false,
1453 access: vec![PUBLIC_SELECT],
1454 ontology: Some(Ontology {
1455 entity_name: "ssh_tunnel_connection",
1456 description: "SSH tunnel connection with public keys",
1457 links: &const {
1458 [OntologyLink {
1459 name: "details_of",
1460 target: "connection",
1461 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
1462 }]
1463 },
1464 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
1465 }),
1466 });
1467pub static MZ_SOURCES: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
1468 let sql = format!("
1469IN CLUSTER mz_catalog_server
1470WITH (
1471 ASSERT NOT NULL id,
1472 ASSERT NOT NULL oid,
1473 ASSERT NOT NULL schema_id,
1474 ASSERT NOT NULL name,
1475 ASSERT NOT NULL type,
1476 ASSERT NOT NULL owner_id,
1477 ASSERT NOT NULL privileges
1478) AS
1479WITH
1480 user_sources AS (
1481 SELECT
1482 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
1483 (data->'value'->>'oid')::oid AS oid,
1484 mz_internal.parse_catalog_id(data->'value'->'schema_id') AS schema_id,
1485 data->'value'->>'name' AS name,
1486 parsed->>'source_type' AS type,
1487 parsed->>'connection_id' AS connection_id,
1488 NULL AS size,
1489 parsed->>'envelope_type' AS envelope_type,
1490 parsed->>'key_format' AS key_format,
1491 parsed->>'value_format' AS value_format,
1492 COALESCE(
1493 parsed->>'cluster_id',
1494 (
1495 SELECT mz_internal.parse_catalog_create_sql(p.data->'value'->'definition'->'V1'->>'create_sql')->>'cluster_id'
1496 FROM mz_internal.mz_catalog_raw p
1497 WHERE
1498 p.data->>'kind' = 'Item' AND
1499 mz_internal.parse_catalog_id(p.data->'key'->'gid') = parsed->>'of_source_id'
1500 )
1501 ) AS cluster_id,
1502 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
1503 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges,
1504 data->'value'->'definition'->'V1'->>'create_sql' AS create_sql,
1505 mz_internal.redact_sql(data->'value'->'definition'->'V1'->>'create_sql') AS redacted_create_sql
1506 FROM
1507 mz_internal.mz_catalog_raw
1508 CROSS JOIN LATERAL (
1509 SELECT mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')
1510 ) AS l(parsed)
1511 WHERE
1512 data->>'kind' = 'Item' AND
1513 parsed->>'type' IN ('source', 'subsource')
1514 ),
1515 builtin_mappings AS (
1516 SELECT
1517 data->'key'->>'schema_name' AS schema_name,
1518 data->'key'->>'object_name' AS name,
1519 's' || (data->'value'->>'catalog_id') AS id
1520 FROM mz_internal.mz_catalog_raw
1521 WHERE
1522 data->>'kind' = 'GidMapping' AND
1523 data->'key'->>'object_type' = '2'
1524 ),
1525 builtin_sources AS (
1526 SELECT
1527 m.id,
1528 src.oid,
1529 s.id AS schema_id,
1530 src.name,
1531 src.type,
1532 NULL AS connection_id,
1533 NULL AS size,
1534 NULL AS envelope_type,
1535 NULL AS key_format,
1536 NULL AS value_format,
1537 NULL AS cluster_id,
1538 '{MZ_SYSTEM_ROLE_ID}' AS owner_id,
1539 src.privileges,
1540 NULL AS create_sql,
1541 NULL AS redacted_create_sql
1542 FROM mz_internal.mz_builtin_sources AS src
1543 JOIN builtin_mappings m USING (schema_name, name)
1544 JOIN mz_schemas s ON s.name = src.schema_name
1545 WHERE s.database_id IS NULL
1546 )
1547SELECT * FROM user_sources
1548UNION ALL
1549SELECT * FROM builtin_sources");
1550
1551 BuiltinMaterializedView {
1552 name: "mz_sources",
1553 schema: MZ_CATALOG_SCHEMA,
1554 oid: oid::MV_MZ_SOURCES_OID,
1555 desc: RelationDesc::builder()
1556 .with_column("id", SqlScalarType::String.nullable(false))
1557 .with_column("oid", SqlScalarType::Oid.nullable(false))
1558 .with_column("schema_id", SqlScalarType::String.nullable(false))
1559 .with_column("name", SqlScalarType::String.nullable(false))
1560 .with_column("type", SqlScalarType::String.nullable(false))
1561 .with_column("connection_id", SqlScalarType::String.nullable(true))
1562 .with_column("size", SqlScalarType::String.nullable(true))
1563 .with_column("envelope_type", SqlScalarType::String.nullable(true))
1564 .with_column("key_format", SqlScalarType::String.nullable(true))
1565 .with_column("value_format", SqlScalarType::String.nullable(true))
1566 .with_column("cluster_id", SqlScalarType::String.nullable(true))
1567 .with_column("owner_id", SqlScalarType::String.nullable(false))
1568 .with_column(
1569 "privileges",
1570 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
1571 )
1572 .with_column("create_sql", SqlScalarType::String.nullable(true))
1573 .with_column("redacted_create_sql", SqlScalarType::String.nullable(true))
1574 .with_key(vec![0])
1575 .with_key(vec![1])
1576 .finish(),
1577 column_comments: BTreeMap::from_iter([
1578 ("id", "Materialize's unique ID for the source."),
1579 ("oid", "A PostgreSQL-compatible OID for the source."),
1580 (
1581 "schema_id",
1582 "The ID of the schema to which the source belongs. Corresponds to `mz_schemas.id`.",
1583 ),
1584 ("name", "The name of the source."),
1585 (
1586 "type",
1587 "The type of the source: `kafka`, `mysql`, `postgres`, `load-generator`, `progress`, or `subsource`.",
1588 ),
1589 (
1590 "connection_id",
1591 "The ID of the connection associated with the source, if any. Corresponds to `mz_connections.id`.",
1592 ),
1593 ("size", "*Deprecated* The size of the source."),
1594 (
1595 "envelope_type",
1596 "For old-syntax Kafka sources, the envelope type: `none`, `upsert`, or `debezium`. `NULL` for new-syntax Kafka sources, whose envelopes are defined per source table (see `mz_kafka_source_tables`), and for other source types.",
1597 ),
1598 (
1599 "key_format",
1600 "For Kafka sources, the format of the Kafka message key: `avro`, `csv`, `regex`, `bytes`, `json`, `text`, or `NULL`.",
1601 ),
1602 (
1603 "value_format",
1604 "For Kafka sources, the format of the Kafka message value: `avro`, `csv`, `regex`, `bytes`, `json`, `text`. `NULL` for other source types.",
1605 ),
1606 (
1607 "cluster_id",
1608 "The ID of the cluster maintaining the source. Corresponds to `mz_clusters.id`.",
1609 ),
1610 (
1611 "owner_id",
1612 "The role ID of the owner of the source. Corresponds to `mz_roles.id`.",
1613 ),
1614 ("privileges", "The privileges granted on the source."),
1615 ("create_sql", "The `CREATE` SQL statement for the source."),
1616 (
1617 "redacted_create_sql",
1618 "The redacted `CREATE` SQL statement for the source.",
1619 ),
1620 ]),
1621 sql: Box::leak(sql.into_boxed_str()),
1622 is_retained_metrics_object: true,
1623 access: vec![PUBLIC_SELECT],
1624 ontology: Some(Ontology {
1625 entity_name: "source",
1626 description: "An external data source ingested into Materialize (e.g., Kafka, Postgres)",
1627 links: &const {
1628 [
1629 OntologyLink {
1630 name: "in_schema",
1631 target: "schema",
1632 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
1633 },
1634 OntologyLink {
1635 name: "owned_by",
1636 target: "role",
1637 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
1638 },
1639 OntologyLink {
1640 name: "runs_on_cluster",
1641 target: "cluster",
1642 properties: LinkProperties::fk_nullable(
1643 "cluster_id",
1644 "id",
1645 Cardinality::ManyToOne,
1646 ),
1647 },
1648 OntologyLink {
1649 name: "uses_connection",
1650 target: "connection",
1651 properties: LinkProperties::fk_nullable(
1652 "connection_id",
1653 "id",
1654 Cardinality::ManyToOne,
1655 ),
1656 },
1657 ]
1658 },
1659 column_semantic_types: &const {
1660 [
1661 ("id", SemanticType::CatalogItemId),
1662 ("oid", SemanticType::OID),
1663 ("schema_id", SemanticType::SchemaId),
1664 ("type", SemanticType::SourceType),
1665 ("connection_id", SemanticType::CatalogItemId),
1666 ("cluster_id", SemanticType::ClusterId),
1667 ("owner_id", SemanticType::RoleId),
1668 ("create_sql", SemanticType::SqlDefinition),
1669 ("redacted_create_sql", SemanticType::RedactedSqlDefinition),
1670 ]
1671 },
1672 }),
1673 }
1674});
1675pub static MZ_SINKS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
1680 BuiltinMaterializedView {
1681 name: "mz_sinks",
1682 schema: MZ_CATALOG_SCHEMA,
1683 oid: oid::MV_MZ_SINKS_OID,
1684 desc: RelationDesc::builder()
1685 .with_column("id", SqlScalarType::String.nullable(false))
1686 .with_column("oid", SqlScalarType::Oid.nullable(false))
1687 .with_column("schema_id", SqlScalarType::String.nullable(false))
1688 .with_column("name", SqlScalarType::String.nullable(false))
1689 .with_column("type", SqlScalarType::String.nullable(false))
1690 .with_column("connection_id", SqlScalarType::String.nullable(true))
1691 .with_column("size", SqlScalarType::String.nullable(true))
1692 .with_column("envelope_type", SqlScalarType::String.nullable(true))
1693 .with_column("format", SqlScalarType::String.nullable(true))
1696 .with_column("key_format", SqlScalarType::String.nullable(true))
1697 .with_column("value_format", SqlScalarType::String.nullable(true))
1698 .with_column("cluster_id", SqlScalarType::String.nullable(false))
1699 .with_column("owner_id", SqlScalarType::String.nullable(false))
1700 .with_column("create_sql", SqlScalarType::String.nullable(false))
1701 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
1702 .with_key(vec![0])
1703 .with_key(vec![1])
1704 .finish(),
1705 column_comments: BTreeMap::from_iter([
1706 ("id", "Materialize's unique ID for the sink."),
1707 ("oid", "A PostgreSQL-compatible OID for the sink."),
1708 (
1709 "schema_id",
1710 "The ID of the schema to which the sink belongs. Corresponds to `mz_schemas.id`.",
1711 ),
1712 ("name", "The name of the sink."),
1713 ("type", "The type of the sink: `kafka`."),
1714 (
1715 "connection_id",
1716 "The ID of the connection associated with the sink, if any. Corresponds to `mz_connections.id`.",
1717 ),
1718 ("size", "The size of the sink."),
1719 (
1720 "envelope_type",
1721 "The envelope of the sink: `upsert`, or `debezium`.",
1722 ),
1723 (
1724 "format",
1725 "*Deprecated* The format of the Kafka messages produced by the sink: `avro`, `json`, `text`, or `bytes`.",
1726 ),
1727 (
1728 "key_format",
1729 "The format of the Kafka message key for messages produced by the sink: `avro`, `json`, `bytes`, `text`, or `NULL`.",
1730 ),
1731 (
1732 "value_format",
1733 "The format of the Kafka message value for messages produced by the sink: `avro`, `json`, `text`, or `bytes`.",
1734 ),
1735 (
1736 "cluster_id",
1737 "The ID of the cluster maintaining the sink. Corresponds to `mz_clusters.id`.",
1738 ),
1739 (
1740 "owner_id",
1741 "The role ID of the owner of the sink. Corresponds to `mz_roles.id`.",
1742 ),
1743 ("create_sql", "The `CREATE` SQL statement for the sink."),
1744 (
1745 "redacted_create_sql",
1746 "The redacted `CREATE` SQL statement for the sink.",
1747 ),
1748 ]),
1749 sql: "
1750IN CLUSTER mz_catalog_server
1751WITH (
1752 ASSERT NOT NULL id,
1753 ASSERT NOT NULL oid,
1754 ASSERT NOT NULL schema_id,
1755 ASSERT NOT NULL name,
1756 ASSERT NOT NULL type,
1757 ASSERT NOT NULL cluster_id,
1758 ASSERT NOT NULL owner_id,
1759 ASSERT NOT NULL create_sql,
1760 ASSERT NOT NULL redacted_create_sql
1761) AS
1762SELECT
1763 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
1764 (data->'value'->>'oid')::oid AS oid,
1765 mz_internal.parse_catalog_id(data->'value'->'schema_id') AS schema_id,
1766 data->'value'->>'name' AS name,
1767 parsed->>'sink_type' AS type,
1768 parsed->>'connection_id' AS connection_id,
1769 NULL::text AS size,
1770 parsed->>'envelope_type' AS envelope_type,
1771 parsed->>'format' AS format,
1772 parsed->>'key_format' AS key_format,
1773 parsed->>'value_format' AS value_format,
1774 parsed->>'cluster_id' AS cluster_id,
1775 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
1776 data->'value'->'definition'->'V1'->>'create_sql' AS create_sql,
1777 mz_internal.redact_sql(data->'value'->'definition'->'V1'->>'create_sql') AS redacted_create_sql
1778FROM
1779 mz_internal.mz_catalog_raw
1780 CROSS JOIN LATERAL (
1781 SELECT mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')
1782 ) AS l(parsed)
1783WHERE
1784 data->>'kind' = 'Item' AND
1785 parsed->>'type' = 'sink'",
1786 is_retained_metrics_object: true,
1787 access: vec![PUBLIC_SELECT],
1788 ontology: Some(Ontology {
1789 entity_name: "sink",
1790 description: "An export of data from Materialize to an external system",
1791 links: &const {
1792 [
1793 OntologyLink {
1794 name: "in_schema",
1795 target: "schema",
1796 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
1797 },
1798 OntologyLink {
1799 name: "owned_by",
1800 target: "role",
1801 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
1802 },
1803 OntologyLink {
1804 name: "runs_on_cluster",
1805 target: "cluster",
1806 properties: LinkProperties::fk("cluster_id", "id", Cardinality::ManyToOne),
1807 },
1808 OntologyLink {
1809 name: "uses_connection",
1810 target: "connection",
1811 properties: LinkProperties::fk_nullable(
1812 "connection_id",
1813 "id",
1814 Cardinality::ManyToOne,
1815 ),
1816 },
1817 ]
1818 },
1819 column_semantic_types: &const {
1820 [
1821 ("id", SemanticType::CatalogItemId),
1822 ("oid", SemanticType::OID),
1823 ("schema_id", SemanticType::SchemaId),
1824 ("connection_id", SemanticType::CatalogItemId),
1825 ("cluster_id", SemanticType::ClusterId),
1826 ("owner_id", SemanticType::RoleId),
1827 ("create_sql", SemanticType::SqlDefinition),
1828 ("redacted_create_sql", SemanticType::RedactedSqlDefinition),
1829 ]
1830 },
1831 }),
1832 }
1833});
1834pub static MZ_VIEWS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
1835 BuiltinMaterializedView {
1836 name: "mz_views",
1837 schema: MZ_CATALOG_SCHEMA,
1838 oid: oid::MV_MZ_VIEWS_OID,
1839 desc: RelationDesc::builder()
1840 .with_column("id", SqlScalarType::String.nullable(false))
1841 .with_column("oid", SqlScalarType::Oid.nullable(false))
1842 .with_column("schema_id", SqlScalarType::String.nullable(false))
1843 .with_column("name", SqlScalarType::String.nullable(false))
1844 .with_column("definition", SqlScalarType::String.nullable(false))
1845 .with_column("owner_id", SqlScalarType::String.nullable(false))
1846 .with_column(
1847 "privileges",
1848 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
1849 )
1850 .with_column("create_sql", SqlScalarType::String.nullable(false))
1851 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
1852 .with_key(vec![0])
1853 .with_key(vec![1])
1854 .finish(),
1855 column_comments: BTreeMap::from_iter([
1856 ("id", "Materialize's unique ID for the view."),
1857 ("oid", "A PostgreSQL-compatible OID for the view."),
1858 (
1859 "schema_id",
1860 "The ID of the schema to which the view belongs. Corresponds to `mz_schemas.id`.",
1861 ),
1862 ("name", "The name of the view."),
1863 ("definition", "The view definition (a `SELECT` query)."),
1864 (
1865 "owner_id",
1866 "The role ID of the owner of the view. Corresponds to `mz_roles.id`.",
1867 ),
1868 ("privileges", "The privileges belonging to the view."),
1869 ("create_sql", "The `CREATE` SQL statement for the view."),
1870 (
1871 "redacted_create_sql",
1872 "The redacted `CREATE` SQL statement for the view.",
1873 ),
1874 ]),
1875 sql: Box::leak(format!("
1882IN CLUSTER mz_catalog_server
1883WITH (
1884 ASSERT NOT NULL id,
1885 ASSERT NOT NULL oid,
1886 ASSERT NOT NULL schema_id,
1887 ASSERT NOT NULL name,
1888 ASSERT NOT NULL definition,
1889 ASSERT NOT NULL owner_id,
1890 ASSERT NOT NULL privileges,
1891 ASSERT NOT NULL create_sql,
1892 ASSERT NOT NULL redacted_create_sql
1893) AS
1894WITH
1895 user_views AS (
1896 SELECT
1897 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
1898 (data->'value'->>'oid')::oid AS oid,
1899 CASE WHEN data->'value'->>'ephemeral_owner_session' IS NULL
1900 THEN mz_internal.parse_catalog_id(data->'value'->'schema_id')
1901 ELSE '0'
1902 END AS schema_id,
1903 data->'value'->>'name' AS name,
1904 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'definition' AS definition,
1905 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
1906 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges,
1907 data->'value'->'definition'->'V1'->>'create_sql' AS create_sql,
1908 mz_internal.redact_sql(data->'value'->'definition'->'V1'->>'create_sql') AS redacted_create_sql
1909 FROM mz_internal.mz_catalog_raw
1910 WHERE
1911 data->>'kind' = 'Item' AND
1912 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'type' = 'view'
1913 ),
1914 builtin_mappings AS (
1915 SELECT
1916 data->'key'->>'schema_name' AS schema_name,
1917 data->'key'->>'object_name' AS name,
1918 's' || (data->'value'->>'catalog_id') AS id
1919 FROM mz_internal.mz_catalog_raw
1920 WHERE
1921 data->>'kind' = 'GidMapping' AND
1922 data->'key'->>'object_type' = '4'
1923 ),
1924 builtin_views AS (
1925 SELECT
1926 m.id,
1927 v.oid,
1928 s.id AS schema_id,
1929 v.name,
1930 v.definition,
1931 '{MZ_SYSTEM_ROLE_ID}' AS owner_id,
1932 v.privileges,
1933 v.create_sql,
1934 mz_internal.redact_sql(v.create_sql) AS redacted_create_sql
1935 FROM mz_internal.mz_builtin_views v
1936 JOIN builtin_mappings m USING (schema_name, name)
1937 JOIN mz_schemas s ON s.name = v.schema_name
1938 WHERE s.database_id IS NULL
1939 )
1940SELECT * FROM user_views
1941UNION ALL
1942SELECT * FROM builtin_views").into_boxed_str()),
1943 is_retained_metrics_object: false,
1944 access: vec![PUBLIC_SELECT],
1945 ontology: Some(Ontology {
1946 entity_name: "view",
1947 description: "A non-materialized view defined by a SQL query",
1948 links: &const {
1949 [
1950 OntologyLink {
1951 name: "in_schema",
1952 target: "schema",
1953 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
1954 },
1955 OntologyLink {
1956 name: "owned_by",
1957 target: "role",
1958 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
1959 },
1960 ]
1961 },
1962 column_semantic_types: &const {
1963 [
1964 ("id", SemanticType::CatalogItemId),
1965 ("oid", SemanticType::OID),
1966 ("schema_id", SemanticType::SchemaId),
1967 ("definition", SemanticType::SqlDefinition),
1968 ("owner_id", SemanticType::RoleId),
1969 ("create_sql", SemanticType::SqlDefinition),
1970 ("redacted_create_sql", SemanticType::RedactedSqlDefinition),
1971 ]
1972 },
1973 }),
1974}
1975});
1976
1977pub static MZ_MATERIALIZED_VIEWS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
1978 BuiltinMaterializedView {
1979 name: "mz_materialized_views",
1980 schema: MZ_CATALOG_SCHEMA,
1981 oid: oid::MV_MZ_MATERIALIZED_VIEWS_OID,
1982 desc: RelationDesc::builder()
1983 .with_column("id", SqlScalarType::String.nullable(false))
1984 .with_column("oid", SqlScalarType::Oid.nullable(false))
1985 .with_column("schema_id", SqlScalarType::String.nullable(false))
1986 .with_column("name", SqlScalarType::String.nullable(false))
1987 .with_column("cluster_id", SqlScalarType::String.nullable(false))
1988 .with_column("definition", SqlScalarType::String.nullable(false))
1989 .with_column("owner_id", SqlScalarType::String.nullable(false))
1990 .with_column(
1991 "privileges",
1992 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
1993 )
1994 .with_column("create_sql", SqlScalarType::String.nullable(false))
1995 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
1996 .with_key(vec![0])
1997 .with_key(vec![1])
1998 .finish(),
1999 column_comments: BTreeMap::from_iter([
2000 ("id", "Materialize's unique ID for the materialized view."),
2001 (
2002 "oid",
2003 "A PostgreSQL-compatible OID for the materialized view.",
2004 ),
2005 (
2006 "schema_id",
2007 "The ID of the schema to which the materialized view belongs. Corresponds to `mz_schemas.id`.",
2008 ),
2009 ("name", "The name of the materialized view."),
2010 (
2011 "cluster_id",
2012 "The ID of the cluster maintaining the materialized view. Corresponds to `mz_clusters.id`.",
2013 ),
2014 (
2015 "definition",
2016 "The materialized view definition (a `SELECT` query).",
2017 ),
2018 (
2019 "owner_id",
2020 "The role ID of the owner of the materialized view. Corresponds to `mz_roles.id`.",
2021 ),
2022 (
2023 "privileges",
2024 "The privileges belonging to the materialized view.",
2025 ),
2026 (
2027 "create_sql",
2028 "The `CREATE` SQL statement for the materialized view.",
2029 ),
2030 (
2031 "redacted_create_sql",
2032 "The redacted `CREATE` SQL statement for the materialized view.",
2033 ),
2034 ]),
2035 sql: Box::leak(format!("
2036IN CLUSTER mz_catalog_server
2037WITH (
2038 ASSERT NOT NULL id,
2039 ASSERT NOT NULL oid,
2040 ASSERT NOT NULL schema_id,
2041 ASSERT NOT NULL name,
2042 ASSERT NOT NULL cluster_id,
2043 ASSERT NOT NULL definition,
2044 ASSERT NOT NULL owner_id,
2045 ASSERT NOT NULL privileges,
2046 ASSERT NOT NULL create_sql,
2047 ASSERT NOT NULL redacted_create_sql
2048) AS
2049WITH
2050 user_mvs AS (
2051 SELECT
2052 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
2053 (data->'value'->>'oid')::oid AS oid,
2054 mz_internal.parse_catalog_id(data->'value'->'schema_id') AS schema_id,
2055 data->'value'->>'name' AS name,
2056 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'cluster_id' AS cluster_id,
2057 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'definition' AS definition,
2058 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
2059 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges,
2060 data->'value'->'definition'->'V1'->>'create_sql' AS create_sql,
2061 mz_internal.redact_sql(data->'value'->'definition'->'V1'->>'create_sql') AS redacted_create_sql
2062 FROM mz_internal.mz_catalog_raw
2063 WHERE
2064 data->>'kind' = 'Item' AND
2065 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'type' = 'materialized-view'
2066 ),
2067 builtin_mappings AS (
2068 SELECT
2069 data->'key'->>'schema_name' AS schema_name,
2070 data->'key'->>'object_name' AS name,
2071 's' || (data->'value'->>'catalog_id') AS id
2072 FROM mz_internal.mz_catalog_raw
2073 WHERE
2074 data->>'kind' = 'GidMapping' AND
2075 data->'key'->>'object_type' = '5'
2076 ),
2077 builtin_mvs AS (
2078 SELECT
2079 m.id,
2080 mv.oid,
2081 s.id AS schema_id,
2082 mv.name,
2083 c.id AS cluster_id,
2084 mv.definition,
2085 '{MZ_SYSTEM_ROLE_ID}' AS owner_id,
2086 mv.privileges,
2087 mv.create_sql,
2088 mz_internal.redact_sql(mv.create_sql) AS redacted_create_sql
2089 FROM mz_internal.mz_builtin_materialized_views mv
2090 JOIN builtin_mappings m USING (schema_name, name)
2091 JOIN mz_schemas s ON s.name = mv.schema_name
2092 JOIN mz_clusters c ON c.name = mv.cluster_name
2093 WHERE s.database_id IS NULL
2094 )
2095SELECT * FROM user_mvs
2096UNION ALL
2097SELECT * FROM builtin_mvs").into_boxed_str()),
2098 is_retained_metrics_object: false,
2099 access: vec![PUBLIC_SELECT],
2100 ontology: Some(Ontology {
2101 entity_name: "mv",
2102 description: "A materialized view maintained incrementally on a cluster",
2103 links: &const { [
2104 OntologyLink { name: "in_schema", target: "schema", properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne) },
2105 OntologyLink { name: "owned_by", target: "role", properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne) },
2106 OntologyLink { name: "runs_on_cluster", target: "cluster", properties: LinkProperties::fk("cluster_id", "id", Cardinality::ManyToOne) },
2107 ] },
2108 column_semantic_types: &const {[("id", SemanticType::CatalogItemId), ("oid", SemanticType::OID), ("schema_id", SemanticType::SchemaId), ("cluster_id", SemanticType::ClusterId), ("definition", SemanticType::SqlDefinition), ("owner_id", SemanticType::RoleId), ("create_sql", SemanticType::SqlDefinition), ("redacted_create_sql", SemanticType::RedactedSqlDefinition)]},
2109 }),
2110 }
2111});
2112pub static MZ_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2113 name: "mz_types",
2114 schema: MZ_CATALOG_SCHEMA,
2115 oid: oid::TABLE_MZ_TYPES_OID,
2116 desc: RelationDesc::builder()
2117 .with_column("id", SqlScalarType::String.nullable(false))
2118 .with_column("oid", SqlScalarType::Oid.nullable(false))
2119 .with_column("schema_id", SqlScalarType::String.nullable(false))
2120 .with_column("name", SqlScalarType::String.nullable(false))
2121 .with_column("category", SqlScalarType::String.nullable(false))
2122 .with_column("owner_id", SqlScalarType::String.nullable(false))
2123 .with_column(
2124 "privileges",
2125 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2126 )
2127 .with_column("create_sql", SqlScalarType::String.nullable(true))
2128 .with_column("redacted_create_sql", SqlScalarType::String.nullable(true))
2129 .with_key(vec![0])
2130 .with_key(vec![1])
2131 .finish(),
2132 column_comments: BTreeMap::from_iter([
2133 ("id", "Materialize's unique ID for the type."),
2134 ("oid", "A PostgreSQL-compatible OID for the type."),
2135 (
2136 "schema_id",
2137 "The ID of the schema to which the type belongs. Corresponds to `mz_schemas.id`.",
2138 ),
2139 ("name", "The name of the type."),
2140 ("category", "The category of the type."),
2141 (
2142 "owner_id",
2143 "The role ID of the owner of the type. Corresponds to `mz_roles.id`.",
2144 ),
2145 ("privileges", "The privileges belonging to the type."),
2146 ("create_sql", "The `CREATE` SQL statement for the type."),
2147 (
2148 "redacted_create_sql",
2149 "The redacted `CREATE` SQL statement for the type.",
2150 ),
2151 ]),
2152 is_retained_metrics_object: false,
2153 access: vec![PUBLIC_SELECT],
2154 ontology: Some(Ontology {
2155 entity_name: "type",
2156 description: "A named data type (base, array, list, map, or pseudo)",
2157 links: &const {
2158 [
2159 OntologyLink {
2160 name: "in_schema",
2161 target: "schema",
2162 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
2163 },
2164 OntologyLink {
2165 name: "owned_by",
2166 target: "role",
2167 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
2168 },
2169 ]
2170 },
2171 column_semantic_types: &const {
2172 [
2173 ("id", SemanticType::CatalogItemId),
2174 ("oid", SemanticType::OID),
2175 ("schema_id", SemanticType::SchemaId),
2176 ("owner_id", SemanticType::RoleId),
2177 ("create_sql", SemanticType::SqlDefinition),
2178 ("redacted_create_sql", SemanticType::RedactedSqlDefinition),
2179 ]
2180 },
2181 }),
2182});
2183pub static MZ_ARRAY_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2184 name: "mz_array_types",
2185 schema: MZ_CATALOG_SCHEMA,
2186 oid: oid::TABLE_MZ_ARRAY_TYPES_OID,
2187 desc: RelationDesc::builder()
2188 .with_column("id", SqlScalarType::String.nullable(false))
2189 .with_column("element_id", SqlScalarType::String.nullable(false))
2190 .finish(),
2191 column_comments: BTreeMap::from_iter([
2192 ("id", "The ID of the array type."),
2193 ("element_id", "The ID of the array's element type."),
2194 ]),
2195 is_retained_metrics_object: false,
2196 access: vec![PUBLIC_SELECT],
2197 ontology: Some(Ontology {
2198 entity_name: "array_type",
2199 description: "An array type with its element type",
2200 links: &const {
2201 [
2202 OntologyLink {
2203 name: "detail_of",
2204 target: "type",
2205 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
2206 },
2207 OntologyLink {
2208 name: "has_element_type",
2209 target: "type",
2210 properties: LinkProperties::fk("element_id", "id", Cardinality::ManyToOne),
2211 },
2212 ]
2213 },
2214 column_semantic_types: &const {
2215 [
2216 ("id", SemanticType::CatalogItemId),
2217 ("element_id", SemanticType::CatalogItemId),
2218 ]
2219 },
2220 }),
2221});
2222pub static MZ_BASE_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2223 name: "mz_base_types",
2224 schema: MZ_CATALOG_SCHEMA,
2225 oid: oid::TABLE_MZ_BASE_TYPES_OID,
2226 desc: RelationDesc::builder()
2227 .with_column("id", SqlScalarType::String.nullable(false))
2228 .finish(),
2229 column_comments: BTreeMap::from_iter([("id", "The ID of the type.")]),
2230 is_retained_metrics_object: false,
2231 access: vec![PUBLIC_SELECT],
2232 ontology: Some(Ontology {
2233 entity_name: "base_type",
2234 description: "A primitive/base data type",
2235 links: &const { [] },
2236 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
2237 }),
2238});
2239pub static MZ_LIST_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2240 name: "mz_list_types",
2241 schema: MZ_CATALOG_SCHEMA,
2242 oid: oid::TABLE_MZ_LIST_TYPES_OID,
2243 desc: RelationDesc::builder()
2244 .with_column("id", SqlScalarType::String.nullable(false))
2245 .with_column("element_id", SqlScalarType::String.nullable(false))
2246 .with_column(
2247 "element_modifiers",
2248 SqlScalarType::List {
2249 element_type: Box::new(SqlScalarType::Int64),
2250 custom_id: None,
2251 }
2252 .nullable(true),
2253 )
2254 .finish(),
2255 column_comments: BTreeMap::from_iter([
2256 ("id", "The ID of the list type."),
2257 ("element_id", "The IID of the list's element type."),
2258 (
2259 "element_modifiers",
2260 "The element type modifiers, or `NULL` if none.",
2261 ),
2262 ]),
2263 is_retained_metrics_object: false,
2264 access: vec![PUBLIC_SELECT],
2265 ontology: Some(Ontology {
2266 entity_name: "list_type",
2267 description: "A list type with its element type",
2268 links: &const {
2269 [
2270 OntologyLink {
2271 name: "detail_of",
2272 target: "type",
2273 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
2274 },
2275 OntologyLink {
2276 name: "has_element_type",
2277 target: "type",
2278 properties: LinkProperties::fk("element_id", "id", Cardinality::ManyToOne),
2279 },
2280 ]
2281 },
2282 column_semantic_types: &const {
2283 [
2284 ("id", SemanticType::CatalogItemId),
2285 ("element_id", SemanticType::CatalogItemId),
2286 ]
2287 },
2288 }),
2289});
2290pub static MZ_MAP_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2291 name: "mz_map_types",
2292 schema: MZ_CATALOG_SCHEMA,
2293 oid: oid::TABLE_MZ_MAP_TYPES_OID,
2294 desc: RelationDesc::builder()
2295 .with_column("id", SqlScalarType::String.nullable(false))
2296 .with_column("key_id", SqlScalarType::String.nullable(false))
2297 .with_column("value_id", SqlScalarType::String.nullable(false))
2298 .with_column(
2299 "key_modifiers",
2300 SqlScalarType::List {
2301 element_type: Box::new(SqlScalarType::Int64),
2302 custom_id: None,
2303 }
2304 .nullable(true),
2305 )
2306 .with_column(
2307 "value_modifiers",
2308 SqlScalarType::List {
2309 element_type: Box::new(SqlScalarType::Int64),
2310 custom_id: None,
2311 }
2312 .nullable(true),
2313 )
2314 .finish(),
2315 column_comments: BTreeMap::from_iter([
2316 ("id", "The ID of the map type."),
2317 ("key_id", "The ID of the map's key type."),
2318 ("value_id", "The ID of the map's value type."),
2319 (
2320 "key_modifiers",
2321 "The key type modifiers, or `NULL` if none.",
2322 ),
2323 (
2324 "value_modifiers",
2325 "The value type modifiers, or `NULL` if none.",
2326 ),
2327 ]),
2328 is_retained_metrics_object: false,
2329 access: vec![PUBLIC_SELECT],
2330 ontology: Some(Ontology {
2331 entity_name: "map_type",
2332 description: "A map type with its key and value types",
2333 links: &const {
2334 [
2335 OntologyLink {
2336 name: "detail_of",
2337 target: "type",
2338 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
2339 },
2340 OntologyLink {
2341 name: "has_key_type",
2342 target: "type",
2343 properties: LinkProperties::fk("key_id", "id", Cardinality::ManyToOne),
2344 },
2345 OntologyLink {
2346 name: "has_value_type",
2347 target: "type",
2348 properties: LinkProperties::fk("value_id", "id", Cardinality::ManyToOne),
2349 },
2350 ]
2351 },
2352 column_semantic_types: &const {
2353 [
2354 ("id", SemanticType::CatalogItemId),
2355 ("key_id", SemanticType::CatalogItemId),
2356 ("value_id", SemanticType::CatalogItemId),
2357 ]
2358 },
2359 }),
2360});
2361pub static MZ_ROLES: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
2362 let sql = format!(
2366 "
2367IN CLUSTER mz_catalog_server
2368WITH (
2369 ASSERT NOT NULL id,
2370 ASSERT NOT NULL oid,
2371 ASSERT NOT NULL name,
2372 ASSERT NOT NULL inherit
2373) AS
2374SELECT
2375 mz_internal.parse_catalog_id(data->'key'->'id') AS id,
2376 (data->'value'->>'oid')::oid AS oid,
2377 data->'value'->>'name' AS name,
2378 (data->'value'->'attributes'->>'inherit')::bool AS inherit,
2379 COALESCE(
2380 (data->'value'->'attributes'->>'login')::bool,
2381 data->'value'->>'name' IN ('{system}', '{support}')
2382 ) AS rolcanlogin,
2383 COALESCE(
2384 (data->'value'->'attributes'->>'superuser')::bool,
2385 CASE WHEN data->'value'->>'name' IN ('{system}', '{support}') THEN true END
2386 ) AS rolsuper
2387FROM mz_internal.mz_catalog_raw
2388WHERE data->>'kind' = 'Role' AND data->'key'->'id' != '\"Public\"'::jsonb",
2389 system = SYSTEM_USER_NAME,
2390 support = SUPPORT_USER_NAME,
2391 );
2392
2393 BuiltinMaterializedView {
2394 name: "mz_roles",
2395 schema: MZ_CATALOG_SCHEMA,
2396 oid: oid::MV_MZ_ROLES_OID,
2397 desc: RelationDesc::builder()
2398 .with_column("id", SqlScalarType::String.nullable(false))
2399 .with_column("oid", SqlScalarType::Oid.nullable(false))
2400 .with_column("name", SqlScalarType::String.nullable(false))
2401 .with_column("inherit", SqlScalarType::Bool.nullable(false))
2402 .with_column("rolcanlogin", SqlScalarType::Bool.nullable(true))
2403 .with_column("rolsuper", SqlScalarType::Bool.nullable(true))
2404 .with_key(vec![0])
2405 .with_key(vec![1])
2406 .finish(),
2407 column_comments: BTreeMap::from_iter([
2408 ("id", "Materialize's unique ID for the role."),
2409 ("oid", "A PostgreSQL-compatible OID for the role."),
2410 ("name", "The name of the role."),
2411 (
2412 "inherit",
2413 "Indicates whether the role has inheritance of privileges.",
2414 ),
2415 ("rolcanlogin", "Indicates whether the role can log in."),
2416 ("rolsuper", "Indicates whether the role is a superuser."),
2417 ]),
2418 sql: Box::leak(sql.into_boxed_str()),
2419 is_retained_metrics_object: false,
2420 access: vec![PUBLIC_SELECT],
2421 ontology: Some(Ontology {
2422 entity_name: "role",
2423 description: "A user or role for authentication and access control",
2424 links: &const { [] },
2425 column_semantic_types: &const { [("id", SemanticType::RoleId), ("oid", SemanticType::OID)] },
2426 }),
2427 }
2428});
2429
2430pub static MZ_ROLE_MEMBERS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
2431 BuiltinMaterializedView {
2432 name: "mz_role_members",
2433 schema: MZ_CATALOG_SCHEMA,
2434 oid: oid::MV_MZ_ROLE_MEMBERS_OID,
2435 desc: RelationDesc::builder()
2436 .with_column("role_id", SqlScalarType::String.nullable(false))
2437 .with_column("member", SqlScalarType::String.nullable(false))
2438 .with_column("grantor", SqlScalarType::String.nullable(false))
2439 .finish(),
2440 column_comments: BTreeMap::from_iter([
2441 (
2442 "role_id",
2443 "The ID of the role the `member` is a member of. Corresponds to `mz_roles.id`.",
2444 ),
2445 (
2446 "member",
2447 "The ID of the role that is a member of `role_id`. Corresponds to `mz_roles.id`.",
2448 ),
2449 (
2450 "grantor",
2451 "The ID of the role that granted membership of `member` to `role_id`. Corresponds to `mz_roles.id`.",
2452 ),
2453 ]),
2454 sql: "
2455IN CLUSTER mz_catalog_server
2456WITH (
2457 ASSERT NOT NULL role_id,
2458 ASSERT NOT NULL member,
2459 ASSERT NOT NULL grantor
2460) AS
2461SELECT
2462 mz_internal.parse_catalog_id(entry->'key') AS role_id,
2463 mz_internal.parse_catalog_id(data->'key'->'id') AS member,
2464 mz_internal.parse_catalog_id(entry->'value') AS grantor
2465FROM
2466 mz_internal.mz_catalog_raw,
2467 jsonb_array_elements(data->'value'->'membership'->'map') AS entry
2468WHERE data->>'kind' = 'Role'",
2469 is_retained_metrics_object: false,
2470 access: vec![PUBLIC_SELECT],
2471 ontology: Some(Ontology {
2472 entity_name: "role_membership",
2473 description: "A membership grant: one role is a member of another role",
2474 links: &const {
2475 [
2476 OntologyLink {
2477 name: "group_role",
2478 target: "role",
2479 properties: LinkProperties::fk("role_id", "id", Cardinality::ManyToOne),
2480 },
2481 OntologyLink {
2482 name: "member_role",
2483 target: "role",
2484 properties: LinkProperties::fk("member", "id", Cardinality::ManyToOne),
2485 },
2486 OntologyLink {
2487 name: "granted_by",
2488 target: "role",
2489 properties: LinkProperties::fk("grantor", "id", Cardinality::ManyToOne),
2490 },
2491 ]
2492 },
2493 column_semantic_types: &const {
2494 [
2495 ("role_id", SemanticType::RoleId),
2496 ("member", SemanticType::RoleId),
2497 ("grantor", SemanticType::RoleId),
2498 ]
2499 },
2500 }),
2501 }
2502});
2503
2504pub static MZ_ROLE_PARAMETERS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
2505 BuiltinMaterializedView {
2506 name: "mz_role_parameters",
2507 schema: MZ_CATALOG_SCHEMA,
2508 oid: oid::MV_MZ_ROLE_PARAMETERS_OID,
2509 desc: RelationDesc::builder()
2510 .with_column("role_id", SqlScalarType::String.nullable(false))
2511 .with_column("parameter_name", SqlScalarType::String.nullable(false))
2512 .with_column("parameter_value", SqlScalarType::String.nullable(false))
2513 .finish(),
2514 column_comments: BTreeMap::from_iter([
2515 (
2516 "role_id",
2517 "The ID of the role whose configuration parameter default is set. Corresponds to `mz_roles.id`.",
2518 ),
2519 (
2520 "parameter_name",
2521 "The configuration parameter name. One of the supported configuration parameters.",
2522 ),
2523 (
2524 "parameter_value",
2525 "The default value of the parameter for the given role. Can be either a single value, or a comma-separated list of values for configuration parameters that accept a list.",
2526 ),
2527 ]),
2528 sql: "
2529IN CLUSTER mz_catalog_server
2530WITH (
2531 ASSERT NOT NULL role_id,
2532 ASSERT NOT NULL parameter_name,
2533 ASSERT NOT NULL parameter_value
2534) AS
2535SELECT
2536 mz_internal.parse_catalog_id(data->'key'->'id') AS role_id,
2537 entry->>'key' AS parameter_name,
2538 CASE
2539 WHEN entry->'val' ? 'Flat' THEN entry->'val'->>'Flat'
2540 ELSE (
2541 SELECT pg_catalog.string_agg(t.elem, ', ' ORDER BY t.ord)
2542 FROM jsonb_array_elements_text(entry->'val'->'SqlSet')
2543 WITH ORDINALITY AS t(elem, ord)
2544 )
2545 END AS parameter_value
2546FROM
2547 mz_internal.mz_catalog_raw,
2548 jsonb_array_elements(data->'value'->'vars'->'entries') AS entry
2549WHERE data->>'kind' = 'Role'",
2550 is_retained_metrics_object: false,
2551 access: vec![PUBLIC_SELECT],
2552 ontology: Some(Ontology {
2553 entity_name: "role_parameter",
2554 description: "A session parameter default set for a role",
2555 links: &const {
2556 [OntologyLink {
2557 name: "default_parameter_setting_of",
2558 target: "role",
2559 properties: LinkProperties::fk("role_id", "id", Cardinality::ManyToOne),
2560 }]
2561 },
2562 column_semantic_types: &[("role_id", SemanticType::RoleId)],
2563 }),
2564 }
2565});
2566pub static MZ_ROLE_AUTH: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2567 name: "mz_role_auth",
2568 schema: MZ_CATALOG_SCHEMA,
2569 oid: oid::TABLE_MZ_ROLE_AUTH_OID,
2570 desc: RelationDesc::builder()
2571 .with_column("role_id", SqlScalarType::String.nullable(false))
2572 .with_column("role_oid", SqlScalarType::Oid.nullable(false))
2573 .with_column("password_hash", SqlScalarType::String.nullable(true))
2574 .with_column(
2575 "updated_at",
2576 SqlScalarType::TimestampTz { precision: None }.nullable(false),
2577 )
2578 .finish(),
2579 column_comments: BTreeMap::from_iter([
2580 (
2581 "role_id",
2582 "The ID of the role. Corresponds to `mz_roles.id`.",
2583 ),
2584 ("role_oid", "A PostgreSQL-compatible OID for the role."),
2585 (
2586 "password_hash",
2587 "The hashed password for the role, if any. Uses the `SCRAM-SHA-256` algorithm.",
2588 ),
2589 (
2590 "updated_at",
2591 "The time at which the password was last updated.",
2592 ),
2593 ]),
2594 is_retained_metrics_object: false,
2595 access: vec![rbac::owner_privilege(ObjectType::Table, MZ_SYSTEM_ROLE_ID)],
2596 ontology: None,
2597});
2598pub static MZ_PSEUDO_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2599 name: "mz_pseudo_types",
2600 schema: MZ_CATALOG_SCHEMA,
2601 oid: oid::TABLE_MZ_PSEUDO_TYPES_OID,
2602 desc: RelationDesc::builder()
2603 .with_column("id", SqlScalarType::String.nullable(false))
2604 .finish(),
2605 column_comments: BTreeMap::from_iter([("id", "The ID of the type.")]),
2606 is_retained_metrics_object: false,
2607 access: vec![PUBLIC_SELECT],
2608 ontology: Some(Ontology {
2609 entity_name: "pseudo_type",
2610 description: "A pseudo-type used in function signatures",
2611 links: &const { [] },
2612 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
2613 }),
2614});
2615pub static MZ_FUNCTIONS: LazyLock<BuiltinTable> = LazyLock::new(|| {
2616 BuiltinTable {
2617 name: "mz_functions",
2618 schema: MZ_CATALOG_SCHEMA,
2619 oid: oid::TABLE_MZ_FUNCTIONS_OID,
2620 desc: RelationDesc::builder()
2621 .with_column("id", SqlScalarType::String.nullable(false)) .with_column("oid", SqlScalarType::Oid.nullable(false))
2623 .with_column("schema_id", SqlScalarType::String.nullable(false))
2624 .with_column("name", SqlScalarType::String.nullable(false))
2625 .with_column(
2626 "argument_type_ids",
2627 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
2628 )
2629 .with_column(
2630 "variadic_argument_type_id",
2631 SqlScalarType::String.nullable(true),
2632 )
2633 .with_column("return_type_id", SqlScalarType::String.nullable(true))
2634 .with_column("returns_set", SqlScalarType::Bool.nullable(false))
2635 .with_column("owner_id", SqlScalarType::String.nullable(false))
2636 .finish(),
2637 column_comments: BTreeMap::from_iter([
2638 ("id", "Materialize's unique ID for the function."),
2639 ("oid", "A PostgreSQL-compatible OID for the function."),
2640 (
2641 "schema_id",
2642 "The ID of the schema to which the function belongs. Corresponds to `mz_schemas.id`.",
2643 ),
2644 ("name", "The name of the function."),
2645 (
2646 "argument_type_ids",
2647 "The ID of each argument's type. Each entry refers to `mz_types.id`.",
2648 ),
2649 (
2650 "variadic_argument_type_id",
2651 "The ID of the variadic argument's type, or `NULL` if the function does not have a variadic argument. Refers to `mz_types.id`.",
2652 ),
2653 (
2654 "return_type_id",
2655 "The returned value's type, or `NULL` if the function does not return a value. Refers to `mz_types.id`. Note that for table functions with > 1 column, this type corresponds to [`record`].",
2656 ),
2657 (
2658 "returns_set",
2659 "Whether the function returns a set, i.e. the function is a table function.",
2660 ),
2661 (
2662 "owner_id",
2663 "The role ID of the owner of the function. Corresponds to `mz_roles.id`.",
2664 ),
2665 ]),
2666 is_retained_metrics_object: false,
2667 access: vec![PUBLIC_SELECT],
2668 ontology: Some(Ontology {
2669 entity_name: "function",
2670 description: "A built-in or user-defined function",
2671 links: &const {
2672 [
2673 OntologyLink {
2674 name: "in_schema",
2675 target: "schema",
2676 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
2677 },
2678 OntologyLink {
2679 name: "owned_by",
2680 target: "role",
2681 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
2682 },
2683 OntologyLink {
2684 name: "returns_type",
2685 target: "type",
2686 properties: LinkProperties::fk_nullable(
2687 "return_type_id",
2688 "id",
2689 Cardinality::ManyToOne,
2690 ),
2691 },
2692 OntologyLink {
2693 name: "has_variadic_arg_type",
2694 target: "type",
2695 properties: LinkProperties::fk_nullable(
2696 "variadic_argument_type_id",
2697 "id",
2698 Cardinality::ManyToOne,
2699 ),
2700 },
2701 ]
2702 },
2703 column_semantic_types: &const {
2704 [
2705 ("id", SemanticType::CatalogItemId),
2706 ("oid", SemanticType::OID),
2707 ("schema_id", SemanticType::SchemaId),
2708 ("variadic_argument_type_id", SemanticType::CatalogItemId),
2709 ("return_type_id", SemanticType::CatalogItemId),
2710 ("owner_id", SemanticType::RoleId),
2711 ]
2712 },
2713 }),
2714 }
2715});
2716pub static MZ_OPERATORS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2717 name: "mz_operators",
2718 schema: MZ_CATALOG_SCHEMA,
2719 oid: oid::TABLE_MZ_OPERATORS_OID,
2720 desc: RelationDesc::builder()
2721 .with_column("oid", SqlScalarType::Oid.nullable(false))
2722 .with_column("name", SqlScalarType::String.nullable(false))
2723 .with_column(
2724 "argument_type_ids",
2725 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
2726 )
2727 .with_column("return_type_id", SqlScalarType::String.nullable(true))
2728 .finish(),
2729 column_comments: BTreeMap::new(),
2730 is_retained_metrics_object: false,
2731 access: vec![PUBLIC_SELECT],
2732 ontology: Some(Ontology {
2733 entity_name: "operator",
2734 description: "A built-in SQL operator",
2735 links: &const {
2736 [OntologyLink {
2737 name: "returns_type",
2738 target: "type",
2739 properties: LinkProperties::fk_nullable(
2740 "return_type_id",
2741 "id",
2742 Cardinality::ManyToOne,
2743 ),
2744 }]
2745 },
2746 column_semantic_types: &const {
2747 [
2748 ("oid", SemanticType::OID),
2749 ("return_type_id", SemanticType::CatalogItemId),
2750 ]
2751 },
2752 }),
2753});
2754
2755pub static MZ_CLUSTERS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
2756 BuiltinMaterializedView {
2757 name: "mz_clusters",
2758 schema: MZ_CATALOG_SCHEMA,
2759 oid: oid::MV_MZ_CLUSTERS_OID,
2760 desc: RelationDesc::builder()
2761 .with_column("id", SqlScalarType::String.nullable(false))
2762 .with_column("name", SqlScalarType::String.nullable(false))
2763 .with_column("owner_id", SqlScalarType::String.nullable(false))
2764 .with_column(
2765 "privileges",
2766 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2767 )
2768 .with_column("managed", SqlScalarType::Bool.nullable(false))
2769 .with_column("size", SqlScalarType::String.nullable(true))
2770 .with_column("replication_factor", SqlScalarType::UInt32.nullable(true))
2771 .with_column("disk", SqlScalarType::Bool.nullable(true))
2772 .with_column(
2773 "availability_zones",
2774 SqlScalarType::List {
2775 element_type: Box::new(SqlScalarType::String),
2776 custom_id: None,
2777 }
2778 .nullable(true),
2779 )
2780 .with_column(
2781 "introspection_debugging",
2782 SqlScalarType::Bool.nullable(true),
2783 )
2784 .with_column(
2785 "introspection_interval",
2786 SqlScalarType::Interval.nullable(true),
2787 )
2788 .with_key(vec![0])
2789 .finish(),
2790 column_comments: BTreeMap::from_iter([
2791 ("id", "Materialize's unique ID for the cluster."),
2792 ("name", "The name of the cluster."),
2793 (
2794 "owner_id",
2795 "The role ID of the owner of the cluster. Corresponds to `mz_roles.id`.",
2796 ),
2797 ("privileges", "The privileges belonging to the cluster."),
2798 (
2799 "managed",
2800 "Whether the cluster is a managed cluster with automatically managed replicas.",
2801 ),
2802 (
2803 "size",
2804 "If the cluster is managed, the desired size of the cluster's replicas. `NULL` for unmanaged clusters.",
2805 ),
2806 (
2807 "replication_factor",
2808 "If the cluster is managed, the desired number of replicas of the cluster. `NULL` for unmanaged clusters.",
2809 ),
2810 (
2811 "disk",
2812 "**Unstable** If the cluster is managed, `true` if the replicas have the `DISK` option . `NULL` for unmanaged clusters.",
2813 ),
2814 (
2815 "availability_zones",
2816 "**Unstable** If the cluster is managed, the list of availability zones specified in `AVAILABILITY ZONES`. `NULL` for unmanaged clusters.",
2817 ),
2818 (
2819 "introspection_debugging",
2820 "Whether introspection of the gathering of the introspection data is enabled.",
2821 ),
2822 (
2823 "introspection_interval",
2824 "The interval at which to collect introspection data.",
2825 ),
2826 ]),
2827 sql: "
2851IN CLUSTER mz_catalog_server
2852WITH (
2853 ASSERT NOT NULL id,
2854 ASSERT NOT NULL name,
2855 ASSERT NOT NULL owner_id,
2856 ASSERT NOT NULL privileges,
2857 ASSERT NOT NULL managed
2858) AS
2859SELECT
2860 mz_internal.parse_catalog_id(data->'key'->'id') AS id,
2861 data->'value'->>'name' AS name,
2862 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
2863 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges,
2864 jsonb_typeof(data->'value'->'config'->'variant') = 'object' AS managed,
2865 data->'value'->'config'->'variant'->'Managed'->>'size' AS size,
2866 (data->'value'->'config'->'variant'->'Managed'->>'replication_factor')::uint4 AS replication_factor,
2867 CASE
2868 WHEN jsonb_typeof(data->'value'->'config'->'variant') = 'object' THEN
2869 NOT COALESCE(internal.swap_enabled, false)
2870 AND COALESCE(internal.disk_bytes, 0) != 0
2871 END AS disk,
2872 CASE
2873 WHEN jsonb_array_length(data->'value'->'config'->'variant'->'Managed'->'availability_zones') > 0 THEN
2874 (
2875 SELECT mz_catalog.list_agg(az.value ORDER BY az.ord)
2876 FROM jsonb_array_elements_text(data->'value'->'config'->'variant'->'Managed'->'availability_zones')
2877 WITH ORDINALITY AS az(value, ord)
2878 )
2879 END AS availability_zones,
2880 (data->'value'->'config'->'variant'->'Managed'->'logging'->>'log_logging')::bool AS introspection_debugging,
2881 CASE
2882 WHEN data->'value'->'config'->'variant'->'Managed'->'logging'->'interval' != 'null'::jsonb THEN
2883 (
2884 (data->'value'->'config'->'variant'->'Managed'->'logging'->'interval'->>'secs')
2885 || ' seconds '
2886 || ((data->'value'->'config'->'variant'->'Managed'->'logging'->'interval'->>'nanos')::bigint / 1000)::text
2887 || ' microseconds'
2888 )::interval
2889 END AS introspection_interval
2890FROM (
2891 SELECT data FROM mz_internal.mz_catalog_raw WHERE data->>'kind' = 'Cluster'
2892) raw
2893LEFT JOIN mz_internal.mz_cluster_replica_size_internal internal
2894 ON internal.size = data->'value'->'config'->'variant'->'Managed'->>'size'",
2895 is_retained_metrics_object: false,
2896 access: vec![PUBLIC_SELECT],
2897 ontology: Some(Ontology {
2898 entity_name: "cluster",
2899 description: "A compute cluster that runs dataflows for sources, sinks, MVs, and indexes",
2900 links: &const {
2901 [
2902 OntologyLink {
2903 name: "owned_by",
2904 target: "role",
2905 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
2906 },
2907 OntologyLink {
2908 name: "has_size",
2909 target: "replica_size",
2910 properties: LinkProperties::fk_nullable("size", "size", Cardinality::ManyToOne),
2911 },
2912 ]
2913 },
2914 column_semantic_types: &const {
2915 [
2916 ("id", SemanticType::ClusterId),
2917 ("owner_id", SemanticType::RoleId),
2918 ]
2919 },
2920 }),
2921 }
2922});
2923
2924pub static MZ_SECRETS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
2925 BuiltinMaterializedView {
2926 name: "mz_secrets",
2927 schema: MZ_CATALOG_SCHEMA,
2928 oid: oid::MV_MZ_SECRETS_OID,
2929 desc: RelationDesc::builder()
2930 .with_column("id", SqlScalarType::String.nullable(false))
2931 .with_column("oid", SqlScalarType::Oid.nullable(false))
2932 .with_column("schema_id", SqlScalarType::String.nullable(false))
2933 .with_column("name", SqlScalarType::String.nullable(false))
2934 .with_column("owner_id", SqlScalarType::String.nullable(false))
2935 .with_column(
2936 "privileges",
2937 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2938 )
2939 .finish(),
2940 column_comments: BTreeMap::from_iter([
2941 ("id", "The unique ID of the secret."),
2942 ("oid", "A PostgreSQL-compatible oid for the secret."),
2943 (
2944 "schema_id",
2945 "The ID of the schema to which the secret belongs. Corresponds to `mz_schemas.id`.",
2946 ),
2947 ("name", "The name of the secret."),
2948 (
2949 "owner_id",
2950 "The role ID of the owner of the secret. Corresponds to `mz_roles.id`.",
2951 ),
2952 ("privileges", "The privileges belonging to the secret."),
2953 ]),
2954 sql: "
2955IN CLUSTER mz_catalog_server
2956WITH (
2957 ASSERT NOT NULL id,
2958 ASSERT NOT NULL oid,
2959 ASSERT NOT NULL schema_id,
2960 ASSERT NOT NULL name,
2961 ASSERT NOT NULL owner_id,
2962 ASSERT NOT NULL privileges
2963) AS
2964SELECT
2965 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
2966 (data->'value'->>'oid')::oid AS oid,
2967 mz_internal.parse_catalog_id(data->'value'->'schema_id') AS schema_id,
2968 data->'value'->>'name' AS name,
2969 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
2970 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges
2971FROM mz_internal.mz_catalog_raw
2972WHERE
2973 data->>'kind' = 'Item' AND
2974 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'type' = 'secret'",
2975 is_retained_metrics_object: false,
2976 access: vec![PUBLIC_SELECT],
2977 ontology: Some(Ontology {
2978 entity_name: "secret",
2979 description: "A user-defined secret containing sensitive configuration (e.g., credentials)",
2980 links: &const { [
2981 OntologyLink {
2982 name: "in_schema",
2983 target: "schema",
2984 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
2985 },
2986 OntologyLink {
2987 name: "owned_by",
2988 target: "role",
2989 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
2990 },
2991 ] },
2992 column_semantic_types: &const {[("id", SemanticType::CatalogItemId), ("oid", SemanticType::OID), ("schema_id", SemanticType::SchemaId), ("owner_id", SemanticType::RoleId)]},
2993 }),
2994 }
2995});
2996
2997pub static MZ_CLUSTER_REPLICAS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
2998 BuiltinMaterializedView {
2999 name: "mz_cluster_replicas",
3000 schema: MZ_CATALOG_SCHEMA,
3001 oid: oid::MV_MZ_CLUSTER_REPLICAS_OID,
3002 desc: RelationDesc::builder()
3003 .with_column("id", SqlScalarType::String.nullable(false))
3004 .with_column("name", SqlScalarType::String.nullable(false))
3005 .with_column("cluster_id", SqlScalarType::String.nullable(false))
3006 .with_column("size", SqlScalarType::String.nullable(true))
3007 .with_column("availability_zone", SqlScalarType::String.nullable(true))
3010 .with_column("owner_id", SqlScalarType::String.nullable(false))
3011 .with_column("disk", SqlScalarType::Bool.nullable(true))
3012 .with_key(vec![0])
3013 .finish(),
3014 column_comments: BTreeMap::from_iter([
3015 ("id", "Materialize's unique ID for the cluster replica."),
3016 ("name", "The name of the cluster replica."),
3017 (
3018 "cluster_id",
3019 "The ID of the cluster to which the replica belongs. Corresponds to `mz_clusters.id`.",
3020 ),
3021 (
3022 "size",
3023 "The cluster replica's size, selected during creation.",
3024 ),
3025 (
3026 "availability_zone",
3027 "The availability zones the replica is provisioned in, comma-separated. `NULL` if nothing constrains the replica's placement.",
3028 ),
3029 (
3030 "owner_id",
3031 "The role ID of the owner of the cluster replica. Corresponds to `mz_roles.id`.",
3032 ),
3033 ("disk", "If the replica has a local disk."),
3034 ]),
3035 sql: "
3059IN CLUSTER mz_catalog_server
3060WITH (
3061 ASSERT NOT NULL id,
3062 ASSERT NOT NULL name,
3063 ASSERT NOT NULL cluster_id,
3064 ASSERT NOT NULL owner_id
3065) AS
3066SELECT
3067 mz_internal.parse_catalog_id(data->'key'->'id') AS id,
3068 data->'value'->>'name' AS name,
3069 mz_internal.parse_catalog_id(data->'value'->'cluster_id') AS cluster_id,
3070 data->'value'->'config'->'location'->'Managed'->>'size' AS size,
3071 CASE
3072 WHEN jsonb_array_length(data->'value'->'config'->'location'->'Managed'->'availability_zones') > 0 THEN
3073 (
3074 SELECT pg_catalog.string_agg(az.value, ',' ORDER BY az.ord)
3075 FROM jsonb_array_elements_text(data->'value'->'config'->'location'->'Managed'->'availability_zones')
3076 WITH ORDINALITY AS az(value, ord)
3077 )
3078 END AS availability_zone,
3079 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
3080 CASE
3081 WHEN data->'value'->'config'->'location' ? 'Managed' THEN
3082 NOT COALESCE(internal.swap_enabled, false)
3083 AND COALESCE(internal.disk_bytes, 0) != 0
3084 END AS disk
3085FROM (
3086 SELECT data FROM mz_internal.mz_catalog_raw WHERE data->>'kind' = 'ClusterReplica'
3087) raw
3088LEFT JOIN mz_internal.mz_cluster_replica_size_internal internal
3089 ON internal.size = data->'value'->'config'->'location'->'Managed'->>'size'",
3090 is_retained_metrics_object: true,
3091 access: vec![PUBLIC_SELECT],
3092 ontology: Some(Ontology {
3093 entity_name: "replica",
3094 description: "A physical replica of a cluster providing fault tolerance",
3095 links: &const {
3096 [
3097 OntologyLink {
3098 name: "owned_by",
3099 target: "role",
3100 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
3101 },
3102 OntologyLink {
3103 name: "belongs_to_cluster",
3104 target: "cluster",
3105 properties: LinkProperties::fk("cluster_id", "id", Cardinality::ManyToOne),
3106 },
3107 OntologyLink {
3108 name: "has_size",
3109 target: "replica_size",
3110 properties: LinkProperties::fk_nullable(
3111 "size",
3112 "size",
3113 Cardinality::ManyToOne,
3114 ),
3115 },
3116 ]
3117 },
3118 column_semantic_types: &const {
3119 [
3120 ("id", SemanticType::ReplicaId),
3121 ("cluster_id", SemanticType::ClusterId),
3122 ("owner_id", SemanticType::RoleId),
3123 ]
3124 },
3125 }),
3126 }
3127});
3128
3129pub static MZ_CLUSTER_REPLICA_SIZES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3130 name: "mz_cluster_replica_sizes",
3131 schema: MZ_CATALOG_SCHEMA,
3132 oid: oid::TABLE_MZ_CLUSTER_REPLICA_SIZES_OID,
3133 desc: RelationDesc::builder()
3134 .with_column("size", SqlScalarType::String.nullable(false))
3135 .with_column("processes", SqlScalarType::UInt64.nullable(false))
3136 .with_column("workers", SqlScalarType::UInt64.nullable(false))
3137 .with_column("cpu_nano_cores", SqlScalarType::UInt64.nullable(false))
3138 .with_column("memory_bytes", SqlScalarType::UInt64.nullable(false))
3139 .with_column("disk_bytes", SqlScalarType::UInt64.nullable(true))
3140 .with_column(
3141 "credits_per_hour",
3142 SqlScalarType::Numeric { max_scale: None }.nullable(false),
3143 )
3144 .with_column("disabled", SqlScalarType::Bool.nullable(false))
3145 .finish(),
3146 column_comments: BTreeMap::from_iter([
3147 ("size", "The human-readable replica size."),
3148 ("processes", "The number of processes in the replica."),
3149 (
3150 "workers",
3151 "The number of Timely Dataflow workers per process.",
3152 ),
3153 (
3154 "cpu_nano_cores",
3155 "The CPU allocation per process, in billionths of a vCPU core.",
3156 ),
3157 ("memory_bytes", "The RAM allocation per process, in bytes."),
3158 ("disk_bytes", "The disk allocation per process."),
3159 (
3160 "credits_per_hour",
3161 "The number of compute credits consumed per hour.",
3162 ),
3163 (
3164 "disabled",
3165 "Whether the size is disabled. Existing replicas keep running on a disabled size, but new clusters and replicas cannot choose it.",
3166 ),
3167 ]),
3168 is_retained_metrics_object: true,
3169 access: vec![PUBLIC_SELECT],
3170 ontology: Some(Ontology {
3171 entity_name: "replica_size",
3172 description: "Cluster replica sizes with CPU, memory, and credit cost",
3173 links: &const { [] },
3174 column_semantic_types: &const {
3175 [
3176 ("memory_bytes", SemanticType::ByteCount),
3177 ("disk_bytes", SemanticType::ByteCount),
3178 ("credits_per_hour", SemanticType::CreditRate),
3179 ]
3180 },
3181 }),
3182});
3183
3184pub static MZ_AUDIT_EVENTS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
3185 BuiltinMaterializedView {
3186 name: "mz_audit_events",
3187 schema: MZ_CATALOG_SCHEMA,
3188 oid: oid::MV_MZ_AUDIT_EVENTS_OID,
3189 desc: RelationDesc::builder()
3190 .with_column("id", SqlScalarType::UInt64.nullable(false))
3191 .with_column("event_type", SqlScalarType::String.nullable(false))
3192 .with_column("object_type", SqlScalarType::String.nullable(false))
3193 .with_column("details", SqlScalarType::Jsonb.nullable(false))
3194 .with_column("user", SqlScalarType::String.nullable(true))
3195 .with_column(
3196 "occurred_at",
3197 SqlScalarType::TimestampTz { precision: None }.nullable(false),
3198 )
3199 .with_key(vec![0])
3200 .finish(),
3201 column_comments: BTreeMap::from_iter([
3202 (
3203 "id",
3204 "Materialize's unique, monotonically increasing ID for the event.",
3205 ),
3206 (
3207 "event_type",
3208 "The type of the event: `create`, `drop`, `alter`, `grant`, `revoke`, or `comment`.",
3209 ),
3210 (
3211 "object_type",
3212 "The type of the affected object: `cluster`, `cluster-replica`, `connection`, `continual-task`, `database`, `func`, `index`, `materialized-view`, `metric-sink`, `network-policy`, `role`, `schema`, `secret`, `sink`, `source`, `system`, `table`, `type`, or `view`.",
3213 ),
3214 (
3215 "details",
3216 "Additional details about the event. The shape of the details varies based on `event_type` and `object_type`.",
3217 ),
3218 (
3219 "user",
3220 "The user who triggered the event, or `NULL` if triggered by the system.",
3221 ),
3222 (
3223 "occurred_at",
3224 "The time at which the event occurred. Guaranteed to be in order of event creation. Events created in the same transaction will have identical values.",
3225 ),
3226 ]),
3227 sql: "
3249IN CLUSTER mz_catalog_server
3250WITH (
3251 ASSERT NOT NULL id,
3252 ASSERT NOT NULL event_type,
3253 ASSERT NOT NULL object_type,
3254 ASSERT NOT NULL details,
3255 ASSERT NOT NULL occurred_at
3256) AS
3257WITH ev AS (
3258 SELECT data->'key'->'event'->'V1' AS e
3259 FROM mz_internal.mz_catalog_raw
3260 WHERE data->>'kind' = 'AuditLog'
3261)
3262SELECT
3263 (e->>'id')::uint8 AS id,
3264 CASE (e->>'event_type')
3265 WHEN '1' THEN 'create'
3266 WHEN '2' THEN 'drop'
3267 WHEN '3' THEN 'alter'
3268 WHEN '4' THEN 'grant'
3269 WHEN '5' THEN 'revoke'
3270 WHEN '6' THEN 'comment'
3271 END AS event_type,
3272 CASE (e->>'object_type')
3273 WHEN '1' THEN 'cluster'
3274 WHEN '2' THEN 'cluster-replica'
3275 WHEN '3' THEN 'connection'
3276 WHEN '4' THEN 'database'
3277 WHEN '5' THEN 'func'
3278 WHEN '6' THEN 'index'
3279 WHEN '7' THEN 'materialized-view'
3280 WHEN '8' THEN 'role'
3281 WHEN '9' THEN 'secret'
3282 WHEN '10' THEN 'schema'
3283 WHEN '11' THEN 'sink'
3284 WHEN '12' THEN 'source'
3285 WHEN '13' THEN 'table'
3286 WHEN '14' THEN 'type'
3287 WHEN '15' THEN 'view'
3288 WHEN '16' THEN 'system'
3289 WHEN '17' THEN 'continual-task'
3290 WHEN '18' THEN 'network-policy'
3291 WHEN '19' THEN 'metric-sink'
3292 WHEN '20' THEN 'query-policy'
3293 END AS object_type,
3294 mz_internal.parse_catalog_audit_log_details(e->'details') AS details,
3295 e->'user'->>'inner' AS \"user\",
3296 -- `occurred_at` is serialized by `proto::EpochMillis` as
3297 -- `{\"millis\": <u64>}`; reach through `'millis'` to get the integer.
3298 to_timestamp(((e->'occurred_at'->>'millis')::float8) / 1000.0) AS occurred_at
3299FROM ev",
3300 is_retained_metrics_object: false,
3301 access: vec![PUBLIC_SELECT],
3302 ontology: Some(Ontology {
3303 entity_name: "audit_event",
3304 description: "An audit log entry recording a DDL operation",
3305 links: &const { [] },
3306 column_semantic_types: &const {
3307 [
3308 ("object_type", SemanticType::ObjectType),
3309 ("occurred_at", SemanticType::WallclockTimestamp),
3310 ]
3311 },
3312 }),
3313 }
3314});
3315
3316pub static MZ_EGRESS_IPS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3317 name: "mz_egress_ips",
3318 schema: MZ_CATALOG_SCHEMA,
3319 oid: oid::TABLE_MZ_EGRESS_IPS_OID,
3320 desc: RelationDesc::builder()
3321 .with_column("egress_ip", SqlScalarType::String.nullable(false))
3322 .with_column("prefix_length", SqlScalarType::Int32.nullable(false))
3323 .with_column("cidr", SqlScalarType::String.nullable(false))
3324 .finish(),
3325 column_comments: BTreeMap::from_iter([
3326 ("egress_ip", "The start of the range of IP addresses."),
3327 (
3328 "prefix_length",
3329 "The number of leading bits in the CIDR netmask.",
3330 ),
3331 ("cidr", "The CIDR representation."),
3332 ]),
3333 is_retained_metrics_object: false,
3334 access: vec![PUBLIC_SELECT],
3335 ontology: Some(Ontology {
3336 entity_name: "egress_ip",
3337 description: "IP addresses used for outbound connections from Materialize",
3338 links: &const { [] },
3339 column_semantic_types: &[],
3340 }),
3341});
3342
3343pub static MZ_AWS_PRIVATELINK_CONNECTIONS: LazyLock<BuiltinMaterializedView> =
3351 LazyLock::new(|| {
3352 BuiltinMaterializedView {
3353 name: "mz_aws_privatelink_connections",
3354 schema: MZ_CATALOG_SCHEMA,
3355 oid: oid::MV_MZ_AWS_PRIVATELINK_CONNECTIONS_OID,
3356 desc: RelationDesc::builder()
3357 .with_column("id", SqlScalarType::String.nullable(false))
3358 .with_column("principal", SqlScalarType::String.nullable(false))
3359 .with_key(vec![0])
3360 .finish(),
3361 column_comments: BTreeMap::from_iter([
3362 ("id", "The ID of the connection."),
3363 (
3364 "principal",
3365 "The AWS Principal that Materialize will use to connect to the VPC endpoint.",
3366 ),
3367 ]),
3368 sql: "
3371IN CLUSTER mz_catalog_server
3372WITH (
3373 ASSERT NOT NULL id,
3374 ASSERT NOT NULL principal
3375) AS
3376SELECT id, principal FROM (
3377 SELECT
3378 mz_internal.parse_catalog_id(r.data->'key'->'gid') AS id,
3379 'arn:aws:iam::' || mz_aws_account_id() || ':role/mz_'
3380 || mz_aws_external_id_prefix() || '_'
3381 || mz_internal.parse_catalog_id(r.data->'key'->'gid') AS principal
3382 FROM mz_internal.mz_catalog_raw r
3383 WHERE
3384 r.data->>'kind' = 'Item' AND
3385 mz_internal.parse_catalog_create_sql(
3386 r.data->'value'->'definition'->'V1'->>'create_sql')->>'connection_type'
3387 = 'aws-privatelink'
3388)
3389WHERE principal IS NOT NULL",
3390 is_retained_metrics_object: false,
3391 access: vec![PUBLIC_SELECT],
3392 ontology: Some(Ontology {
3393 entity_name: "aws_privatelink_connection",
3394 description: "AWS PrivateLink connection configuration",
3395 links: &const {
3396 [OntologyLink {
3397 name: "details_of",
3398 target: "connection",
3399 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
3400 }]
3401 },
3402 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
3403 }),
3404 }
3405 });
3406
3407pub static MZ_CLUSTER_REPLICA_FRONTIERS: LazyLock<BuiltinSource> =
3408 LazyLock::new(|| BuiltinSource {
3409 name: "mz_cluster_replica_frontiers",
3410 schema: MZ_CATALOG_SCHEMA,
3411 oid: oid::SOURCE_MZ_CLUSTER_REPLICA_FRONTIERS_OID,
3412 data_source: IntrospectionType::ReplicaFrontiers.into(),
3413 desc: RelationDesc::builder()
3414 .with_column("object_id", SqlScalarType::String.nullable(false))
3415 .with_column("replica_id", SqlScalarType::String.nullable(false))
3416 .with_column("write_frontier", SqlScalarType::MzTimestamp.nullable(true))
3417 .finish(),
3418 column_comments: BTreeMap::from_iter([
3419 (
3420 "object_id",
3421 "The ID of the source, sink, index, materialized view, or subscription.",
3422 ),
3423 ("replica_id", "The ID of a cluster replica."),
3424 (
3425 "write_frontier",
3426 "The next timestamp at which the output may change.",
3427 ),
3428 ]),
3429 is_retained_metrics_object: false,
3430 access: vec![PUBLIC_SELECT],
3431 ontology: None,
3432 });
3433
3434pub static MZ_CLUSTER_REPLICA_FRONTIERS_IND: LazyLock<BuiltinIndex> =
3435 LazyLock::new(|| BuiltinIndex {
3436 name: "mz_cluster_replica_frontiers_ind",
3437 schema: MZ_CATALOG_SCHEMA,
3438 oid: oid::INDEX_MZ_CLUSTER_REPLICA_FRONTIERS_IND_OID,
3439 sql: "IN CLUSTER mz_catalog_server ON mz_catalog.mz_cluster_replica_frontiers (object_id)",
3440 is_retained_metrics_object: false,
3441 });
3442
3443pub static MZ_DEFAULT_PRIVILEGES: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
3444 BuiltinMaterializedView {
3445 name: "mz_default_privileges",
3446 schema: MZ_CATALOG_SCHEMA,
3447 oid: oid::MV_MZ_DEFAULT_PRIVILEGES_OID,
3448 desc: RelationDesc::builder()
3449 .with_column("role_id", SqlScalarType::String.nullable(false))
3450 .with_column("database_id", SqlScalarType::String.nullable(true))
3451 .with_column("schema_id", SqlScalarType::String.nullable(true))
3452 .with_column("object_type", SqlScalarType::String.nullable(false))
3453 .with_column("grantee", SqlScalarType::String.nullable(false))
3454 .with_column("privileges", SqlScalarType::String.nullable(false))
3455 .finish(),
3456 column_comments: BTreeMap::from_iter([
3457 (
3458 "role_id",
3459 "Privileges described in this row will be granted on objects created by `role_id`. The role ID `p` stands for the `PUBLIC` pseudo-role and applies to all roles.",
3460 ),
3461 (
3462 "database_id",
3463 "Privileges described in this row will be granted only on objects in the database identified by `database_id` if non-null.",
3464 ),
3465 (
3466 "schema_id",
3467 "Privileges described in this row will be granted only on objects in the schema identified by `schema_id` if non-null.",
3468 ),
3469 (
3470 "object_type",
3471 "Privileges described in this row will be granted only on objects of type `object_type`.",
3472 ),
3473 (
3474 "grantee",
3475 "Privileges described in this row will be granted to `grantee`. The role ID `p` stands for the `PUBLIC` pseudo-role and applies to all roles.",
3476 ),
3477 ("privileges", "The set of privileges that will be granted."),
3478 ]),
3479 sql: "
3487IN CLUSTER mz_catalog_server
3488WITH (
3489 ASSERT NOT NULL role_id,
3490 ASSERT NOT NULL object_type,
3491 ASSERT NOT NULL grantee,
3492 ASSERT NOT NULL privileges
3493) AS
3494SELECT
3495 mz_internal.parse_catalog_id(data->'key'->'role_id') AS role_id,
3496 CASE WHEN data->'key'->'database_id' != 'null'::jsonb
3497 THEN mz_internal.parse_catalog_id(data->'key'->'database_id') END AS database_id,
3498 CASE WHEN data->'key'->'schema_id' != 'null'::jsonb
3499 THEN mz_internal.parse_catalog_id(data->'key'->'schema_id') END AS schema_id,
3500 CASE data->'key'->>'object_type'
3501 WHEN '1' THEN 'table'
3502 WHEN '2' THEN 'view'
3503 WHEN '3' THEN 'materialized view'
3504 WHEN '4' THEN 'source'
3505 WHEN '5' THEN 'sink'
3506 WHEN '6' THEN 'index'
3507 WHEN '7' THEN 'type'
3508 WHEN '8' THEN 'role'
3509 WHEN '9' THEN 'cluster'
3510 WHEN '10' THEN 'cluster replica'
3511 WHEN '11' THEN 'secret'
3512 WHEN '12' THEN 'connection'
3513 WHEN '13' THEN 'database'
3514 WHEN '14' THEN 'schema'
3515 WHEN '15' THEN 'function'
3516 -- variant 16 reserved/unused in mz_catalog_protos::ObjectType.
3517 WHEN '17' THEN 'network policy'
3518 WHEN '19' THEN 'query policy'
3519 END AS object_type,
3520 mz_internal.parse_catalog_id(data->'key'->'grantee') AS grantee,
3521 mz_internal.parse_catalog_acl_mode(data->'value'->'privileges') AS privileges
3522FROM mz_internal.mz_catalog_raw
3523WHERE data->>'kind' = 'DefaultPrivileges'",
3524 is_retained_metrics_object: false,
3525 access: vec![PUBLIC_SELECT],
3526 ontology: Some(Ontology {
3527 entity_name: "default_privilege",
3528 description: "A default privilege rule applied to newly created objects",
3529 links: &const {
3530 [
3531 OntologyLink {
3532 name: "default_priv_for_role",
3533 target: "role",
3534 properties: LinkProperties::fk("role_id", "id", Cardinality::ManyToOne),
3535 },
3536 OntologyLink {
3537 name: "default_priv_in_database",
3538 target: "database",
3539 properties: LinkProperties::fk_nullable(
3540 "database_id",
3541 "id",
3542 Cardinality::ManyToOne,
3543 ),
3544 },
3545 OntologyLink {
3546 name: "default_priv_in_schema",
3547 target: "schema",
3548 properties: LinkProperties::fk_nullable(
3549 "schema_id",
3550 "id",
3551 Cardinality::ManyToOne,
3552 ),
3553 },
3554 OntologyLink {
3555 name: "default_priv_granted_to",
3556 target: "role",
3557 properties: LinkProperties::fk("grantee", "id", Cardinality::ManyToOne),
3558 },
3559 ]
3560 },
3561 column_semantic_types: &const {
3562 [
3563 ("role_id", SemanticType::RoleId),
3564 ("database_id", SemanticType::DatabaseId),
3565 ("schema_id", SemanticType::SchemaId),
3566 ("object_type", SemanticType::ObjectType),
3567 ("grantee", SemanticType::RoleId),
3568 ]
3569 },
3570 }),
3571 }
3572});
3573
3574pub static MZ_SYSTEM_PRIVILEGES: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
3575 BuiltinMaterializedView {
3576 name: "mz_system_privileges",
3577 schema: MZ_CATALOG_SCHEMA,
3578 oid: oid::MV_MZ_SYSTEM_PRIVILEGES_OID,
3579 desc: RelationDesc::builder()
3580 .with_column("privileges", SqlScalarType::MzAclItem.nullable(false))
3581 .finish(),
3582 column_comments: BTreeMap::from_iter([(
3583 "privileges",
3584 "The privileges belonging to the system.",
3585 )]),
3586 sql: "
3590IN CLUSTER mz_catalog_server
3591WITH (
3592 ASSERT NOT NULL privileges
3593) AS
3594SELECT
3595 unnest(mz_internal.parse_catalog_privileges(
3596 jsonb_build_array(
3597 jsonb_build_object(
3598 'grantee', data->'key'->'grantee',
3599 'grantor', data->'key'->'grantor',
3600 'acl_mode', data->'value'->'acl_mode'
3601 )
3602 )
3603 )) AS privileges
3604FROM mz_internal.mz_catalog_raw
3605WHERE data->>'kind' = 'SystemPrivileges'",
3606 is_retained_metrics_object: false,
3607 access: vec![PUBLIC_SELECT],
3608 ontology: Some(Ontology {
3609 entity_name: "system_privilege",
3610 description: "A system-level privilege grant",
3611 links: &const { [] },
3612 column_semantic_types: &[],
3613 }),
3614 }
3615});
3616
3617pub static MZ_STORAGE_USAGE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
3618 name: "mz_storage_usage",
3619 schema: MZ_CATALOG_SCHEMA,
3620 oid: oid::VIEW_MZ_STORAGE_USAGE_OID,
3621 desc: RelationDesc::builder()
3622 .with_column("object_id", SqlScalarType::String.nullable(false))
3623 .with_column("size_bytes", SqlScalarType::UInt64.nullable(false))
3624 .with_column(
3625 "collection_timestamp",
3626 SqlScalarType::TimestampTz { precision: None }.nullable(false),
3627 )
3628 .with_key(vec![0, 2])
3629 .finish(),
3630 column_comments: BTreeMap::from_iter([
3631 (
3632 "object_id",
3633 "The ID of the table, source, or materialized view.",
3634 ),
3635 (
3636 "size_bytes",
3637 "The number of storage bytes used by the object.",
3638 ),
3639 (
3640 "collection_timestamp",
3641 "The time at which storage usage of the object was assessed.",
3642 ),
3643 ]),
3644 sql: "
3645SELECT
3646 object_id,
3647 sum(size_bytes)::uint8 AS size_bytes,
3648 collection_timestamp
3649FROM
3650 mz_internal.mz_storage_shards
3651 JOIN mz_internal.mz_storage_usage_by_shard USING (shard_id)
3652GROUP BY object_id, collection_timestamp",
3653 access: vec![PUBLIC_SELECT],
3654 ontology: Some(Ontology {
3655 entity_name: "storage_usage",
3656 description: "Historical storage usage per object over time",
3657 links: &const {
3658 [OntologyLink {
3659 name: "storage_usage_of",
3660 target: "object",
3661 properties: LinkProperties::fk("object_id", "id", Cardinality::ManyToOne),
3662 }]
3663 },
3664 column_semantic_types: &const {
3665 [
3666 ("object_id", SemanticType::CatalogItemId),
3667 ("size_bytes", SemanticType::ByteCount),
3668 ("collection_timestamp", SemanticType::WallclockTimestamp),
3669 ]
3670 },
3671 }),
3672});
3673
3674pub static MZ_RECENT_STORAGE_USAGE: LazyLock<BuiltinView> = LazyLock::new(|| {
3675 BuiltinView {
3676 name: "mz_recent_storage_usage",
3677 schema: MZ_CATALOG_SCHEMA,
3678 oid: oid::VIEW_MZ_RECENT_STORAGE_USAGE_OID,
3679 desc: RelationDesc::builder()
3680 .with_column("object_id", SqlScalarType::String.nullable(false))
3681 .with_column("size_bytes", SqlScalarType::UInt64.nullable(true))
3682 .with_key(vec![0])
3683 .finish(),
3684 column_comments: BTreeMap::from_iter([
3685 ("object_id", "The ID of the table, source, or materialized view."),
3686 ("size_bytes", "The number of storage bytes used by the object in the most recent assessment."),
3687 ]),
3688 sql: "
3689WITH
3690
3691recent_storage_usage_by_shard AS (
3692 SELECT shard_id, size_bytes, collection_timestamp
3693 FROM mz_internal.mz_storage_usage_by_shard
3694 -- Restricting to the last 6 hours makes it feasible to index the view.
3695 WHERE collection_timestamp + '6 hours' >= mz_now()
3696),
3697
3698most_recent_collection_timestamp_by_shard AS (
3699 SELECT shard_id, max(collection_timestamp) AS collection_timestamp
3700 FROM recent_storage_usage_by_shard
3701 GROUP BY shard_id
3702)
3703
3704SELECT
3705 object_id,
3706 sum(size_bytes)::uint8 AS size_bytes
3707FROM
3708 mz_internal.mz_storage_shards
3709 LEFT JOIN most_recent_collection_timestamp_by_shard
3710 ON mz_storage_shards.shard_id = most_recent_collection_timestamp_by_shard.shard_id
3711 LEFT JOIN recent_storage_usage_by_shard
3712 ON mz_storage_shards.shard_id = recent_storage_usage_by_shard.shard_id
3713 AND most_recent_collection_timestamp_by_shard.collection_timestamp = recent_storage_usage_by_shard.collection_timestamp
3714GROUP BY object_id",
3715 access: vec![PUBLIC_SELECT],
3716 ontology: Some(Ontology {
3717 entity_name: "recent_storage",
3718 description: "Most recent storage usage snapshot per object",
3719 links: &const { [
3720 OntologyLink { name: "recent_storage_of", target: "object", properties: LinkProperties::fk("object_id", "id", Cardinality::OneToOne) },
3721 ] },
3722 column_semantic_types: &const {[("object_id", SemanticType::CatalogItemId), ("size_bytes", SemanticType::ByteCount)]},
3723 }),
3724}
3725});
3726
3727pub static MZ_RECENT_STORAGE_USAGE_IND: LazyLock<BuiltinIndex> = LazyLock::new(|| BuiltinIndex {
3728 name: "mz_recent_storage_usage_ind",
3729 schema: MZ_CATALOG_SCHEMA,
3730 oid: oid::INDEX_MZ_RECENT_STORAGE_USAGE_IND_OID,
3731 sql: "IN CLUSTER mz_catalog_server ON mz_catalog.mz_recent_storage_usage (object_id)",
3732 is_retained_metrics_object: false,
3733});
3734
3735pub static MZ_RELATIONS: LazyLock<BuiltinView> = LazyLock::new(|| {
3736 BuiltinView {
3737 name: "mz_relations",
3738 schema: MZ_CATALOG_SCHEMA,
3739 oid: oid::VIEW_MZ_RELATIONS_OID,
3740 desc: RelationDesc::builder()
3741 .with_column("id", SqlScalarType::String.nullable(false))
3742 .with_column("oid", SqlScalarType::Oid.nullable(false))
3743 .with_column("schema_id", SqlScalarType::String.nullable(false))
3744 .with_column("name", SqlScalarType::String.nullable(false))
3745 .with_column("type", SqlScalarType::String.nullable(false))
3746 .with_column("owner_id", SqlScalarType::String.nullable(false))
3747 .with_column("cluster_id", SqlScalarType::String.nullable(true))
3748 .with_column("privileges", SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false))
3749 .finish(),
3750 column_comments: BTreeMap::from_iter([
3751 ("id", "Materialize's unique ID for the relation."),
3752 ("oid", "A PostgreSQL-compatible OID for the relation."),
3753 ("schema_id", "The ID of the schema to which the relation belongs. Corresponds to `mz_schemas.id`."),
3754 ("name", "The name of the relation."),
3755 ("type", "The type of the relation: either `table`, `source`, `view`, or `materialized-view`."),
3756 ("owner_id", "The role ID of the owner of the relation. Corresponds to `mz_roles.id`."),
3757 ("cluster_id", "The ID of the cluster maintaining the source, materialized view, index, or sink. Corresponds to `mz_clusters.id`. `NULL` for other object types."),
3758 ("privileges", "The privileges belonging to the relation."),
3759 ]),
3760 sql: "
3761 SELECT id, oid, schema_id, name, 'table' AS type, owner_id, NULL::text AS cluster_id, privileges FROM mz_catalog.mz_tables
3762UNION ALL SELECT id, oid, schema_id, name, 'source', owner_id, cluster_id, privileges FROM mz_catalog.mz_sources
3763UNION ALL SELECT id, oid, schema_id, name, 'view', owner_id, NULL::text, privileges FROM mz_catalog.mz_views
3764UNION ALL SELECT id, oid, schema_id, name, 'materialized-view', owner_id, cluster_id, privileges FROM mz_catalog.mz_materialized_views",
3765 access: vec![PUBLIC_SELECT],
3766 ontology: Some(Ontology {
3767 entity_name: "relation",
3768 description: "Union of all relation types: tables, sources, views, MVs (convenience view)",
3769 links: &const { [
3770 OntologyLink { name: "union_includes", target: "table", properties: LinkProperties::union_disc("type", "table") },
3771 OntologyLink { name: "union_includes", target: "source", properties: LinkProperties::union_disc("type", "source") },
3772 OntologyLink { name: "union_includes", target: "view", properties: LinkProperties::union_disc("type", "view") },
3773 OntologyLink { name: "union_includes", target: "mv", properties: LinkProperties::union_disc("type", "materialized-view") },
3774 ] },
3775 column_semantic_types: &const {[("id", SemanticType::CatalogItemId), ("oid", SemanticType::OID), ("schema_id", SemanticType::SchemaId), ("type", SemanticType::ObjectType), ("owner_id", SemanticType::RoleId), ("cluster_id", SemanticType::ClusterId)]},
3776 }),
3777 }
3778});
3779
3780pub static MZ_OBJECTS: LazyLock<BuiltinView> = LazyLock::new(|| {
3781 BuiltinView {
3782 name: "mz_objects",
3783 schema: MZ_CATALOG_SCHEMA,
3784 oid: oid::VIEW_MZ_OBJECTS_OID,
3785 desc: RelationDesc::builder()
3786 .with_column("id", SqlScalarType::String.nullable(false))
3787 .with_column("oid", SqlScalarType::Oid.nullable(false))
3788 .with_column("schema_id", SqlScalarType::String.nullable(false))
3789 .with_column("name", SqlScalarType::String.nullable(false))
3790 .with_column("type", SqlScalarType::String.nullable(false))
3791 .with_column("owner_id", SqlScalarType::String.nullable(false))
3792 .with_column("cluster_id", SqlScalarType::String.nullable(true))
3793 .with_column("privileges", SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(true))
3794 .finish(),
3795 column_comments: BTreeMap::from_iter([
3796 ("id", "Materialize's unique ID for the object."),
3797 ("oid", "A PostgreSQL-compatible OID for the object."),
3798 ("schema_id", "The ID of the schema to which the object belongs. Corresponds to `mz_schemas.id`."),
3799 ("name", "The name of the object."),
3800 ("type", "The type of the object: one of `table`, `source`, `view`, `materialized-view`, `sink`, `metric-sink`, `index`, `connection`, `secret`, `type`, or `function`."),
3801 ("owner_id", "The role ID of the owner of the object. Corresponds to `mz_roles.id`."),
3802 ("cluster_id", "The ID of the cluster maintaining the source, materialized view, index, or sink. Corresponds to `mz_clusters.id`. `NULL` for other object types."),
3803 ("privileges", "The privileges belonging to the object."),
3804 ]),
3805 sql:
3806 "SELECT id, oid, schema_id, name, type, owner_id, cluster_id, privileges FROM mz_catalog.mz_relations
3807UNION ALL
3808 SELECT id, oid, schema_id, name, 'sink', owner_id, cluster_id, NULL::mz_catalog.mz_aclitem[] FROM mz_catalog.mz_sinks
3809UNION ALL
3810 SELECT id, oid, schema_id, name, 'metric-sink', owner_id, cluster_id, NULL::mz_catalog.mz_aclitem[] FROM mz_internal.mz_metric_sinks
3811UNION ALL
3812 SELECT mz_indexes.id, mz_indexes.oid, mz_relations.schema_id, mz_indexes.name, 'index', mz_indexes.owner_id, mz_indexes.cluster_id, NULL::mz_catalog.mz_aclitem[]
3813 FROM mz_catalog.mz_indexes
3814 JOIN mz_catalog.mz_relations ON mz_indexes.on_id = mz_relations.id
3815UNION ALL
3816 SELECT id, oid, schema_id, name, 'connection', owner_id, NULL::text, privileges FROM mz_catalog.mz_connections
3817UNION ALL
3818 SELECT id, oid, schema_id, name, 'type', owner_id, NULL::text, privileges FROM mz_catalog.mz_types
3819UNION ALL
3820 SELECT id, oid, schema_id, name, 'function', owner_id, NULL::text, NULL::mz_catalog.mz_aclitem[] FROM mz_catalog.mz_functions
3821UNION ALL
3822 SELECT id, oid, schema_id, name, 'secret', owner_id, NULL::text, privileges FROM mz_catalog.mz_secrets",
3823 access: vec![PUBLIC_SELECT],
3824 ontology: Some(Ontology {
3825 entity_name: "object",
3826 description: "Union of all object types: relations, indexes, connections, etc. (convenience view)",
3827 links: &const {
3828 [
3829 OntologyLink {
3830 name: "union_includes",
3831 target: "relation",
3832 properties: LinkProperties::Union {
3833 discriminator_column: None,
3834 discriminator_value: None,
3835 note: Some("covers all mz_relations rows (table, source, view, mv)"),
3836 },
3837 },
3838 OntologyLink {
3839 name: "union_includes",
3840 target: "table",
3841 properties: LinkProperties::union_disc("type", "table"),
3842 },
3843 OntologyLink {
3844 name: "union_includes",
3845 target: "source",
3846 properties: LinkProperties::union_disc("type", "source"),
3847 },
3848 OntologyLink {
3849 name: "union_includes",
3850 target: "view",
3851 properties: LinkProperties::union_disc("type", "view"),
3852 },
3853 OntologyLink {
3854 name: "union_includes",
3855 target: "mv",
3856 properties: LinkProperties::union_disc("type", "materialized-view"),
3857 },
3858 OntologyLink {
3859 name: "union_includes",
3860 target: "sink",
3861 properties: LinkProperties::union_disc("type", "sink"),
3862 },
3863 OntologyLink {
3864 name: "union_includes",
3865 target: "index",
3866 properties: LinkProperties::union_disc("type", "index"),
3867 },
3868 OntologyLink {
3869 name: "union_includes",
3870 target: "connection",
3871 properties: LinkProperties::union_disc("type", "connection"),
3872 },
3873 OntologyLink {
3874 name: "union_includes",
3875 target: "type",
3876 properties: LinkProperties::union_disc("type", "type"),
3877 },
3878 OntologyLink {
3879 name: "union_includes",
3880 target: "function",
3881 properties: LinkProperties::union_disc("type", "function"),
3882 },
3883 OntologyLink {
3884 name: "union_includes",
3885 target: "secret",
3886 properties: LinkProperties::union_disc("type", "secret"),
3887 },
3888 OntologyLink {
3889 name: "in_schema",
3890 target: "schema",
3891 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
3892 },
3893 OntologyLink {
3894 name: "owned_by",
3895 target: "role",
3896 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
3897 },
3898 OntologyLink {
3899 name: "on_cluster",
3900 target: "cluster",
3901 properties: LinkProperties::fk_nullable(
3902 "cluster_id",
3903 "id",
3904 Cardinality::ManyToOne,
3905 ),
3906 },
3907 ]
3908 },
3909 column_semantic_types: &const {
3910 [
3911 ("id", SemanticType::CatalogItemId),
3912 ("oid", SemanticType::OID),
3913 ("schema_id", SemanticType::SchemaId),
3914 ("type", SemanticType::ObjectType),
3915 ("owner_id", SemanticType::RoleId),
3916 ("cluster_id", SemanticType::ClusterId),
3917 ]
3918 },
3919 }),
3920 }
3921});
3922
3923pub static MZ_TIMEZONE_ABBREVIATIONS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
3924 name: "mz_timezone_abbreviations",
3925 schema: MZ_CATALOG_SCHEMA,
3926 oid: oid::VIEW_MZ_TIMEZONE_ABBREVIATIONS_OID,
3927 desc: RelationDesc::builder()
3928 .with_column("abbreviation", SqlScalarType::String.nullable(false))
3929 .with_column("utc_offset", SqlScalarType::Interval.nullable(true))
3930 .with_column("dst", SqlScalarType::Bool.nullable(true))
3931 .with_column("timezone_name", SqlScalarType::String.nullable(true))
3932 .with_key(vec![0])
3933 .finish(),
3934 column_comments: BTreeMap::from_iter([
3935 ("abbreviation", "The timezone abbreviation."),
3936 (
3937 "utc_offset",
3938 "The UTC offset of the timezone or `NULL` if fixed.",
3939 ),
3940 (
3941 "dst",
3942 "Whether the timezone is in daylight savings or `NULL` if fixed.",
3943 ),
3944 (
3945 "timezone_name",
3946 "The full name of the non-fixed timezone or `NULL` if not fixed.",
3947 ),
3948 ]),
3949 sql: format!(
3950 "SELECT * FROM ({}) _ (abbreviation, utc_offset, dst, timezone_name)",
3951 mz_pgtz::abbrev::MZ_CATALOG_TIMEZONE_ABBREVIATIONS_SQL,
3952 )
3953 .leak(),
3954 access: vec![PUBLIC_SELECT],
3955 ontology: None,
3956});
3957
3958pub static MZ_TIMEZONE_NAMES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
3959 name: "mz_timezone_names",
3960 schema: MZ_CATALOG_SCHEMA,
3961 oid: oid::VIEW_MZ_TIMEZONE_NAMES_OID,
3962 desc: RelationDesc::builder()
3963 .with_column("name", SqlScalarType::String.nullable(false))
3964 .with_key(vec![0])
3965 .finish(),
3966 column_comments: BTreeMap::from_iter([("name", "The timezone name.")]),
3967 sql: format!(
3968 "SELECT * FROM ({}) _ (name)",
3969 mz_pgtz::timezone::MZ_CATALOG_TIMEZONE_NAMES_SQL,
3970 )
3971 .leak(),
3972 access: vec![PUBLIC_SELECT],
3973 ontology: None,
3974});
3975
3976pub const MZ_DATABASES_IND: BuiltinIndex = BuiltinIndex {
3977 name: "mz_databases_ind",
3978 schema: MZ_CATALOG_SCHEMA,
3979 oid: oid::INDEX_MZ_DATABASES_IND_OID,
3980 sql: "IN CLUSTER mz_catalog_server
3981ON mz_catalog.mz_databases (name)",
3982 is_retained_metrics_object: false,
3983};
3984
3985pub const MZ_SCHEMAS_IND: BuiltinIndex = BuiltinIndex {
3986 name: "mz_schemas_ind",
3987 schema: MZ_CATALOG_SCHEMA,
3988 oid: oid::INDEX_MZ_SCHEMAS_IND_OID,
3989 sql: "IN CLUSTER mz_catalog_server
3990ON mz_catalog.mz_schemas (database_id)",
3991 is_retained_metrics_object: false,
3992};
3993
3994pub const MZ_CONNECTIONS_IND: BuiltinIndex = BuiltinIndex {
3995 name: "mz_connections_ind",
3996 schema: MZ_CATALOG_SCHEMA,
3997 oid: oid::INDEX_MZ_CONNECTIONS_IND_OID,
3998 sql: "IN CLUSTER mz_catalog_server
3999ON mz_catalog.mz_connections (schema_id)",
4000 is_retained_metrics_object: false,
4001};
4002
4003pub const MZ_TABLES_IND: BuiltinIndex = BuiltinIndex {
4004 name: "mz_tables_ind",
4005 schema: MZ_CATALOG_SCHEMA,
4006 oid: oid::INDEX_MZ_TABLES_IND_OID,
4007 sql: "IN CLUSTER mz_catalog_server
4008ON mz_catalog.mz_tables (schema_id)",
4009 is_retained_metrics_object: false,
4010};
4011
4012pub const MZ_TYPES_IND: BuiltinIndex = BuiltinIndex {
4013 name: "mz_types_ind",
4014 schema: MZ_CATALOG_SCHEMA,
4015 oid: oid::INDEX_MZ_TYPES_IND_OID,
4016 sql: "IN CLUSTER mz_catalog_server
4017ON mz_catalog.mz_types (schema_id)",
4018 is_retained_metrics_object: false,
4019};
4020
4021pub const MZ_OBJECTS_IND: BuiltinIndex = BuiltinIndex {
4022 name: "mz_objects_ind",
4023 schema: MZ_CATALOG_SCHEMA,
4024 oid: oid::INDEX_MZ_OBJECTS_IND_OID,
4025 sql: "IN CLUSTER mz_catalog_server
4026ON mz_catalog.mz_objects (schema_id)",
4027 is_retained_metrics_object: false,
4028};
4029
4030pub const MZ_COLUMNS_IND: BuiltinIndex = BuiltinIndex {
4031 name: "mz_columns_ind",
4032 schema: MZ_CATALOG_SCHEMA,
4033 oid: oid::INDEX_MZ_COLUMNS_IND_OID,
4034 sql: "IN CLUSTER mz_catalog_server
4035ON mz_catalog.mz_columns (name)",
4036 is_retained_metrics_object: false,
4037};
4038
4039pub const MZ_SECRETS_IND: BuiltinIndex = BuiltinIndex {
4040 name: "mz_secrets_ind",
4041 schema: MZ_CATALOG_SCHEMA,
4042 oid: oid::INDEX_MZ_SECRETS_IND_OID,
4043 sql: "IN CLUSTER mz_catalog_server
4044ON mz_catalog.mz_secrets (name)",
4045 is_retained_metrics_object: false,
4046};
4047
4048pub const MZ_VIEWS_IND: BuiltinIndex = BuiltinIndex {
4049 name: "mz_views_ind",
4050 schema: MZ_CATALOG_SCHEMA,
4051 oid: oid::INDEX_MZ_VIEWS_IND_OID,
4052 sql: "IN CLUSTER mz_catalog_server
4053ON mz_catalog.mz_views (schema_id)",
4054 is_retained_metrics_object: false,
4055};
4056
4057pub const MZ_CLUSTERS_IND: BuiltinIndex = BuiltinIndex {
4058 name: "mz_clusters_ind",
4059 schema: MZ_CATALOG_SCHEMA,
4060 oid: oid::INDEX_MZ_CLUSTERS_IND_OID,
4061 sql: "IN CLUSTER mz_catalog_server
4062ON mz_catalog.mz_clusters (id)",
4063 is_retained_metrics_object: false,
4064};
4065
4066pub const MZ_INDEXES_IND: BuiltinIndex = BuiltinIndex {
4067 name: "mz_indexes_ind",
4068 schema: MZ_CATALOG_SCHEMA,
4069 oid: oid::INDEX_MZ_INDEXES_IND_OID,
4070 sql: "IN CLUSTER mz_catalog_server
4071ON mz_catalog.mz_indexes (id)",
4072 is_retained_metrics_object: false,
4073};
4074
4075pub const MZ_ROLES_IND: BuiltinIndex = BuiltinIndex {
4076 name: "mz_roles_ind",
4077 schema: MZ_CATALOG_SCHEMA,
4078 oid: oid::INDEX_MZ_ROLES_IND_OID,
4079 sql: "IN CLUSTER mz_catalog_server
4080ON mz_catalog.mz_roles (id)",
4081 is_retained_metrics_object: false,
4082};
4083
4084pub const MZ_SOURCES_IND: BuiltinIndex = BuiltinIndex {
4085 name: "mz_sources_ind",
4086 schema: MZ_CATALOG_SCHEMA,
4087 oid: oid::INDEX_MZ_SOURCES_IND_OID,
4088 sql: "IN CLUSTER mz_catalog_server
4089ON mz_catalog.mz_sources (id)",
4090 is_retained_metrics_object: true,
4091};
4092
4093pub const MZ_SINKS_IND: BuiltinIndex = BuiltinIndex {
4094 name: "mz_sinks_ind",
4095 schema: MZ_CATALOG_SCHEMA,
4096 oid: oid::INDEX_MZ_SINKS_IND_OID,
4097 sql: "IN CLUSTER mz_catalog_server
4098ON mz_catalog.mz_sinks (id)",
4099 is_retained_metrics_object: true,
4100};
4101
4102pub const MZ_MATERIALIZED_VIEWS_IND: BuiltinIndex = BuiltinIndex {
4103 name: "mz_materialized_views_ind",
4104 schema: MZ_CATALOG_SCHEMA,
4105 oid: oid::INDEX_MZ_MATERIALIZED_VIEWS_IND_OID,
4106 sql: "IN CLUSTER mz_catalog_server
4107ON mz_catalog.mz_materialized_views (id)",
4108 is_retained_metrics_object: false,
4109};
4110
4111pub const MZ_CLUSTER_REPLICAS_IND: BuiltinIndex = BuiltinIndex {
4112 name: "mz_cluster_replicas_ind",
4113 schema: MZ_CATALOG_SCHEMA,
4114 oid: oid::INDEX_MZ_CLUSTER_REPLICAS_IND_OID,
4115 sql: "IN CLUSTER mz_catalog_server
4116ON mz_catalog.mz_cluster_replicas (id)",
4117 is_retained_metrics_object: true,
4118};
4119
4120pub const MZ_CLUSTER_REPLICA_SIZES_IND: BuiltinIndex = BuiltinIndex {
4121 name: "mz_cluster_replica_sizes_ind",
4122 schema: MZ_CATALOG_SCHEMA,
4123 oid: oid::INDEX_MZ_CLUSTER_REPLICA_SIZES_IND_OID,
4124 sql: "IN CLUSTER mz_catalog_server
4125ON mz_catalog.mz_cluster_replica_sizes (size)",
4126 is_retained_metrics_object: true,
4127};
4128
4129pub const MZ_KAFKA_SOURCES_IND: BuiltinIndex = BuiltinIndex {
4130 name: "mz_kafka_sources_ind",
4131 schema: MZ_CATALOG_SCHEMA,
4132 oid: oid::INDEX_MZ_KAFKA_SOURCES_IND_OID,
4133 sql: "IN CLUSTER mz_catalog_server
4134ON mz_catalog.mz_kafka_sources (id)",
4135 is_retained_metrics_object: true,
4136};
4137
4138#[cfg(test)]
4139mod tests {
4140 use mz_catalog_protos::objects::ObjectType as ProtoObjectType;
4141 use mz_sql::catalog::ObjectType as SqlObjectType;
4142
4143 use crate::builtin::mz_catalog::MZ_DEFAULT_PRIVILEGES;
4144
4145 #[mz_ore::test]
4153 fn object_type_case_matches_proto_display() {
4154 fn expected_for(proto: ProtoObjectType) -> Option<SqlObjectType> {
4160 match proto {
4161 ProtoObjectType::Unknown => None,
4162 ProtoObjectType::MetricSink => None,
4163 ProtoObjectType::Table => Some(SqlObjectType::Table),
4164 ProtoObjectType::View => Some(SqlObjectType::View),
4165 ProtoObjectType::MaterializedView => Some(SqlObjectType::MaterializedView),
4166 ProtoObjectType::Source => Some(SqlObjectType::Source),
4167 ProtoObjectType::Sink => Some(SqlObjectType::Sink),
4168 ProtoObjectType::Index => Some(SqlObjectType::Index),
4169 ProtoObjectType::Type => Some(SqlObjectType::Type),
4170 ProtoObjectType::Role => Some(SqlObjectType::Role),
4171 ProtoObjectType::Cluster => Some(SqlObjectType::Cluster),
4172 ProtoObjectType::ClusterReplica => Some(SqlObjectType::ClusterReplica),
4173 ProtoObjectType::Secret => Some(SqlObjectType::Secret),
4174 ProtoObjectType::Connection => Some(SqlObjectType::Connection),
4175 ProtoObjectType::Database => Some(SqlObjectType::Database),
4176 ProtoObjectType::Schema => Some(SqlObjectType::Schema),
4177 ProtoObjectType::Func => Some(SqlObjectType::Func),
4178 ProtoObjectType::NetworkPolicy => Some(SqlObjectType::NetworkPolicy),
4179 ProtoObjectType::QueryPolicy => Some(SqlObjectType::QueryPolicy),
4180 }
4181 }
4182
4183 let variants: &[ProtoObjectType] = &[
4188 ProtoObjectType::Unknown,
4189 ProtoObjectType::Table,
4190 ProtoObjectType::View,
4191 ProtoObjectType::MaterializedView,
4192 ProtoObjectType::Source,
4193 ProtoObjectType::Sink,
4194 ProtoObjectType::Index,
4195 ProtoObjectType::Type,
4196 ProtoObjectType::Role,
4197 ProtoObjectType::Cluster,
4198 ProtoObjectType::ClusterReplica,
4199 ProtoObjectType::Secret,
4200 ProtoObjectType::Connection,
4201 ProtoObjectType::Database,
4202 ProtoObjectType::Schema,
4203 ProtoObjectType::Func,
4204 ProtoObjectType::NetworkPolicy,
4205 ProtoObjectType::MetricSink,
4206 ProtoObjectType::QueryPolicy,
4207 ];
4208
4209 let sql = MZ_DEFAULT_PRIVILEGES.sql;
4210 for &proto in variants {
4211 #[allow(clippy::as_conversions)]
4214 let repr = proto as u8;
4215 match expected_for(proto) {
4216 Some(sql_ty) => {
4217 let display = sql_ty.to_string().to_lowercase();
4218 let one_space = format!("WHEN '{repr}' THEN '{display}'");
4222 let two_spaces = format!("WHEN '{repr}' THEN '{display}'");
4223 assert!(
4224 sql.contains(&one_space) || sql.contains(&two_spaces),
4225 "missing CASE arm for `{proto:?}`: expected \
4226 `WHEN '{repr}' THEN '{display}'` (or with double space) \
4227 in MZ_DEFAULT_PRIVILEGES.sql",
4228 );
4229 }
4230 None => {
4231 let pattern = format!("WHEN '{repr}'");
4232 assert!(
4233 !sql.contains(&pattern),
4234 "unexpected CASE arm for sentinel `{proto:?}`: \
4235 found `{pattern}` in MZ_DEFAULT_PRIVILEGES.sql",
4236 );
4237 }
4238 }
4239 }
4240 }
4241}