66//! The main types are:
77//! - [`MaterializedViewMetadata`]: The top-level metadata for a materialized view
88//! - [`RefreshState`]: Information about the last refresh operation
9- //! - [`SourceTables`]: Collection of source table states
10- //! - [`SourceViews`]: Collection of source view states
9+ //! - [`SourceStates`]: Collection of source states
1110
1211use std:: { collections:: HashMap , ops:: Deref } ;
1312
1413use serde:: { Deserialize , Serialize } ;
1514use uuid:: Uuid ;
1615
17- use crate :: identifier:: Identifier ;
16+ use crate :: {
17+ identifier:: { FullIdentifier , Identifier } ,
18+ namespace:: Namespace ,
19+ } ;
1820
1921use super :: {
2022 tabular:: TabularMetadataRef ,
@@ -41,26 +43,25 @@ pub struct RefreshState {
4143 /// The version-id of the materialized view when the refresh operation was performed.
4244 pub refresh_version_id : i64 ,
4345 /// A map from sequence-id (as defined in the view lineage) to the source tables’ snapshot-id of when the last refresh operation was performed.
44- pub source_table_states : SourceTables ,
45- /// A map from sequence-id (as defined in the view lineage) to the source views’ version-id of when the last refresh operation was performed.
46- pub source_view_states : SourceViews ,
46+ pub source_states : SourceStates ,
47+ // A timestamp of when the refresh operation was started
48+ pub refresh_start_timestamp_ms : i64 ,
4749}
4850
49- /// Represents a collection of source table states in a materialized view refresh
50- ///
51- /// # Fields
52- /// * `0` - A HashMap mapping (table UUID, optional reference) pairs to snapshot IDs
53- #[ derive( Debug , Serialize , Deserialize , PartialEq , Eq , Clone ) ]
54- #[ serde( from = "Vec<SourceTable>" , into = "Vec<SourceTable>" ) ]
55- pub struct SourceTables ( pub HashMap < ( Uuid , Option < String > ) , i64 > ) ;
56-
5751/// Represents a collection of source view states in a materialized view refresh
5852///
5953/// # Fields
6054/// * `0` - A HashMap mapping (table UUID, optional reference) pairs to version IDs
6155#[ derive( Debug , Serialize , Deserialize , PartialEq , Eq , Clone ) ]
62- #[ serde( from = "Vec<SourceView>" , into = "Vec<SourceView>" ) ]
63- pub struct SourceViews ( pub HashMap < ( Uuid , Option < String > ) , i64 > ) ;
56+ #[ serde( from = "Vec<SourceState>" , into = "Vec<SourceState>" ) ]
57+ pub struct SourceStates ( pub HashMap < FullIdentifier , SourceState > ) ;
58+
59+ #[ derive( Debug , Serialize , Deserialize , PartialEq , Eq , Clone ) ]
60+ #[ serde( rename_all = "kebab-case" , tag = "type" ) ]
61+ pub enum SourceState {
62+ Table ( SourceTable ) ,
63+ View ( SourceView ) ,
64+ }
6465
6566/// Represents a source table state in a materialized view refresh
6667///
@@ -71,8 +72,13 @@ pub struct SourceViews(pub HashMap<(Uuid, Option<String>), i64>);
7172#[ derive( Debug , Serialize , Deserialize , PartialEq , Eq , Clone ) ]
7273#[ serde( rename_all = "kebab-case" ) ]
7374pub struct SourceTable {
75+ name : String ,
76+ namespace : Namespace ,
77+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
78+ catalog : Option < String > ,
7479 uuid : Uuid ,
7580 snapshot_id : i64 ,
81+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
7682 r#ref : Option < String > ,
7783}
7884
@@ -84,65 +90,77 @@ pub struct SourceTable {
8490#[ derive( Debug , Serialize , Deserialize , PartialEq , Eq , Clone ) ]
8591#[ serde( rename_all = "kebab-case" ) ]
8692pub struct SourceView {
93+ name : String ,
94+ namespace : Namespace ,
95+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
96+ catalog : Option < String > ,
8797 uuid : Uuid ,
8898 version_id : i64 ,
8999}
90100
91- impl From < Vec < SourceTable > > for SourceTables {
92- fn from ( value : Vec < SourceTable > ) -> Self {
93- SourceTables (
94- value
95- . into_iter ( )
96- . map ( |x| ( ( x. uuid , x. r#ref ) , x. snapshot_id ) )
97- . collect ( ) ,
98- )
101+ impl SourceTable {
102+ /// Create a new SourceTable
103+ pub fn new (
104+ catalog : Option < & str > ,
105+ namespace : & [ String ] ,
106+ name : & str ,
107+ uuid : Uuid ,
108+ snapshot_id : i64 ,
109+ r#ref : Option < String > ,
110+ ) -> Self {
111+ Self {
112+ catalog : catalog. map ( ToString :: to_string) ,
113+ namespace : Namespace ( namespace. to_owned ( ) ) ,
114+ name : name. to_owned ( ) ,
115+ uuid,
116+ snapshot_id,
117+ r#ref,
118+ }
99119 }
100120}
101121
102- impl From < SourceTables > for Vec < SourceTable > {
103- fn from ( value : SourceTables ) -> Self {
104- value
105- . 0
106- . into_iter ( )
107- . map ( |( ( uuid, r#ref) , snapshot_id) | SourceTable {
108- uuid,
109- snapshot_id,
110- r#ref,
111- } )
112- . collect ( )
122+ impl SourceState {
123+ /// Returns the snapshot_id for Table states, None for View states
124+ pub fn snapshot_id ( & self ) -> Option < i64 > {
125+ match self {
126+ SourceState :: Table ( t) => Some ( t. snapshot_id ) ,
127+ SourceState :: View ( _) => None ,
128+ }
113129 }
114130}
115131
116- impl From < Vec < SourceView > > for SourceViews {
117- fn from ( value : Vec < SourceView > ) -> Self {
118- SourceViews (
132+ impl From < Vec < SourceState > > for SourceStates {
133+ fn from ( value : Vec < SourceState > ) -> Self {
134+ SourceStates (
119135 value
120136 . into_iter ( )
121- . map ( |x| ( ( x. uuid , None ) , x. version_id ) )
137+ . map ( |x| match & x {
138+ SourceState :: Table ( table) => (
139+ FullIdentifier :: new (
140+ table. catalog . as_deref ( ) ,
141+ & table. namespace ,
142+ & table. name ,
143+ ) ,
144+ x,
145+ ) ,
146+ SourceState :: View ( view) => (
147+ FullIdentifier :: new ( view. catalog . as_deref ( ) , & view. namespace , & view. name ) ,
148+ x,
149+ ) ,
150+ } )
122151 . collect ( ) ,
123152 )
124153 }
125154}
126155
127- impl From < SourceViews > for Vec < SourceView > {
128- fn from ( value : SourceViews ) -> Self {
129- value
130- . 0
131- . into_iter ( )
132- . map ( |( ( uuid, _) , version_id) | SourceView { uuid, version_id } )
133- . collect ( )
134- }
135- }
136-
137- impl Deref for SourceTables {
138- type Target = HashMap < ( Uuid , Option < String > ) , i64 > ;
139- fn deref ( & self ) -> & Self :: Target {
140- & self . 0
156+ impl From < SourceStates > for Vec < SourceState > {
157+ fn from ( value : SourceStates ) -> Self {
158+ value. 0 . into_values ( ) . collect ( )
141159 }
142160}
143161
144- impl Deref for SourceViews {
145- type Target = HashMap < ( Uuid , Option < String > ) , i64 > ;
162+ impl Deref for SourceStates {
163+ type Target = HashMap < FullIdentifier , SourceState > ;
146164 fn deref ( & self ) -> & Self :: Target {
147165 & self . 0
148166 }
@@ -181,7 +199,6 @@ mod tests {
181199 "dialect" : "spark"
182200 } ],
183201 "storage-table": {
184- "catalog": "prod",
185202 "namespace": ["default"],
186203 "name": "event_agg_storage"
187204 }
0 commit comments