From be5b863018c752938c05f437054da59ced35b86b Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Fri, 17 Jan 2025 09:58:30 -0500 Subject: [PATCH] Add tests for error --- datafusion/core/tests/dataframe/mod.rs | 66 +++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/datafusion/core/tests/dataframe/mod.rs b/datafusion/core/tests/dataframe/mod.rs index 15f4e55f35d8..851cd4d09a40 100644 --- a/datafusion/core/tests/dataframe/mod.rs +++ b/datafusion/core/tests/dataframe/mod.rs @@ -47,7 +47,7 @@ use datafusion::datasource::MemTable; use datafusion::error::Result; use datafusion::execution::context::SessionContext; use datafusion::execution::session_state::SessionStateBuilder; -use datafusion::prelude::JoinType; +use datafusion::prelude::{AvroReadOptions, JoinType, NdJsonReadOptions}; use datafusion::prelude::{CsvReadOptions, ParquetReadOptions}; use datafusion::test_util::{parquet_test_data, populate_csv_partitions}; use datafusion::{assert_batches_eq, assert_batches_sorted_eq}; @@ -2778,3 +2778,67 @@ async fn test_alias_nested() -> Result<()> { ); Ok(()) } + +#[tokio::test] +async fn register_non_json_file() { + let ctx = SessionContext::new(); + let err = ctx + .register_json( + "data", + "tests/data/test_binary.parquet", + NdJsonReadOptions::default(), + ) + .await; + assert_contains!( + err.unwrap_err().to_string(), + "test_binary.parquet' does not match the expected extension '.json'" + ); +} + +#[tokio::test] +async fn register_non_csv_file() { + let ctx = SessionContext::new(); + let err = ctx + .register_csv( + "data", + "tests/data/test_binary.parquet", + CsvReadOptions::default(), + ) + .await; + assert_contains!( + err.unwrap_err().to_string(), + "test_binary.parquet' does not match the expected extension '.csv'" + ); +} + +#[tokio::test] +async fn register_non_avro_file() { + let ctx = SessionContext::new(); + let err = ctx + .register_avro( + "data", + "tests/data/test_binary.parquet", + AvroReadOptions::default(), + ) + .await; + assert_contains!( + err.unwrap_err().to_string(), + "test_binary.parquet' does not match the expected extension '.avro'" + ); +} + +#[tokio::test] +async fn register_non_parquet_file() { + let ctx = SessionContext::new(); + let err = ctx + .register_parquet( + "data", + "tests/data/1.parquet", + ParquetReadOptions::default(), + ) + .await; + assert_contains!( + err.unwrap_err().to_string(), + "1.json' does not match the expected extension '.parquet'" + ); +}