Skip to content

Commit

Permalink
handle bpchar
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipleblanc committed Oct 24, 2024
1 parent 2040d6b commit 8b67c8c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Many of the table providers in this repo are for querying data from other databa
Run the included examples to see how to use the table providers:

### DuckDB

```bash
# Read from a table in a DuckDB file
cargo run --example duckdb --features duckdb
Expand All @@ -29,6 +30,7 @@ cargo run --example duckdb_function --features duckdb
```

### SQLite

```bash
cargo run --example sqlite --features sqlite
```
Expand Down Expand Up @@ -82,6 +84,7 @@ cargo run --example mysql --features mysql
```

### Flight SQL

```bash
brew install roapi
# or
Expand Down
28 changes: 21 additions & 7 deletions src/sql/arrow_sql_gen/postgres/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ pub(crate) fn pg_data_type_to_arrow_type(
}
"real" | "float4" => Ok(DataType::Float32),
"double precision" | "float8" => Ok(DataType::Float64),
"character" | "char" | "character varying" | "varchar" | "text" => Ok(DataType::Utf8),
"character" | "char" | "character varying" | "varchar" | "text" | "bpchar" => {
Ok(DataType::Utf8)
}
"bytea" => Ok(DataType::Binary),
"date" => Ok(DataType::Date32),
"time" | "time without time zone" => Ok(DataType::Time64(TimeUnit::Nanosecond)),
Expand Down Expand Up @@ -244,11 +246,11 @@ mod tests {
// Test numeric types
assert_eq!(
pg_data_type_to_arrow_type("numeric", None).expect("Failed to convert numeric"),
DataType::Decimal128(38, 0)
DataType::Decimal128(38, 20)
);
assert_eq!(
pg_data_type_to_arrow_type("numeric()", None).expect("Failed to convert numeric()"),
DataType::Decimal128(38, 0)
DataType::Decimal128(38, 20)
);
assert_eq!(
pg_data_type_to_arrow_type("numeric(10,2)", None)
Expand Down Expand Up @@ -289,11 +291,11 @@ mod tests {
fn test_parse_numeric_type() {
assert_eq!(
parse_numeric_type("numeric").expect("Failed to parse numeric"),
(38, 0)
(38, 20)
);
assert_eq!(
parse_numeric_type("numeric()").expect("Failed to parse numeric()"),
(38, 0)
(38, 20)
);
assert_eq!(
parse_numeric_type("numeric(10)").expect("Failed to parse numeric(10)"),
Expand All @@ -305,11 +307,11 @@ mod tests {
);
assert_eq!(
parse_numeric_type("decimal").expect("Failed to parse decimal"),
(38, 0)
(38, 20)
);
assert_eq!(
parse_numeric_type("decimal()").expect("Failed to parse decimal()"),
(38, 0)
(38, 20)
);
assert_eq!(
parse_numeric_type("decimal(15)").expect("Failed to parse decimal(15)"),
Expand Down Expand Up @@ -449,6 +451,18 @@ mod tests {
pg_data_type_to_arrow_type("tsquery", None).expect("Failed to convert tsquery"),
DataType::LargeUtf8
);

// Test bpchar type
assert_eq!(
pg_data_type_to_arrow_type("bpchar", None).expect("Failed to convert bpchar"),
DataType::Utf8
);

// Test bpchar with length specification
assert_eq!(
pg_data_type_to_arrow_type("bpchar(10)", None).expect("Failed to convert bpchar(10)"),
DataType::Utf8
);
}

#[test]
Expand Down

0 comments on commit 8b67c8c

Please sign in to comment.