Skip to content

Commit

Permalink
test: add a test of creating a foreign table with reserved column name (
Browse files Browse the repository at this point in the history
#182)

* fix: reserved column name in auto create schema

* fix: remove code change and fix test
  • Loading branch information
kysshsy authored Dec 15, 2024
1 parent ad3d5b6 commit ae0cc16
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
40 changes: 40 additions & 0 deletions tests/tests/fixtures/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,46 @@ pub fn primitive_record_batch_single() -> Result<RecordBatch> {
)?)
}

pub fn reserved_column_record_batch() -> Result<RecordBatch> {
// authorization is a reserved column name
let fields = vec![
Field::new("id", DataType::Utf8, false),
Field::new("operation_id", DataType::Utf8, false),
Field::new("order_id", DataType::Utf8, false),
Field::new("dealer_id", DataType::Utf8, false),
Field::new("dealer_name", DataType::Utf8, false),
Field::new("authorization", DataType::Utf8, false),
Field::new("on_day", DataType::Boolean, false),
];

let schema = Arc::new(Schema::new(fields));

Ok(RecordBatch::try_new(
schema,
vec![
Arc::new(StringArray::from(vec![Some("1"), Some("2"), Some("3")])),
Arc::new(StringArray::from(vec![Some("1"), Some("2"), Some("3")])),
Arc::new(StringArray::from(vec![Some("1"), Some("2"), Some("3")])),
Arc::new(StringArray::from(vec![Some("1"), Some("2"), Some("3")])),
Arc::new(StringArray::from(vec![
Some("Jason"),
Some("Alice"),
Some("Bob"),
])),
Arc::new(StringArray::from(vec![
Some("auth_1"),
Some("auth_2"),
Some("auth_3"),
])),
Arc::new(BooleanArray::from(vec![
Some(true),
Some(false),
Some(true),
])),
],
)?)
}

pub fn primitive_create_foreign_data_wrapper(
wrapper: &str,
handler: &str,
Expand Down
30 changes: 29 additions & 1 deletion tests/tests/table_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ mod fixtures;

use crate::fixtures::arrow::{
primitive_record_batch, primitive_setup_fdw_local_file_listing, record_batch_with_casing,
setup_local_file_listing_with_casing,
reserved_column_record_batch, setup_local_file_listing_with_casing,
setup_parquet_wrapper_and_server,
};
use crate::fixtures::db::Query;
use crate::fixtures::{conn, tempdir};
Expand Down Expand Up @@ -91,6 +92,33 @@ async fn test_reserved_table_name(mut conn: PgConnection, tempdir: TempDir) -> R
Ok(())
}

#[rstest]
fn test_reserved_column_name(mut conn: PgConnection, tempdir: TempDir) -> Result<()> {
let stored_batch = reserved_column_record_batch()?;
let parquet_path = tempdir.path().join("reserved_column_table.parquet");
let parquet_file = File::create(&parquet_path).unwrap();

let mut writer = ArrowWriter::try_new(parquet_file, stored_batch.schema(), None).unwrap();
writer.write(&stored_batch)?;
writer.close()?;

setup_parquet_wrapper_and_server().execute(&mut conn);

match format!(
"CREATE FOREIGN TABLE reserved_table_name () SERVER parquet_server OPTIONS (files '{}', preserve_casing 'true')",
parquet_path.to_str().unwrap()
)
.execute_result(&mut conn)
{
Ok(_) => {}
Err(e) => {
panic!("fail to create table with reserved column name: {}", e)
}
}

Ok(())
}

#[rstest]
async fn test_invalid_file(mut conn: PgConnection) -> Result<()> {
match primitive_setup_fdw_local_file_listing("invalid_file.parquet", "primitive")
Expand Down

0 comments on commit ae0cc16

Please sign in to comment.