@@ -54,8 +54,9 @@ use datafusion::error::Result;
5454use datafusion:: execution:: context:: SessionContext ;
5555use datafusion:: execution:: session_state:: SessionStateBuilder ;
5656use datafusion:: logical_expr:: { ColumnarValue , Volatility } ;
57- use datafusion:: prelude:: { CsvReadOptions , ParquetReadOptions } ;
58- use datafusion:: prelude:: { JoinType , NdJsonReadOptions } ;
57+ use datafusion:: prelude:: {
58+ AvroReadOptions , CsvReadOptions , JoinType , NdJsonReadOptions , ParquetReadOptions ,
59+ } ;
5960use datafusion:: test_util:: {
6061 parquet_test_data, populate_csv_partitions, register_aggregate_csv, test_table,
6162 test_table_with_name,
@@ -5121,3 +5122,63 @@ async fn test_alias_nested() -> Result<()> {
51215122 ) ;
51225123 Ok ( ( ) )
51235124}
5125+
5126+ #[ tokio:: test]
5127+ async fn register_non_json_file ( ) {
5128+ let ctx = SessionContext :: new ( ) ;
5129+ let err = ctx
5130+ . register_json (
5131+ "data" ,
5132+ "tests/data/test_binary.parquet" ,
5133+ NdJsonReadOptions :: default ( ) ,
5134+ )
5135+ . await ;
5136+ assert_contains ! (
5137+ err. unwrap_err( ) . to_string( ) ,
5138+ "test_binary.parquet' does not match the expected extension '.json'"
5139+ ) ;
5140+ }
5141+
5142+ #[ tokio:: test]
5143+ async fn register_non_csv_file ( ) {
5144+ let ctx = SessionContext :: new ( ) ;
5145+ let err = ctx
5146+ . register_csv (
5147+ "data" ,
5148+ "tests/data/test_binary.parquet" ,
5149+ CsvReadOptions :: default ( ) ,
5150+ )
5151+ . await ;
5152+ assert_contains ! (
5153+ err. unwrap_err( ) . to_string( ) ,
5154+ "test_binary.parquet' does not match the expected extension '.csv'"
5155+ ) ;
5156+ }
5157+
5158+ #[ tokio:: test]
5159+ async fn register_non_avro_file ( ) {
5160+ let ctx = SessionContext :: new ( ) ;
5161+ let err = ctx
5162+ . register_avro (
5163+ "data" ,
5164+ "tests/data/test_binary.parquet" ,
5165+ AvroReadOptions :: default ( ) ,
5166+ )
5167+ . await ;
5168+ assert_contains ! (
5169+ err. unwrap_err( ) . to_string( ) ,
5170+ "test_binary.parquet' does not match the expected extension '.avro'"
5171+ ) ;
5172+ }
5173+
5174+ #[ tokio:: test]
5175+ async fn register_non_parquet_file ( ) {
5176+ let ctx = SessionContext :: new ( ) ;
5177+ let err = ctx
5178+ . register_parquet ( "data" , "tests/data/1.json" , ParquetReadOptions :: default ( ) )
5179+ . await ;
5180+ assert_contains ! (
5181+ err. unwrap_err( ) . to_string( ) ,
5182+ "1.json' does not match the expected extension '.parquet'"
5183+ ) ;
5184+ }
0 commit comments