From df5d6854a502a8e7205cc168a812c48bada52295 Mon Sep 17 00:00:00 2001 From: kysshsy Date: Fri, 4 Oct 2024 19:28:44 +0800 Subject: [PATCH] test: add search path test comment: add test comment --- tests/fixtures/arrow.rs | 26 +++++++++++++++++++++++--- tests/scan.rs | 13 +++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/tests/fixtures/arrow.rs b/tests/fixtures/arrow.rs index fc88e50b..56578502 100644 --- a/tests/fixtures/arrow.rs +++ b/tests/fixtures/arrow.rs @@ -44,9 +44,12 @@ fn array_data() -> ArrayData { } fn single_array_data() -> ArrayData { + let values: [u8; 5] = *b"hello"; + let offsets: [i32; 2] = [0, 5]; ArrayData::builder(DataType::Binary) .len(1) - .add_buffer(Buffer::from("hello")) + .add_buffer(Buffer::from_slice_ref(&offsets[..])) + .add_buffer(Buffer::from_slice_ref(&values[..])) .build() .unwrap() } @@ -75,9 +78,12 @@ fn binary_array_data() -> ArrayData { } fn single_binary_array_data() -> ArrayData { - ArrayData::builder(DataType::Binary) + let values: [u8; 5] = *b"hello"; + let offsets: [i64; 2] = [0, 5]; + ArrayData::builder(DataType::LargeBinary) .len(1) - .add_buffer(Buffer::from("hello")) + .add_buffer(Buffer::from_slice_ref(&offsets[..])) + .add_buffer(Buffer::from_slice_ref(&values[..])) .build() .unwrap() } @@ -457,6 +463,20 @@ pub fn setup_local_file_listing_with_casing(local_file_path: &str, table: &str) ) } +pub fn setup_parquet_wrapper_and_server() -> String { + let create_foreign_data_wrapper = primitive_create_foreign_data_wrapper( + "parquet_wrapper", + "parquet_fdw_handler", + "parquet_fdw_validator", + ); + let create_server = primitive_create_server("parquet_server", "parquet_wrapper"); + format!( + "{create_foreign_data_wrapper}; + {create_server}; + " + ) +} + fn valid(data_type: &DataType, oid: u32) -> bool { let oid = match PgBuiltInOids::from_u32(oid) { Ok(oid) => oid, diff --git a/tests/scan.rs b/tests/scan.rs index 5a090fc2..bbe70e7e 100644 --- a/tests/scan.rs +++ b/tests/scan.rs @@ -22,7 +22,7 @@ use crate::fixtures::arrow::{ primitive_create_table, primitive_create_user_mapping_options, primitive_record_batch, primitive_record_batch_single, primitive_setup_fdw_local_file_delta, primitive_setup_fdw_local_file_listing, primitive_setup_fdw_s3_delta, - primitive_setup_fdw_s3_listing, + primitive_setup_fdw_s3_listing, setup_parquet_wrapper_and_server, }; use crate::fixtures::db::Query; use crate::fixtures::{conn, duckdb_conn, s3, tempdir, S3}; @@ -593,6 +593,11 @@ async fn test_prepare_stmt_execute(#[future(awt)] s3: S3, mut conn: PgConnection Ok(()) } +// Note: PostgreSQL will replan the query when certain catalog changes occur, +// such as changes to the search path or when a table is deleted. +// In contrast, DuckDB does not replan when the search path is changed. +// If there are two foreign tables in different schemas and the prepared statements do not specify the schemas, +// it may lead to ambiguity or errors when referencing the tables. #[rstest] async fn test_prepare_search_path(mut conn: PgConnection, tempdir: TempDir) -> Result<()> { let stored_batch = primitive_record_batch()?; @@ -612,9 +617,13 @@ async fn test_prepare_search_path(mut conn: PgConnection, tempdir: TempDir) -> R writer.write(&stored_batch_less)?; writer.close()?; + // In this example, we create two tables with identical structures and names, but in different schemas. + // We expect that when the search path is changed, the correct table (the one in the current schema) will be referenced in DuckDB. "CREATE SCHEMA tpch1".execute(&mut conn); "CREATE SCHEMA tpch2".execute(&mut conn); + setup_parquet_wrapper_and_server().execute(&mut conn); + let file_path = parquet_path.as_path().to_str().unwrap(); let file_less_path = less_parquet_path.as_path().to_str().unwrap(); @@ -626,7 +635,7 @@ async fn test_prepare_search_path(mut conn: PgConnection, tempdir: TempDir) -> R "SET search_path TO tpch1".execute(&mut conn); - "PREPARE q1 AS SELECT * FROM t1 where boolean_col = $1".execute(&mut conn); + "PREPARE q1 AS SELECT * FROM t1 WHERE boolean_col = $1".execute(&mut conn); let result: Vec<(bool,)> = "EXECUTE q1(true)".fetch_collect(&mut conn); assert_eq!(result.len(), 2);