Skip to content

Commit

Permalink
add table casing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rebasedming committed Jul 31, 2024
1 parent 099e394 commit d446a2e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/fdw/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ fn construct_alter_table_statement(

format!(
"ALTER TABLE {} {}",
table_name,
spi::quote_identifier(table_name),
column_definitions.join(", ")
)
}
Expand Down
26 changes: 25 additions & 1 deletion tests/table_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async fn test_recreated_view(mut conn: PgConnection, tempdir: TempDir) -> Result
}

#[rstest]
async fn test_preserve_casing(mut conn: PgConnection, tempdir: TempDir) -> Result<()> {
async fn test_preserve_casing_column_name(mut conn: PgConnection, tempdir: TempDir) -> Result<()> {
let stored_batch = record_batch_with_casing()?;
let parquet_path = tempdir.path().join("test_casing.parquet");
let parquet_file = File::create(&parquet_path)?;
Expand All @@ -148,3 +148,27 @@ async fn test_preserve_casing(mut conn: PgConnection, tempdir: TempDir) -> Resul

Ok(())
}

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

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

primitive_setup_fdw_local_file_listing(parquet_path.as_path().to_str().unwrap(), "MyTable")
.execute(&mut conn);

format!(
r#"CREATE FOREIGN TABLE "PrimitiveTable" () SERVER parquet_server OPTIONS (files '{}', preserve_casing 'true')"#,
parquet_path.to_str().unwrap()
).execute(&mut conn);

let count: (i64,) = r#"SELECT COUNT(*) FROM "PrimitiveTable" LIMIT 1"#.fetch_one(&mut conn);
assert_eq!(count.0, 3);

Ok(())
}

0 comments on commit d446a2e

Please sign in to comment.