@@ -320,39 +320,6 @@ fn csharp_precision_scale(type_name: &str, original_size: i32, original_scale: i
320320 }
321321}
322322
323- fn append_global_temp_schema ( batches : & mut Vec < RecordBatch > , schema : & Arc < Schema > ) -> Result < ( ) > {
324- for batch in batches. iter ( ) {
325- for row in 0 ..batch. num_rows ( ) {
326- if optional_string ( batch, "TABLE_SCHEM" , row) ?. as_deref ( ) == Some ( "global_temp" ) {
327- return Ok ( ( ) ) ;
328- }
329- }
330- }
331- let columns = schema
332- . fields ( )
333- . iter ( )
334- . map ( |field| match ( field. name ( ) . as_str ( ) , field. data_type ( ) ) {
335- ( "TABLE_SCHEM" , DataType :: Utf8 ) => {
336- Ok ( Arc :: new ( StringArray :: from ( vec ! [ "global_temp" ] ) ) as ArrayRef )
337- }
338- ( "TABLE_CATALOG" , DataType :: Utf8 ) => {
339- Ok ( Arc :: new ( StringArray :: from ( vec ! [ "" ] ) ) as ArrayRef )
340- }
341- ( "TABLE_SCHEM" , DataType :: LargeUtf8 ) => {
342- Ok ( Arc :: new ( arrow_array:: LargeStringArray :: from ( vec ! [ "global_temp" ] ) ) as ArrayRef )
343- }
344- ( "TABLE_CATALOG" , DataType :: LargeUtf8 ) => {
345- Ok ( Arc :: new ( arrow_array:: LargeStringArray :: from ( vec ! [ "" ] ) ) as ArrayRef )
346- }
347- ( name, data_type) => Err ( invalid ( format ! (
348- "unexpected GetSchemas field {name} with type {data_type}"
349- ) ) ) ,
350- } )
351- . collect :: < Result < Vec < _ > > > ( ) ?;
352- batches. push ( RecordBatch :: try_new ( Arc :: clone ( schema) , columns) ?) ;
353- Ok ( ( ) )
354- }
355-
356323fn csharp_key_schema ( schema : & Arc < Schema > ) -> Arc < Schema > {
357324 Arc :: new ( Schema :: new_with_metadata (
358325 schema
@@ -463,6 +430,14 @@ pub(crate) fn execute_statement_command(
463430 } ;
464431 let source_schema = stream. schema ( ) ;
465432 let batches = drain ( runtime, stream) ?;
433+ statement_result_reader ( command, source_schema, batches)
434+ }
435+
436+ fn statement_result_reader (
437+ command : & str ,
438+ source_schema : Arc < Schema > ,
439+ batches : Vec < RecordBatch > ,
440+ ) -> Result < Reader > {
466441 if command. eq_ignore_ascii_case ( "GetPrimaryKeys" )
467442 || command. eq_ignore_ascii_case ( "GetCrossReference" )
468443 {
@@ -476,16 +451,6 @@ pub(crate) fn execute_statement_command(
476451 . collect :: < Result < Vec < _ > > > ( ) ?;
477452 return Ok ( batches_reader ( output_schema, batches) ) ;
478453 }
479- if command. eq_ignore_ascii_case ( "GetSchemas" ) {
480- let mut batches = batches;
481- if schema
482- . as_deref ( )
483- . is_none_or ( |schema| like_match ( schema, "global_temp" ) )
484- {
485- append_global_temp_schema ( & mut batches, & source_schema) ?;
486- }
487- return Ok ( batches_reader ( source_schema, batches) ) ;
488- }
489454 if !command. eq_ignore_ascii_case ( "GetColumns" ) {
490455 return Ok ( batches_reader ( source_schema, batches) ) ;
491456 }
@@ -1542,30 +1507,38 @@ mod tests {
15421507 }
15431508
15441509 #[ test]
1545- fn get_schemas_extension_appends_global_temp_once ( ) {
1510+ fn get_schemas_statement_preserves_server_rows ( ) {
15461511 let schema = Arc :: new ( Schema :: new ( vec ! [
15471512 Field :: new( "TABLE_SCHEM" , DataType :: Utf8 , false ) ,
15481513 Field :: new( "TABLE_CATALOG" , DataType :: Utf8 , false ) ,
15491514 ] ) ) ;
1550- let mut batches = vec ! [ RecordBatch :: try_new(
1551- Arc :: clone( & schema) ,
1552- vec![
1553- Arc :: new( StringArray :: from( vec![ "default" ] ) ) ,
1554- Arc :: new( StringArray :: from( vec![ "main" ] ) ) ,
1555- ] ,
1556- )
1557- . unwrap( ) ] ;
1558- append_global_temp_schema ( & mut batches, & schema) . unwrap ( ) ;
1559- append_global_temp_schema ( & mut batches, & schema) . unwrap ( ) ;
1560- assert_eq ! ( batches. len( ) , 2 ) ;
1561- assert_eq ! (
1562- required_string( & batches[ 1 ] , "TABLE_SCHEM" , 0 ) . unwrap( ) ,
1563- "global_temp"
1564- ) ;
1565- assert_eq ! (
1566- required_string( & batches[ 1 ] , "TABLE_CATALOG" , 0 ) . unwrap( ) ,
1567- ""
1568- ) ;
1515+ for ( schemas, catalogs) in [
1516+ ( vec ! [ ] , vec ! [ ] ) ,
1517+ ( vec ! [ "default" ] , vec ! [ "main" ] ) ,
1518+ ( vec ! [ "default" , "global_temp" ] , vec ! [ "main" , "" ] ) ,
1519+ ] {
1520+ let batch = RecordBatch :: try_new (
1521+ Arc :: clone ( & schema) ,
1522+ vec ! [
1523+ Arc :: new( StringArray :: from( schemas. clone( ) ) ) ,
1524+ Arc :: new( StringArray :: from( catalogs. clone( ) ) ) ,
1525+ ] ,
1526+ )
1527+ . unwrap ( ) ;
1528+ for command in [ "GetSchemas" , "getschemas" ] {
1529+ let mut reader =
1530+ statement_result_reader ( command, Arc :: clone ( & schema) , vec ! [ batch. clone( ) ] )
1531+ . unwrap ( ) ;
1532+ assert_eq ! ( reader. schema( ) , schema) ;
1533+ let actual = reader. next ( ) . unwrap ( ) . unwrap ( ) ;
1534+ assert_eq ! ( actual, batch) ;
1535+ assert ! ( reader. next( ) . is_none( ) ) ;
1536+ }
1537+ }
1538+ let mut reader =
1539+ statement_result_reader ( "GetSchemas" , Arc :: clone ( & schema) , vec ! [ ] ) . unwrap ( ) ;
1540+ assert_eq ! ( reader. schema( ) , schema) ;
1541+ assert ! ( reader. next( ) . is_none( ) ) ;
15691542 }
15701543
15711544 #[ test]
0 commit comments