Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions arrow-pg/src/datatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ pub fn into_pg_type(arrow_type: &DataType) -> PgWireResult<Type> {
DataType::Time32(_) | DataType::Time64(_) => Type::TIME,
DataType::Date32 | DataType::Date64 => Type::DATE,
DataType::Interval(_) => Type::INTERVAL,
DataType::Binary | DataType::FixedSizeBinary(_) | DataType::LargeBinary => Type::BYTEA,
DataType::Binary
| DataType::FixedSizeBinary(_)
| DataType::LargeBinary
| DataType::BinaryView => Type::BYTEA,
DataType::Float16 | DataType::Float32 => Type::FLOAT4,
DataType::Float64 => Type::FLOAT8,
DataType::Decimal128(_, _) => Type::NUMERIC,
DataType::Utf8 => Type::VARCHAR,
DataType::LargeUtf8 => Type::TEXT,
DataType::LargeUtf8 | DataType::Utf8View => Type::TEXT,
DataType::List(field) | DataType::FixedSizeList(field, _) | DataType::LargeList(field) => {
match field.data_type() {
DataType::Boolean => Type::BOOL_ARRAY,
Expand All @@ -58,11 +61,14 @@ pub fn into_pg_type(arrow_type: &DataType) -> PgWireResult<Type> {
DataType::Time32(_) | DataType::Time64(_) => Type::TIME_ARRAY,
DataType::Date32 | DataType::Date64 => Type::DATE_ARRAY,
DataType::Interval(_) => Type::INTERVAL_ARRAY,
DataType::FixedSizeBinary(_) | DataType::Binary => Type::BYTEA_ARRAY,
DataType::FixedSizeBinary(_)
| DataType::Binary
| DataType::LargeBinary
| DataType::BinaryView => Type::BYTEA_ARRAY,
DataType::Float16 | DataType::Float32 => Type::FLOAT4_ARRAY,
DataType::Float64 => Type::FLOAT8_ARRAY,
DataType::Utf8 => Type::VARCHAR_ARRAY,
DataType::LargeUtf8 => Type::TEXT_ARRAY,
DataType::LargeUtf8 | DataType::Utf8View => Type::TEXT_ARRAY,
struct_type @ DataType::Struct(_) => Type::new(
Type::RECORD_ARRAY.name().into(),
Type::RECORD_ARRAY.oid(),
Expand All @@ -78,7 +84,6 @@ pub fn into_pg_type(arrow_type: &DataType) -> PgWireResult<Type> {
}
}
}
DataType::Utf8View => Type::TEXT,
DataType::Dictionary(_, value_type) => into_pg_type(value_type)?,
DataType::Struct(fields) => {
let name: String = fields
Expand Down
27 changes: 22 additions & 5 deletions arrow-pg/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ fn get_utf8_view_value(arr: &Arc<dyn Array>, idx: usize) -> Option<&str> {
})
}

fn get_binary_view_value(arr: &Arc<dyn Array>, idx: usize) -> Option<&[u8]> {
(!arr.is_null(idx)).then(|| {
arr.as_any()
.downcast_ref::<BinaryViewArray>()
.unwrap()
.value(idx)
})
}

fn get_utf8_value(arr: &Arc<dyn Array>, idx: usize) -> Option<&str> {
(!arr.is_null(idx)).then(|| {
arr.as_any()
Expand All @@ -161,12 +170,15 @@ fn get_large_utf8_value(arr: &Arc<dyn Array>, idx: usize) -> Option<&str> {
})
}

fn get_binary_value(arr: &Arc<dyn Array>, idx: usize) -> Option<&[u8]> {
fn get_binary_value(arr: &Arc<dyn Array>, idx: usize) -> Option<String> {
(!arr.is_null(idx)).then(|| {
arr.as_any()
.downcast_ref::<BinaryArray>()
.unwrap()
.value(idx)
String::from_utf8_lossy(
arr.as_any()
.downcast_ref::<BinaryArray>()
.unwrap()
.value(idx),
)
.to_string()
})
}

Expand Down Expand Up @@ -330,6 +342,11 @@ pub fn encode_value<T: Encoder>(
type_,
format,
)?,
DataType::BinaryView => encoder.encode_field_with_type_and_format(
&get_binary_view_value(arr, idx),
type_,
format,
)?,
DataType::LargeUtf8 => encoder.encode_field_with_type_and_format(
&get_large_utf8_value(arr, idx),
type_,
Expand Down
Loading