@@ -5,7 +5,7 @@ use datafusion::{
55 sql:: {
66 sqlparser:: {
77 self ,
8- ast:: FunctionArg ,
8+ ast:: { FunctionArg , ObjectNamePart } ,
99 dialect:: { Dialect , GenericDialect } ,
1010 tokenizer:: Token ,
1111 } ,
@@ -15,14 +15,16 @@ use datafusion::{
1515
1616/// A multipart identifier to a remote table, view or parameterized view.
1717///
18- /// RemoteTableRef can be created by parsing from a string represeting a table obbject with optional
18+ /// RemoteTableRef can be created by parsing from a string representing a table object with optional
1919/// ```rust
20+ /// use datafusion_federation::sql::RemoteTableRef;
21+ /// use datafusion::sql::sqlparser::dialect::PostgreSqlDialect;
2022///
2123/// RemoteTableRef::try_from("myschema.table");
2224/// RemoteTableRef::try_from(r#"myschema."Table""#);
2325/// RemoteTableRef::try_from("myschema.view('obj')");
2426///
25- /// RemoteTableRef::parse_with_dialect("myschema.view(name = 'obj')", &PostgresSqlDialect {});
27+ /// RemoteTableRef::parse_with_dialect("myschema.view(name = 'obj')", &PostgreSqlDialect {});
2628/// ```
2729#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
2830pub struct RemoteTableRef {
@@ -41,7 +43,7 @@ impl RemoteTableRef {
4143 Self :: parse_with_dialect ( s, & GenericDialect { } )
4244 }
4345
44- /// Create new using a specfic instance of dialect.
46+ /// Create new using a specific instance of dialect.
4547 pub fn parse_with_dialect ( s : & str , dialect : & dyn Dialect ) -> Result < Self , DataFusionError > {
4648 let mut parser = sqlparser:: parser:: Parser :: new ( dialect) . try_with_sql ( s) ?;
4749 let name = parser. parse_object_name ( true ) ?;
@@ -52,15 +54,23 @@ impl RemoteTableRef {
5254 } ;
5355
5456 let table_ref = match ( name. 0 . first ( ) , name. 0 . get ( 1 ) , name. 0 . get ( 2 ) ) {
55- ( Some ( catalog) , Some ( schema) , Some ( table) ) => TableReference :: full (
57+ (
58+ Some ( ObjectNamePart :: Identifier ( catalog) ) ,
59+ Some ( ObjectNamePart :: Identifier ( schema) ) ,
60+ Some ( ObjectNamePart :: Identifier ( table) ) ,
61+ ) => TableReference :: full (
5662 catalog. value . clone ( ) ,
5763 schema. value . clone ( ) ,
5864 table. value . clone ( ) ,
5965 ) ,
60- ( Some ( schema) , Some ( table) , None ) => {
61- TableReference :: partial ( schema. value . clone ( ) , table. value . clone ( ) )
66+ (
67+ Some ( ObjectNamePart :: Identifier ( schema) ) ,
68+ Some ( ObjectNamePart :: Identifier ( table) ) ,
69+ None ,
70+ ) => TableReference :: partial ( schema. value . clone ( ) , table. value . clone ( ) ) ,
71+ ( Some ( ObjectNamePart :: Identifier ( table) ) , None , None ) => {
72+ TableReference :: bare ( table. value . clone ( ) )
6273 }
63- ( Some ( table) , None , None ) => TableReference :: bare ( table. value . clone ( ) ) ,
6474 _ => {
6575 return Err ( DataFusionError :: NotImplemented (
6676 "Unable to parse string into TableReference" . to_string ( ) ,
@@ -166,8 +176,8 @@ mod tests {
166176 let expected = RemoteTableRef :: from ( (
167177 TableReference :: bare ( "table" ) ,
168178 vec ! [
169- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
170- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
179+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
180+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
171181 ] ,
172182 ) ) ;
173183 assert_eq ! ( table_ref, expected) ;
@@ -176,8 +186,8 @@ mod tests {
176186 let expected = RemoteTableRef :: from ( (
177187 TableReference :: bare ( "Table" ) ,
178188 vec ! [
179- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
180- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
189+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
190+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
181191 ] ,
182192 ) ) ;
183193 assert_eq ! ( table_ref, expected) ;
@@ -189,8 +199,8 @@ mod tests {
189199 let expected = RemoteTableRef :: from ( (
190200 TableReference :: bare ( "table" ) ,
191201 vec ! [
192- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
193- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
202+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
203+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
194204 ] ,
195205 ) ) ;
196206 assert_eq ! ( table_ref, expected) ;
@@ -199,8 +209,8 @@ mod tests {
199209 let expected = RemoteTableRef :: from ( (
200210 TableReference :: bare ( "Table" ) ,
201211 vec ! [
202- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
203- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
212+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
213+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
204214 ] ,
205215 ) ) ;
206216 assert_eq ! ( table_ref, expected) ;
@@ -223,8 +233,8 @@ mod tests {
223233 let expected = RemoteTableRef :: from ( (
224234 TableReference :: partial ( "schema" , "table" ) ,
225235 vec ! [
226- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
227- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
236+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
237+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
228238 ] ,
229239 ) ) ;
230240 assert_eq ! ( table_ref, expected) ;
@@ -233,8 +243,8 @@ mod tests {
233243 let expected = RemoteTableRef :: from ( (
234244 TableReference :: partial ( "schema" , "Table" ) ,
235245 vec ! [
236- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
237- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
246+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
247+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
238248 ] ,
239249 ) ) ;
240250 assert_eq ! ( table_ref, expected) ;
@@ -246,8 +256,8 @@ mod tests {
246256 let expected = RemoteTableRef :: from ( (
247257 TableReference :: partial ( "schema" , "table" ) ,
248258 vec ! [
249- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
250- FunctionArg :: Unnamed ( Expr :: Value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
259+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ) ,
260+ FunctionArg :: Unnamed ( Expr :: value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ) ,
251261 ] ,
252262 ) ) ;
253263 assert_eq ! ( table_ref, expected) ;
@@ -265,12 +275,12 @@ mod tests {
265275 vec ! [
266276 FunctionArg :: ExprNamed {
267277 name: ast:: Expr :: Identifier ( Ident :: new( "user_id" ) ) ,
268- arg: Expr :: Value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ,
278+ arg: Expr :: value ( Value :: Number ( "1" . to_string( ) , false ) ) . into( ) ,
269279 operator: FunctionArgOperator :: RightArrow ,
270280 } ,
271281 FunctionArg :: ExprNamed {
272282 name: ast:: Expr :: Identifier ( Ident :: new( "age" ) ) ,
273- arg: Expr :: Value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ,
283+ arg: Expr :: value ( Value :: Number ( "2" . to_string( ) , false ) ) . into( ) ,
274284 operator: FunctionArgOperator :: RightArrow ,
275285 } ,
276286 ] ,
0 commit comments