Skip to content

Commit cb60c0f

Browse files
committed
remove CatalogItemId enum
Make it an alias of `GlobalId`.
1 parent 4a5abcb commit cb60c0f

File tree

6 files changed

+11
-92
lines changed

6 files changed

+11
-92
lines changed

src/adapter/src/coord.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,8 @@ impl Coordinator {
23622362
CatalogItemId::System(id) => *id >= next_system_item_id,
23632363
CatalogItemId::User(id) => *id >= next_user_item_id,
23642364
CatalogItemId::IntrospectionSourceIndex(_)
2365-
| CatalogItemId::Transient(_) => false,
2365+
| CatalogItemId::Transient(_)
2366+
| CatalogItemId::Explain => false,
23662367
};
23672368
if id_too_large {
23682369
info!(

src/catalog-protos/src/serialization.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ impl RustType<crate::objects::CatalogItemId> for CatalogItemId {
590590
CatalogItemId::Transient(x) => {
591591
crate::objects::catalog_item_id::Value::Transient(*x)
592592
}
593+
CatalogItemId::Explain => unimplemented!(),
593594
}),
594595
}
595596
}

src/catalog/src/durable/objects.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ impl TryFrom<CatalogItemId> for SystemCatalogItemId {
637637
CatalogItemId::IntrospectionSourceIndex(_) => Err("introspection_source_index"),
638638
CatalogItemId::User(_) => Err("user"),
639639
CatalogItemId::Transient(_) => Err("transient"),
640+
CatalogItemId::Explain => Err("explain"),
640641
}
641642
}
642643
}
@@ -662,6 +663,7 @@ impl TryFrom<CatalogItemId> for IntrospectionSourceIndexCatalogItemId {
662663
}
663664
CatalogItemId::User(_) => Err("user"),
664665
CatalogItemId::Transient(_) => Err("transient"),
666+
CatalogItemId::Explain => Err("explain"),
665667
}
666668
}
667669
}

src/repr/src/catalog_item_id.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ message ProtoCatalogItemId {
1919
uint64 user = 2;
2020
uint64 transient = 3;
2121
uint64 introspection_source_index = 4;
22+
google.protobuf.Empty explain = 5;
2223
}
2324
}

src/repr/src/catalog_item_id.rs

Lines changed: 5 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -7,100 +7,13 @@
77
// the Business Source License, use of this software will be governed
88
// by the Apache License, Version 2.0.
99

10-
use std::fmt;
11-
use std::str::FromStr;
12-
13-
use anyhow::{Error, anyhow};
14-
use mz_lowertest::MzReflect;
1510
use mz_proto::{RustType, TryFromProtoError};
16-
use proptest_derive::Arbitrary;
17-
use serde::{Deserialize, Serialize};
18-
19-
include!(concat!(env!("OUT_DIR"), "/mz_repr.catalog_item_id.rs"));
20-
21-
/// The identifier for an item within the Catalog.
22-
#[derive(
23-
Arbitrary,
24-
Clone,
25-
Copy,
26-
Debug,
27-
Eq,
28-
PartialEq,
29-
Ord,
30-
PartialOrd,
31-
Hash,
32-
Serialize,
33-
Deserialize,
34-
MzReflect,
35-
)]
36-
pub enum CatalogItemId {
37-
/// System namespace.
38-
System(u64),
39-
/// Introspection Source Index namespace.
40-
IntrospectionSourceIndex(u64),
41-
/// User namespace.
42-
User(u64),
43-
/// Transient item.
44-
Transient(u64),
45-
}
4611

47-
impl CatalogItemId {
48-
/// Reports whether this ID is in the system namespace.
49-
pub fn is_system(&self) -> bool {
50-
matches!(
51-
self,
52-
CatalogItemId::System(_) | CatalogItemId::IntrospectionSourceIndex(_)
53-
)
54-
}
55-
56-
/// Reports whether this ID is in the user namespace.
57-
pub fn is_user(&self) -> bool {
58-
matches!(self, CatalogItemId::User(_))
59-
}
12+
use crate::GlobalId;
6013

61-
/// Reports whether this ID is for a transient item.
62-
pub fn is_transient(&self) -> bool {
63-
matches!(self, CatalogItemId::Transient(_))
64-
}
65-
}
66-
67-
impl FromStr for CatalogItemId {
68-
type Err = Error;
69-
70-
fn from_str(mut s: &str) -> Result<Self, Self::Err> {
71-
if s.len() < 2 {
72-
return Err(anyhow!("couldn't parse id {}", s));
73-
}
74-
let tag = s.chars().next().unwrap();
75-
s = &s[1..];
76-
let variant = match tag {
77-
's' => {
78-
if Some('i') == s.chars().next() {
79-
s = &s[1..];
80-
CatalogItemId::IntrospectionSourceIndex
81-
} else {
82-
CatalogItemId::System
83-
}
84-
}
85-
'u' => CatalogItemId::User,
86-
't' => CatalogItemId::Transient,
87-
_ => return Err(anyhow!("couldn't parse id {}", s)),
88-
};
89-
let val: u64 = s.parse()?;
90-
Ok(variant(val))
91-
}
92-
}
14+
include!(concat!(env!("OUT_DIR"), "/mz_repr.catalog_item_id.rs"));
9315

94-
impl fmt::Display for CatalogItemId {
95-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
96-
match self {
97-
CatalogItemId::System(id) => write!(f, "s{}", id),
98-
CatalogItemId::IntrospectionSourceIndex(id) => write!(f, "si{}", id),
99-
CatalogItemId::User(id) => write!(f, "u{}", id),
100-
CatalogItemId::Transient(id) => write!(f, "t{}", id),
101-
}
102-
}
103-
}
16+
pub type CatalogItemId = GlobalId;
10417

10518
impl RustType<ProtoCatalogItemId> for CatalogItemId {
10619
fn into_proto(&self) -> ProtoCatalogItemId {
@@ -111,6 +24,7 @@ impl RustType<ProtoCatalogItemId> for CatalogItemId {
11124
CatalogItemId::IntrospectionSourceIndex(x) => IntrospectionSourceIndex(*x),
11225
CatalogItemId::User(x) => User(*x),
11326
CatalogItemId::Transient(x) => Transient(*x),
27+
CatalogItemId::Explain => Explain(()),
11428
}),
11529
}
11630
}
@@ -122,6 +36,7 @@ impl RustType<ProtoCatalogItemId> for CatalogItemId {
12236
Some(IntrospectionSourceIndex(x)) => Ok(CatalogItemId::IntrospectionSourceIndex(x)),
12337
Some(User(x)) => Ok(CatalogItemId::User(x)),
12438
Some(Transient(x)) => Ok(CatalogItemId::Transient(x)),
39+
Some(Explain(())) => Ok(CatalogItemId::Explain),
12540
None => Err(TryFromProtoError::missing_field("ProtoCatalogItemId::kind")),
12641
}
12742
}

src/storage-types/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub trait AlterCompatible: std::fmt::Debug + PartialEq {
4848
}
4949

5050
impl AlterCompatible for mz_repr::GlobalId {}
51-
impl AlterCompatible for mz_repr::CatalogItemId {}
5251

5352
/// The diff type used by storage.
5453
pub type StorageDiff = i64;

0 commit comments

Comments
 (0)