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 ;
1510use 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
10518impl 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 }
0 commit comments