Skip to content

Commit f392b09

Browse files
authored
feat: support oid & name type for postgres (datafusion-contrib#204)
1 parent 00a2af6 commit f392b09

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/sql/arrow_sql_gen/postgres.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ pub fn rows_to_arrow(rows: &[Row], projected_schema: &Option<SchemaRef>) -> Resu
255255
Type::INT8 => {
256256
handle_primitive_type!(builder, Type::INT8, Int64Builder, i64, row, i);
257257
}
258+
Type::OID => {
259+
handle_primitive_type!(builder, Type::OID, UInt32Builder, u32, row, i);
260+
}
258261
Type::FLOAT4 => {
259262
handle_primitive_type!(builder, Type::FLOAT4, Float32Builder, f32, row, i);
260263
}
@@ -267,6 +270,9 @@ pub fn rows_to_arrow(rows: &[Row], projected_schema: &Option<SchemaRef>) -> Resu
267270
Type::VARCHAR => {
268271
handle_primitive_type!(builder, Type::VARCHAR, StringBuilder, &str, row, i);
269272
}
273+
Type::NAME => {
274+
handle_primitive_type!(builder, Type::NAME, StringBuilder, &str, row, i);
275+
}
270276
Type::BYTEA => {
271277
handle_primitive_type!(builder, Type::BYTEA, BinaryBuilder, Vec<u8>, row, i);
272278
}
@@ -835,9 +841,10 @@ fn map_column_type_to_data_type(column_type: &Type) -> Option<DataType> {
835841
Type::INT2 => Some(DataType::Int16),
836842
Type::INT4 => Some(DataType::Int32),
837843
Type::INT8 | Type::MONEY => Some(DataType::Int64),
844+
Type::OID => Some(DataType::UInt32),
838845
Type::FLOAT4 => Some(DataType::Float32),
839846
Type::FLOAT8 => Some(DataType::Float64),
840-
Type::TEXT | Type::VARCHAR | Type::BPCHAR | Type::UUID => Some(DataType::Utf8),
847+
Type::TEXT | Type::VARCHAR | Type::BPCHAR | Type::UUID | Type::NAME => Some(DataType::Utf8),
841848
Type::BYTEA => Some(DataType::Binary),
842849
Type::BOOL => Some(DataType::Boolean),
843850
Type::JSON => Some(DataType::LargeUtf8),

src/sql/arrow_sql_gen/postgres/schema.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ pub(crate) fn pg_data_type_to_arrow_type(
1414
"smallint" => Ok(DataType::Int16),
1515
"integer" | "int" | "int4" => Ok(DataType::Int32),
1616
"bigint" | "int8" | "money" => Ok(DataType::Int64),
17+
"oid" => Ok(DataType::UInt32),
1718
"numeric" | "decimal" => {
1819
let (precision, scale) = parse_numeric_type(pg_type)?;
1920
Ok(DataType::Decimal128(precision, scale))
2021
}
2122
"real" | "float4" => Ok(DataType::Float32),
2223
"double precision" | "float8" => Ok(DataType::Float64),
23-
"character" | "char" | "character varying" | "varchar" | "text" | "bpchar" | "uuid" => {
24-
Ok(DataType::Utf8)
25-
}
24+
"character" | "char" | "character varying" | "varchar" | "text" | "bpchar" | "uuid"
25+
| "name" => Ok(DataType::Utf8),
2626
"bytea" => Ok(DataType::Binary),
2727
"date" => Ok(DataType::Date32),
2828
"time" | "time without time zone" => Ok(DataType::Time64(TimeUnit::Nanosecond)),
@@ -196,6 +196,10 @@ mod tests {
196196
pg_data_type_to_arrow_type("bigint", None).expect("Failed to convert bigint"),
197197
DataType::Int64
198198
);
199+
assert_eq!(
200+
pg_data_type_to_arrow_type("oid", None).expect("Failed to convert oid"),
201+
DataType::UInt32
202+
);
199203
assert_eq!(
200204
pg_data_type_to_arrow_type("real", None).expect("Failed to convert real"),
201205
DataType::Float32
@@ -224,6 +228,10 @@ mod tests {
224228
pg_data_type_to_arrow_type("text", None).expect("Failed to convert text"),
225229
DataType::Utf8
226230
);
231+
assert_eq!(
232+
pg_data_type_to_arrow_type("name", None).expect("Failed to convert name"),
233+
DataType::Utf8
234+
);
227235

228236
// Test date/time types
229237
assert_eq!(

0 commit comments

Comments
 (0)