Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/user/content/reference/system-catalog/mz_internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,8 @@ The `mz_webhook_sources` table contains a row for each webhook source in the sys
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_activity_log_thinned -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_materialized_views -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_sources -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_tables -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_views -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_catalog_raw -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_cluster_replica_size_internal -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_cluster_workload_classes -->
Expand Down
123 changes: 6 additions & 117 deletions src/adapter/src/catalog/builtin_table_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use mz_catalog::builtin::{
MZ_LICENSE_KEYS, MZ_LIST_TYPES, MZ_MAP_TYPES, MZ_MATERIALIZED_VIEW_REFRESH_STRATEGIES,
MZ_OBJECT_DEPENDENCIES, MZ_OBJECT_GLOBAL_IDS, MZ_OPERATORS, MZ_PSEUDO_TYPES, MZ_REPLACEMENTS,
MZ_ROLE_AUTH, MZ_SESSIONS, MZ_SINKS, MZ_SOURCE_REFERENCES, MZ_STORAGE_USAGE_BY_SHARD,
MZ_SUBSCRIPTIONS, MZ_TABLES, MZ_TYPE_PG_METADATA, MZ_TYPES, MZ_VIEWS, MZ_WEBHOOKS_SOURCES,
MZ_SUBSCRIPTIONS, MZ_TYPE_PG_METADATA, MZ_TYPES, MZ_WEBHOOKS_SOURCES,
};
use mz_catalog::durable::SourceReferences;
use mz_catalog::memory::error::Error;
use mz_catalog::memory::objects::{
CatalogEntry, CatalogItem, DataSourceDesc, Func, Index, MaterializedView, Sink, Table,
TableDataSource, Type, View,
TableDataSource, Type,
};
use mz_expr::MirScalarExpr;
use mz_license_keys::ValidatedLicenseKey;
Expand Down Expand Up @@ -163,13 +163,6 @@ impl CatalogState {
let privileges = privileges_row.unpack_first();
let mut updates = match entry.item() {
CatalogItem::Index(index) => self.pack_index_update(id, index, diff),
CatalogItem::Table(table) => {
// Source-table metadata (mz_postgres/mysql/sql_server/kafka_source_tables)
// is now derived from the persisted create_sql by materialized
// views over mz_catalog_raw, so ingestion-export tables need no
// special packing here.
self.pack_table_update(id, oid, schema_id, name, owner_id, privileges, diff, table)
}
CatalogItem::Source(source) => {
match &source.data_source {
DataSourceDesc::Webhook { .. } => {
Expand All @@ -186,9 +179,6 @@ impl CatalogState {
| DataSourceDesc::Catalog => vec![],
}
}
CatalogItem::View(view) => {
self.pack_view_update(id, oid, schema_id, name, owner_id, privileges, view, diff)
}
CatalogItem::MaterializedView(mview) => {
self.pack_materialized_view_update(id, mview, diff)
}
Expand All @@ -201,7 +191,10 @@ impl CatalogState {
CatalogItem::Func(func) => {
self.pack_func_update(id, schema_id, name, owner_id, func, diff)
}
CatalogItem::Log(_) | CatalogItem::Secret(_) => vec![],
CatalogItem::Table(_)
| CatalogItem::View(_)
| CatalogItem::Log(_)
| CatalogItem::Secret(_) => vec![],
// Connection details (mz_kafka_connections, mz_ssh_tunnel_connections,
// mz_aws_connections, mz_aws_privatelink_connections) are now derived
// from the persisted create_sql by materialized views over
Expand Down Expand Up @@ -330,110 +323,6 @@ impl CatalogState {
)
}

fn pack_table_update(
&self,
id: CatalogItemId,
oid: u32,
schema_id: &SchemaSpecifier,
name: &str,
owner_id: &RoleId,
privileges: Datum,
diff: Diff,
table: &Table,
) -> Vec<BuiltinTableUpdate<&'static BuiltinTable>> {
let redacted = table.create_sql.as_ref().map(|create_sql| {
mz_sql::parse::parse(create_sql)
.unwrap_or_else(|_| panic!("create_sql cannot be invalid: {}", create_sql))
.into_element()
.ast
.to_ast_string_redacted()
});
let source_id = if let TableDataSource::DataSource {
desc: DataSourceDesc::IngestionExport { ingestion_id, .. },
..
} = &table.data_source
{
Some(ingestion_id.to_string())
} else {
None
};

vec![BuiltinTableUpdate::row(
&*MZ_TABLES,
Row::pack_slice(&[
Datum::String(&id.to_string()),
Datum::UInt32(oid),
Datum::String(&schema_id.to_string()),
Datum::String(name),
Datum::String(&owner_id.to_string()),
privileges,
if let Some(create_sql) = &table.create_sql {
Datum::String(create_sql)
} else {
Datum::Null
},
if let Some(redacted) = &redacted {
Datum::String(redacted)
} else {
Datum::Null
},
if let Some(source_id) = source_id.as_ref() {
Datum::String(source_id)
} else {
Datum::Null
},
]),
diff,
)]
}

fn pack_view_update(
&self,
id: CatalogItemId,
oid: u32,
schema_id: &SchemaSpecifier,
name: &str,
owner_id: &RoleId,
privileges: Datum,
view: &View,
diff: Diff,
) -> Vec<BuiltinTableUpdate<&'static BuiltinTable>> {
let create_stmt = mz_sql::parse::parse(&view.create_sql)
.unwrap_or_else(|e| {
panic!(
"create_sql cannot be invalid: `{}` --- error: `{}`",
view.create_sql, e
)
})
.into_element()
.ast;
let query = match &create_stmt {
Statement::CreateView(stmt) => &stmt.definition.query,
_ => unreachable!(),
};

let mut query_string = query.to_ast_string_stable();
// PostgreSQL appends a semicolon in `pg_views.definition`, we
// do the same for compatibility's sake.
query_string.push(';');

vec![BuiltinTableUpdate::row(
&*MZ_VIEWS,
Row::pack_slice(&[
Datum::String(&id.to_string()),
Datum::UInt32(oid),
Datum::String(&schema_id.to_string()),
Datum::String(name),
Datum::String(&query_string),
Datum::String(&owner_id.to_string()),
privileges,
Datum::String(&view.create_sql),
Datum::String(&create_stmt.to_ast_string_redacted()),
]),
diff,
)]
}

fn pack_materialized_view_update(
&self,
id: CatalogItemId,
Expand Down
17 changes: 17 additions & 0 deletions src/adapter/src/catalog/open/builtin_schema_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,23 @@ static MIGRATIONS: LazyLock<Vec<MigrationStep>> = LazyLock::new(|| {
MZ_CATALOG_SCHEMA,
"mz_aws_privatelink_connections",
),
// Converting mz_tables and mz_views from builtin tables to
// materialized views over mz_catalog_raw changes their catalog
// fingerprints, so each needs an explicit replacement step. See the
// NOTE above: this version must stay at the workspace's current dev
// version until the change ships.
MigrationStep::replacement(
"26.38.0-dev.0",
CatalogItemType::MaterializedView,
MZ_CATALOG_SCHEMA,
"mz_tables",
),
MigrationStep::replacement(
"26.38.0-dev.0",
CatalogItemType::MaterializedView,
MZ_CATALOG_SCHEMA,
"mz_views",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two things that need to move in lockstep with these steps:

  • misc/python/materialize/checks/all_checks/builtin_version_pin.py maps each stable mz_catalog builtin to the version that converted it to a view, and mz_tables/mz_views currently sit at None there. Could you set both to the release these steps ship in (currently v26.38.0)? Nothing goes red when this is missed (every reader on current upgrade paths carries the catalog: tolerate and strip stale builtin version pins on upgrade #37610 tolerance fix), so it only shows up by reading.
  • The workspace version bump lands Thursdays. If the stack doesn't merge before the 26.39 bump, these steps and the pin entries need to move together.

),
]
});

Expand Down
4 changes: 2 additions & 2 deletions src/catalog/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ pub static BUILTINS_STATIC: LazyLock<Vec<Builtin<NameReference>>> = LazyLock::ne
Builtin::Table(&MZ_COLUMNS),
// mz_indexes is generated dynamically below with inlined builtin VALUES.
Builtin::Table(&MZ_INDEX_COLUMNS),
Builtin::Table(&MZ_TABLES),
Builtin::MaterializedView(&MZ_TABLES),
// mz_sources is generated dynamically below with inlined builtin VALUES.
Builtin::Table(&MZ_SOURCE_REFERENCES),
Builtin::MaterializedView(&MZ_POSTGRES_SOURCES),
Expand All @@ -1126,7 +1126,7 @@ pub static BUILTINS_STATIC: LazyLock<Vec<Builtin<NameReference>>> = LazyLock::ne
Builtin::MaterializedView(&MZ_SQL_SERVER_SOURCE_TABLES),
Builtin::MaterializedView(&MZ_KAFKA_SOURCE_TABLES),
Builtin::Table(&MZ_SINKS),
Builtin::Table(&MZ_VIEWS),
Builtin::MaterializedView(&MZ_VIEWS),
Builtin::Table(&MZ_TYPES),
Builtin::Table(&MZ_TYPE_PG_METADATA),
Builtin::Table(&MZ_ARRAY_TYPES),
Expand Down
Loading
Loading