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/sql/system-catalog/mz_internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -1685,11 +1685,13 @@ 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_columns -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_functions -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_index_columns -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_indexes -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_log_indexes -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_materialized_views -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_object_mappings -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_operators -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_sources -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_tables -->
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_builtin_types -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
"mz_columns": MzVersion.parse_mz("v26.49.0"),
"mz_default_privileges": MzVersion.parse_mz("v26.30.0"),
"mz_egress_ips": None,
"mz_functions": None,
"mz_functions": MzVersion.parse_mz("v26.54.0"),
"mz_iceberg_sinks": MzVersion.parse_mz("v26.38.0"),
"mz_index_columns": MzVersion.parse_mz("v26.49.0"),
"mz_kafka_connections": MzVersion.parse_mz("v26.37.0"),
"mz_kafka_sinks": MzVersion.parse_mz("v26.38.0"),
"mz_kafka_sources": MzVersion.parse_mz("v26.34.0"),
"mz_list_types": MzVersion.parse_mz("v26.54.0"),
"mz_map_types": MzVersion.parse_mz("v26.54.0"),
"mz_operators": None,
"mz_operators": MzVersion.parse_mz("v26.54.0"),
"mz_pseudo_types": MzVersion.parse_mz("v26.54.0"),
"mz_sinks": MzVersion.parse_mz("v26.38.0"),
"mz_ssh_tunnel_connections": MzVersion.parse_mz("v26.37.0"),
Expand Down
148 changes: 9 additions & 139 deletions src/adapter/src/catalog/builtin_table_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,20 @@ mod notice;
use bytesize::ByteSize;
use ipnet::IpNet;
use mz_audit_log::VersionedStorageUsage;
use mz_catalog::SYSTEM_CONN_ID;
use mz_catalog::builtin::{
BuiltinTable, MZ_AGGREGATES, MZ_CLUSTER_REPLICA_SIZE_INTERNAL, MZ_CLUSTER_REPLICA_SIZES,
MZ_EGRESS_IPS, MZ_FUNCTIONS, MZ_LICENSE_KEYS, MZ_OPERATORS, MZ_ROLE_AUTH, MZ_SESSIONS,
MZ_STORAGE_USAGE_BY_SHARD, MZ_SUBSCRIPTIONS, MZ_WEBHOOKS_SOURCES,
BuiltinTable, MZ_CLUSTER_REPLICA_SIZE_INTERNAL, MZ_CLUSTER_REPLICA_SIZES, MZ_EGRESS_IPS,
MZ_LICENSE_KEYS, MZ_ROLE_AUTH, MZ_SESSIONS, MZ_STORAGE_USAGE_BY_SHARD, MZ_SUBSCRIPTIONS,
MZ_WEBHOOKS_SOURCES,
};
use mz_catalog::memory::error::Error;
use mz_catalog::memory::objects::{CatalogItem, DataSourceDesc, Func};
use mz_catalog::memory::objects::{CatalogItem, DataSourceDesc};
use mz_controller::clusters::ReplicaAllocation;
use mz_license_keys::ValidatedLicenseKey;
use mz_orchestrator::{CpuLimit, DiskLimit, MemoryLimit};
use mz_ore::cast::CastFrom;
use mz_persist_client::batch::ProtoBatch;
use mz_repr::adt::array::ArrayDimension;
use mz_repr::role_id::RoleId;
use mz_repr::{CatalogItemId, Datum, Diff, GlobalId, Row};
use mz_sql::func::FuncImplCatalogDetails;
use mz_sql::names::SchemaSpecifier;
use mz_storage_client::client::TableData;
use smallvec::smallvec;
use uuid::Uuid;
Expand Down Expand Up @@ -116,16 +112,6 @@ impl CatalogState {
diff: Diff,
) -> Vec<BuiltinTableUpdate<&'static BuiltinTable>> {
let entry = self.get_entry(&id);
let conn_id = entry.item().conn_id().unwrap_or(&SYSTEM_CONN_ID);
let schema_id = &self
.get_schema(
&entry.name().qualifiers.database_spec,
&entry.name().qualifiers.schema_spec,
conn_id,
)
.id;
let name = &entry.name().item;
let owner_id = entry.owner_id();
let updates = match entry.item() {
CatalogItem::Source(source) => {
match &source.data_source {
Expand All @@ -146,18 +132,16 @@ impl CatalogState {
// mz_sinks, mz_kafka_sinks and mz_iceberg_sinks read create_sql
// out of mz_catalog_raw, so there is nothing to pack here.
CatalogItem::Sink(_) => vec![],
CatalogItem::Func(func) => {
self.pack_func_update(id, schema_id, name, owner_id, func, diff)
}
// Tables, views, materialized views, indexes, types and metric
// sinks are exposed through relations derived from
// `mz_catalog_raw`, and logs and secrets never had builtin-table
// rows, so none pack a row here.
// Tables, views, materialized views, indexes, types, functions
// and metric sinks are exposed through materialized views derived
// from `mz_catalog_raw`, and logs and secrets never had
// builtin-table rows, so none pack a row here.
Comment on lines +135 to +138

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.

#40843 changed this to "relations derived from", and this goes back to "materialized views". The type and function relations are plain views now.

CatalogItem::Table(_)
| CatalogItem::View(_)
| CatalogItem::MaterializedView(_)
| CatalogItem::Index(_)
| CatalogItem::Type(_)
| CatalogItem::Func(_)
| CatalogItem::Log(_)
| CatalogItem::Secret(_)
| CatalogItem::MetricSink(_) => vec![],
Expand All @@ -171,120 +155,6 @@ impl CatalogState {
updates
}

fn pack_func_update(
&self,
id: CatalogItemId,
schema_id: &SchemaSpecifier,
name: &str,
owner_id: &RoleId,
func: &Func,
diff: Diff,
) -> Vec<BuiltinTableUpdate<&'static BuiltinTable>> {
let mut updates = vec![];
for func_impl_details in func.inner.func_impls() {
let arg_type_ids = func_impl_details
.arg_typs
.iter()
.map(|typ| self.get_system_type(typ).id().to_string())
.collect::<Vec<_>>();

let mut row = Row::default();
row.packer()
.try_push_array(
&[ArrayDimension {
lower_bound: 1,
length: arg_type_ids.len(),
}],
arg_type_ids.iter().map(|id| Datum::String(id)),
)
.expect(
"arg_type_ids is 1 dimensional, and its length is used for the array length",
);
let arg_type_ids = row.unpack_first();

updates.push(BuiltinTableUpdate::row(
&*MZ_FUNCTIONS,
Row::pack_slice(&[
Datum::String(&id.to_string()),
Datum::UInt32(func_impl_details.oid),
Datum::String(&schema_id.to_string()),
Datum::String(name),
arg_type_ids,
Datum::from(
func_impl_details
.variadic_typ
.map(|typ| self.get_system_type(typ).id().to_string())
.as_deref(),
),
Datum::from(
func_impl_details
.return_typ
.map(|typ| self.get_system_type(typ).id().to_string())
.as_deref(),
),
func_impl_details.return_is_set.into(),
Datum::String(&owner_id.to_string()),
]),
diff,
));

if let mz_sql::func::Func::Aggregate(_) = func.inner {
updates.push(BuiltinTableUpdate::row(
&*MZ_AGGREGATES,
Row::pack_slice(&[
Datum::UInt32(func_impl_details.oid),
// TODO(database-issues#1064): Support ordered-set aggregate functions.
Datum::String("n"),
Datum::Int16(0),
]),
diff,
));
}
}
updates
}

pub fn pack_op_update(
&self,
operator: &str,
func_impl_details: FuncImplCatalogDetails,
diff: Diff,
) -> BuiltinTableUpdate<&'static BuiltinTable> {
let arg_type_ids = func_impl_details
.arg_typs
.iter()
.map(|typ| self.get_system_type(typ).id().to_string())
.collect::<Vec<_>>();

let mut row = Row::default();
row.packer()
.try_push_array(
&[ArrayDimension {
lower_bound: 1,
length: arg_type_ids.len(),
}],
arg_type_ids.iter().map(|id| Datum::String(id)),
)
.expect("arg_type_ids is 1 dimensional, and its length is used for the array length");
let arg_type_ids = row.unpack_first();

BuiltinTableUpdate::row(
&*MZ_OPERATORS,
Row::pack_slice(&[
Datum::UInt32(func_impl_details.oid),
Datum::String(operator),
arg_type_ids,
Datum::from(
func_impl_details
.return_typ
.map(|typ| self.get_system_type(typ).id().to_string())
.as_deref(),
),
]),
diff,
)
}

pub fn pack_storage_usage_update(
&self,
VersionedStorageUsage::V1(event): VersionedStorageUsage,
Expand Down
16 changes: 0 additions & 16 deletions src/adapter/src/catalog/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ use mz_repr::adt::mz_acl_item::PrivilegeMap;
use mz_repr::namespaces::is_unstable_schema;
use mz_repr::{CatalogItemId, Diff, GlobalId, RelationVersion, Timestamp};
use mz_sql::catalog::{CatalogError as SqlCatalogError, CatalogItemType, RoleMembership, RoleVars};
use mz_sql::func::OP_IMPLS;
use mz_sql::names::CommentObjectId;
use mz_sql::rbac;
use mz_sql::session::user::{MZ_SYSTEM_ROLE_ID, SYSTEM_USER};
Expand Down Expand Up @@ -623,21 +622,6 @@ impl Catalog {
storage: Arc::new(tokio::sync::Mutex::new(storage)),
};

// Operators aren't stored in the catalog, but we would like them in
// introspection views.
for (op, func) in OP_IMPLS.iter() {
match func {
mz_sql::func::Func::Scalar(impls) => {
for imp in impls {
builtin_table_updates.push(catalog.state.resolve_builtin_table_update(
catalog.state.pack_op_update(op, imp.details(), Diff::ONE),
));
}
}
_ => unreachable!("all operators must be scalar functions"),
}
}

for ip in &catalog.state.egress_addresses {
builtin_table_updates.push(
catalog
Expand Down
11 changes: 6 additions & 5 deletions src/catalog/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,9 +1222,9 @@ pub static BUILTINS_STATIC: LazyLock<Vec<Builtin<NameReference>>> = LazyLock::ne
Builtin::MaterializedView(&MZ_ROLE_MEMBERS),
Builtin::MaterializedView(&MZ_ROLE_PARAMETERS),
Builtin::View(&MZ_PSEUDO_TYPES),
Builtin::Table(&MZ_FUNCTIONS),
Builtin::Table(&MZ_OPERATORS),
Builtin::Table(&MZ_AGGREGATES),
Builtin::View(&MZ_FUNCTIONS),
Builtin::View(&MZ_OPERATORS),
Builtin::View(&MZ_AGGREGATES),
Builtin::Table(&MZ_CLUSTER_REPLICA_SIZES),
Builtin::Table(&MZ_CLUSTER_REPLICA_SIZE_INTERNAL),
Builtin::MaterializedView(&MZ_CLUSTERS),
Expand Down Expand Up @@ -1572,7 +1572,7 @@ pub static BUILTINS_STATIC: LazyLock<Vec<Builtin<NameReference>>> = LazyLock::ne
{
let ontology_preview = ontology::generate_views(&builtin_items);
let builtin_reporter_preview: Vec<_> =
builtin::builtins(&builtin_types, &builtin_items).collect();
builtin::builtins(&builtin_types, &builtin_funcs, &builtin_items).collect();
let generator_input: Vec<_> = builtin_types
.iter()
.chain(builtin_funcs.iter())
Expand All @@ -1599,7 +1599,8 @@ pub static BUILTINS_STATIC: LazyLock<Vec<Builtin<NameReference>>> = LazyLock::ne

// Generate builtin relations reporting builtin objects last, since they need a complete view
// of all other builtins.
let mut builtin_builtins = builtin::builtins(&builtin_types, &builtin_items).collect();
let mut builtin_builtins =
builtin::builtins(&builtin_types, &builtin_funcs, &builtin_items).collect();

// Construct the full list of builtins, retaining dependency order.
let mut builtins = Vec::new();
Expand Down
Loading