1616// under the License.
1717
1818use std:: fmt:: { self , Display , Formatter } ;
19- use std:: sync:: { Arc , RwLock } ;
19+ use std:: sync:: Arc ;
2020use std:: { any:: Any , borrow:: Cow } ;
2121
2222use arrow:: datatypes:: Schema ;
@@ -25,7 +25,6 @@ use datafusion::arrow::datatypes::SchemaRef;
2525use datafusion:: common:: Constraints ;
2626use datafusion:: datasource:: TableType ;
2727use datafusion:: logical_expr:: { Expr , TableProviderFilterPushDown , TableSource } ;
28- use pyo3:: exceptions:: PyRuntimeError ;
2928use pyo3:: prelude:: * ;
3029
3130use datafusion:: logical_expr:: utils:: split_conjunction;
@@ -34,6 +33,8 @@ use crate::sql::logical::PyLogicalPlan;
3433
3534use super :: { data_type:: DataTypeMap , function:: SqlFunction } ;
3635
36+ use parking_lot:: RwLock ;
37+
3738#[ pyclass( name = "SqlSchema" , module = "datafusion.common" , subclass, frozen) ]
3839#[ derive( Debug , Clone ) ]
3940pub struct SqlSchema {
@@ -110,88 +111,60 @@ impl SqlSchema {
110111
111112 #[ getter]
112113 fn name ( & self ) -> PyResult < String > {
113- Ok ( self
114- . name
115- . read ( )
116- . map_err ( |_| PyRuntimeError :: new_err ( "failed to read schema name" ) ) ?
117- . clone ( ) )
114+ Ok ( self . name . read ( ) . clone ( ) )
118115 }
119116
120117 #[ setter]
121118 fn set_name ( & self , value : String ) -> PyResult < ( ) > {
122- * self
123- . name
124- . write ( )
125- . map_err ( |_| PyRuntimeError :: new_err ( "failed to write schema name" ) ) ? = value;
119+ * self . name . write ( ) = value;
126120 Ok ( ( ) )
127121 }
128122
129123 #[ getter]
130124 fn tables ( & self ) -> PyResult < Vec < SqlTable > > {
131- Ok ( self
132- . tables
133- . read ( )
134- . map_err ( |_| PyRuntimeError :: new_err ( "failed to read schema tables" ) ) ?
135- . clone ( ) )
125+ Ok ( self . tables . read ( ) . clone ( ) )
136126 }
137127
138128 #[ setter]
139129 fn set_tables ( & self , tables : Vec < SqlTable > ) -> PyResult < ( ) > {
140- * self
141- . tables
142- . write ( )
143- . map_err ( |_| PyRuntimeError :: new_err ( "failed to write schema tables" ) ) ? = tables;
130+ * self . tables . write ( ) = tables;
144131 Ok ( ( ) )
145132 }
146133
147134 #[ getter]
148135 fn views ( & self ) -> PyResult < Vec < SqlView > > {
149- Ok ( self
150- . views
151- . read ( )
152- . map_err ( |_| PyRuntimeError :: new_err ( "failed to read schema views" ) ) ?
153- . clone ( ) )
136+ Ok ( self . views . read ( ) . clone ( ) )
154137 }
155138
156139 #[ setter]
157140 fn set_views ( & self , views : Vec < SqlView > ) -> PyResult < ( ) > {
158- * self
159- . views
160- . write ( )
161- . map_err ( |_| PyRuntimeError :: new_err ( "failed to write schema views" ) ) ? = views;
141+ * self . views . write ( ) = views;
162142 Ok ( ( ) )
163143 }
164144
165145 #[ getter]
166146 fn functions ( & self ) -> PyResult < Vec < SqlFunction > > {
167- Ok ( self
168- . functions
169- . read ( )
170- . map_err ( |_| PyRuntimeError :: new_err ( "failed to read schema functions" ) ) ?
171- . clone ( ) )
147+ Ok ( self . functions . read ( ) . clone ( ) )
172148 }
173149
174150 #[ setter]
175151 fn set_functions ( & self , functions : Vec < SqlFunction > ) -> PyResult < ( ) > {
176- * self
177- . functions
178- . write ( )
179- . map_err ( |_| PyRuntimeError :: new_err ( "failed to write schema functions" ) ) ? = functions;
152+ * self . functions . write ( ) = functions;
180153 Ok ( ( ) )
181154 }
182155
183156 pub fn table_by_name ( & self , table_name : & str ) -> Option < SqlTable > {
184- let tables = self . tables . read ( ) . expect ( "failed to read schema tables" ) ;
157+ let tables = self . tables . read ( ) ;
185158 tables. iter ( ) . find ( |tbl| tbl. name . eq ( table_name) ) . cloned ( )
186159 }
187160
188161 pub fn add_table ( & self , table : SqlTable ) {
189- let mut tables = self . tables . write ( ) . expect ( "failed to write schema tables" ) ;
162+ let mut tables = self . tables . write ( ) ;
190163 tables. push ( table) ;
191164 }
192165
193166 pub fn drop_table ( & self , table_name : String ) {
194- let mut tables = self . tables . write ( ) . expect ( "failed to write schema tables" ) ;
167+ let mut tables = self . tables . write ( ) ;
195168 tables. retain ( |x| !x. name . eq ( & table_name) ) ;
196169 }
197170}
0 commit comments