Skip to content

Commit

Permalink
rename functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rebasedming committed Jul 31, 2024
1 parent 1ee00b8 commit f625a25
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
16 changes: 8 additions & 8 deletions src/duckdb/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,25 @@ fn get_global_arrow() -> &'static UnsafeCell<Option<duckdb::Arrow<'static>>> {
unsafe { GLOBAL_ARROW.as_ref().expect("Arrow not initialized") }
}

pub fn create_csv_view(
pub fn create_csv_relation(
table_name: &str,
schema_name: &str,
table_options: HashMap<String, String>,
) -> Result<usize> {
let statement = csv::create_view(table_name, schema_name, table_options)?;
let statement = csv::create_duckdb_relation(table_name, schema_name, table_options)?;
execute(statement.as_str(), [])
}

pub fn create_delta_view(
pub fn create_delta_relation(
table_name: &str,
schema_name: &str,
table_options: HashMap<String, String>,
) -> Result<usize> {
let statement = delta::create_view(table_name, schema_name, table_options)?;
let statement = delta::create_duckdb_relation(table_name, schema_name, table_options)?;
execute(statement.as_str(), [])
}

pub fn create_iceberg_view(
pub fn create_iceberg_relation(
table_name: &str,
schema_name: &str,
table_options: HashMap<String, String>,
Expand All @@ -136,16 +136,16 @@ pub fn create_iceberg_view(
execute("LOAD iceberg", [])?;
}

let statement = iceberg::create_view(table_name, schema_name, table_options)?;
let statement = iceberg::create_duckdb_relation(table_name, schema_name, table_options)?;
execute(statement.as_str(), [])
}

pub fn create_parquet_view(
pub fn create_parquet_relation(
table_name: &str,
schema_name: &str,
table_options: HashMap<String, String>,
) -> Result<usize> {
let statement = parquet::create_view(table_name, schema_name, table_options)?;
let statement = parquet::create_duckdb_relation(table_name, schema_name, table_options)?;
execute(statement.as_str(), [])
}

Expand Down
14 changes: 7 additions & 7 deletions src/duckdb/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl CsvOption {
}
}

pub fn create_view(
pub fn create_duckdb_relation(
table_name: &str,
schema_name: &str,
table_options: HashMap<String, String>,
Expand Down Expand Up @@ -367,7 +367,7 @@ mod tests {
use duckdb::Connection;

#[test]
fn test_create_csv_view_single_file() {
fn test_create_csv_relation_single_file() {
let table_name = "test";
let schema_name = "main";
let table_options = HashMap::from([(
Expand All @@ -376,7 +376,7 @@ mod tests {
)]);
let expected =
"CREATE VIEW IF NOT EXISTS main.test AS SELECT * FROM read_csv('/data/file.csv')";
let actual = create_view(table_name, schema_name, table_options).unwrap();
let actual = create_duckdb_relation(table_name, schema_name, table_options).unwrap();

assert_eq!(expected, actual);

Expand All @@ -388,7 +388,7 @@ mod tests {
}

#[test]
fn test_create_csv_view_multiple_files() {
fn test_create_csv_relation_multiple_files() {
let table_name = "test";
let schema_name = "main";
let table_options = HashMap::from([(
Expand All @@ -397,7 +397,7 @@ mod tests {
)]);

let expected = "CREATE VIEW IF NOT EXISTS main.test AS SELECT * FROM read_csv(['/data/file1.csv', '/data/file2.csv'])";
let actual = create_view(table_name, schema_name, table_options).unwrap();
let actual = create_duckdb_relation(table_name, schema_name, table_options).unwrap();

assert_eq!(expected, actual);

Expand All @@ -409,7 +409,7 @@ mod tests {
}

#[test]
fn test_create_csv_view_with_options() {
fn test_create_csv_relation_with_options() {
let table_name = "test";
let schema_name = "main";
let table_options = HashMap::from([
Expand Down Expand Up @@ -517,7 +517,7 @@ mod tests {
]);

let expected = "CREATE VIEW IF NOT EXISTS main.test AS SELECT * FROM read_csv('/data/file.csv', all_varchar = true, allow_quoted_nulls = true, auto_detect = true, auto_type_candidates = ['BIGINT', 'DATE'], columns = {'col1': 'INTEGER', 'col2': 'VARCHAR'}, compression = 'gzip', dateformat = '%d/%m/%Y', decimal_separator = '.', delim = ',', escape = '\"', filename = true, force_not_null = ['col1', 'col2'], header = true, hive_partitioning = true, hive_types = true, hive_types_autocast = true, ignore_errors = true, max_line_size = 1000, names = ['col1', 'col2'], new_line = '\n', normalize_names = true, null_padding = true, nullstr = ['none', 'null'], parallel = true, quote = '\"', sample_size = 100, sep = ',', skip = 0, timestampformat = 'yyyy-MM-dd HH:mm:ss', types = ['BIGINT', 'VARCHAR'], union_by_name = true)";
let actual = create_view(table_name, schema_name, table_options).unwrap();
let actual = create_duckdb_relation(table_name, schema_name, table_options).unwrap();

assert_eq!(expected, actual);

Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl DeltaOption {
}
}

pub fn create_view(
pub fn create_duckdb_relation(
table_name: &str,
schema_name: &str,
table_options: HashMap<String, String>,
Expand Down Expand Up @@ -76,7 +76,7 @@ mod tests {
use duckdb::Connection;

#[test]
fn test_create_delta_view() {
fn test_create_delta_relation() {
let table_name = "test";
let schema_name = "main";
let table_options = HashMap::from([(
Expand All @@ -86,7 +86,7 @@ mod tests {

let expected =
"CREATE VIEW IF NOT EXISTS main.test AS SELECT * FROM delta_scan('/data/delta')";
let actual = create_view(table_name, schema_name, table_options).unwrap();
let actual = create_duckdb_relation(table_name, schema_name, table_options).unwrap();

assert_eq!(expected, actual);

Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/iceberg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl IcebergOption {
}
}

pub fn create_view(
pub fn create_duckdb_relation(
table_name: &str,
schema_name: &str,
table_options: HashMap<String, String>,
Expand Down Expand Up @@ -93,7 +93,7 @@ mod tests {
use duckdb::Connection;

#[test]
fn test_create_iceberg_view() {
fn test_create_iceberg_relation() {
let table_name = "test";
let schema_name = "main";
let table_options = HashMap::from([(
Expand All @@ -103,7 +103,7 @@ mod tests {

let expected =
"CREATE VIEW IF NOT EXISTS main.test AS SELECT * FROM iceberg_scan('/data/iceberg')";
let actual = create_view(table_name, schema_name, table_options).unwrap();
let actual = create_duckdb_relation(table_name, schema_name, table_options).unwrap();

assert_eq!(expected, actual);

Expand Down
14 changes: 7 additions & 7 deletions src/duckdb/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl ParquetOption {
}
}

pub fn create_view(
pub fn create_duckdb_relation(
table_name: &str,
schema_name: &str,
table_options: HashMap<String, String>,
Expand Down Expand Up @@ -152,14 +152,14 @@ mod tests {
use duckdb::Connection;

#[test]
fn test_create_parquet_view_single_file() {
fn test_create_parquet_relation_single_file() {
let table_name = "test";
let schema_name = "main";
let files = "/data/file.parquet";
let table_options =
HashMap::from([(ParquetOption::Files.as_str().to_string(), files.to_string())]);
let expected = "CREATE VIEW IF NOT EXISTS main.test AS SELECT * FROM read_parquet('/data/file.parquet')";
let actual = create_view(table_name, schema_name, table_options).unwrap();
let actual = create_duckdb_relation(table_name, schema_name, table_options).unwrap();

assert_eq!(expected, actual);

Expand All @@ -171,15 +171,15 @@ mod tests {
}

#[test]
fn test_create_parquet_view_multiple_files() {
fn test_create_parquet_relation_multiple_files() {
let table_name = "test";
let schema_name = "main";
let files = "/data/file1.parquet, /data/file2.parquet";
let table_options =
HashMap::from([(ParquetOption::Files.as_str().to_string(), files.to_string())]);

let expected = "CREATE VIEW IF NOT EXISTS main.test AS SELECT * FROM read_parquet(['/data/file1.parquet', '/data/file2.parquet'])";
let actual = create_view(table_name, schema_name, table_options).unwrap();
let actual = create_duckdb_relation(table_name, schema_name, table_options).unwrap();

assert_eq!(expected, actual);

Expand All @@ -191,7 +191,7 @@ mod tests {
}

#[test]
fn test_create_parquet_view_with_options() {
fn test_create_parquet_relation_with_options() {
let table_name = "test";
let schema_name = "main";
let table_options = HashMap::from([
Expand Down Expand Up @@ -230,7 +230,7 @@ mod tests {
]);

let expected = "CREATE VIEW IF NOT EXISTS main.test AS SELECT * FROM read_parquet('/data/file.parquet', binary_as_string = true, filename = false, file_row_number = true, hive_partitioning = true, hive_types = {'release': DATE, 'orders': BIGINT}, hive_types_autocast = true, union_by_name = true)";
let actual = create_view(table_name, schema_name, table_options).unwrap();
let actual = create_duckdb_relation(table_name, schema_name, table_options).unwrap();

assert_eq!(expected, actual);

Expand Down
15 changes: 7 additions & 8 deletions src/fdw/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ unsafe fn auto_create_schema_impl(fcinfo: pg_sys::FunctionCallInfo) -> Result<()
);
}

// Drop stale view
// Drop stale relation
connection::drop_relation(table_name, schema_name)?;

// Create DuckDB secrets
Expand All @@ -131,7 +131,7 @@ unsafe fn auto_create_schema_impl(fcinfo: pg_sys::FunctionCallInfo) -> Result<()
// Create DuckDB relation
let table_options = unsafe { options_to_hashmap((*foreign_table).options)? };
let handler = FdwHandler::from(foreign_table);
register_duckdb_view(table_name, schema_name, table_options.clone(), handler)?;
create_duckdb_relation(table_name, schema_name, table_options.clone(), handler)?;

// If the table already has columns, no need for auto schema creation
let relation = pg_sys::relation_open(oid, pg_sys::AccessShareLock as i32);
Expand Down Expand Up @@ -255,30 +255,29 @@ fn construct_alter_table_statement(
}

#[inline]
pub fn register_duckdb_view(
pub fn create_duckdb_relation(
table_name: &str,
schema_name: &str,
table_options: HashMap<String, String>,
handler: FdwHandler,
) -> Result<()> {
// Initialize DuckDB view
connection::execute(
format!("CREATE SCHEMA IF NOT EXISTS {schema_name}").as_str(),
[],
)?;

match handler {
FdwHandler::Csv => {
connection::create_csv_view(table_name, schema_name, table_options)?;
connection::create_csv_relation(table_name, schema_name, table_options)?;
}
FdwHandler::Delta => {
connection::create_delta_view(table_name, schema_name, table_options)?;
connection::create_delta_relation(table_name, schema_name, table_options)?;
}
FdwHandler::Iceberg => {
connection::create_iceberg_view(table_name, schema_name, table_options)?;
connection::create_iceberg_relation(table_name, schema_name, table_options)?;
}
FdwHandler::Parquet => {
connection::create_parquet_view(table_name, schema_name, table_options)?;
connection::create_parquet_relation(table_name, schema_name, table_options)?;
}
_ => {
bail!("got unexpected fdw_handler")
Expand Down

0 comments on commit f625a25

Please sign in to comment.