@@ -491,4 +491,41 @@ async fn test_select_system_column() {
491
491
"+--------------+-----------+" ,
492
492
] ;
493
493
assert_batches_sorted_eq ! ( expected, & batchs) ;
494
+
495
+ let batch = record_batch ! (
496
+ ( "other_id" , UInt8 , [ 1 , 2 , 3 ] ) ,
497
+ ( "bank_account" , UInt64 , [ 9 , 10 , 11 ] ) ,
498
+ ( "_row_id" , UInt32 , [ 10 , 11 , 12 ] )
499
+ )
500
+ . unwrap ( ) ;
501
+ let schema = Schema :: new ( vec ! [
502
+ Field :: new( "other_id" , DataType :: UInt8 , true ) ,
503
+ Field :: new( "bank_account" , DataType :: UInt64 , true ) ,
504
+ Field :: new( "_row_id" , DataType :: UInt32 , true ) , // not a system column!
505
+ ] ) ;
506
+ let batch = batch. with_schema ( Arc :: new ( schema) ) . unwrap ( ) ;
507
+ let _ = ctx. register_batch ( "test2" , batch) ;
508
+
509
+ // Normally _row_id would be a name conflict
510
+ // But when it's a conflict between a metadata column and a non-metadata column, the non metadata column should be used
511
+ let select7 =
512
+ "SELECT id, other_id, _row_id FROM test INNER JOIN test2 ON id = other_id" ;
513
+ let df = ctx. sql ( select7) . await . unwrap ( ) ;
514
+ let batchs = df. collect ( ) . await . unwrap ( ) ;
515
+ #[ rustfmt:: skip]
516
+ let expected = [
517
+ "+----+----------+---------+" ,
518
+ "| id | other_id | _row_id |" ,
519
+ "+----+----------+---------+" ,
520
+ "| 1 | 1 | 10 |" ,
521
+ "| 2 | 2 | 11 |" ,
522
+ "| 3 | 3 | 12 |" ,
523
+ "+----+----------+---------+" ,
524
+ ] ;
525
+ assert_batches_sorted_eq ! ( expected, & batchs) ;
526
+
527
+ // Demonstrate that for other columns we get a conflict
528
+ let select7 =
529
+ "SELECT id, other_id, bank_account FROM test INNER JOIN test2 ON id = other_id" ;
530
+ assert ! ( ctx. sql( select7) . await . is_err( ) ) ;
494
531
}
0 commit comments