Skip to content

Commit 40b1124

Browse files
committed
Revert "Use psuedo type for composite"
This reverts commit 4313e41.
1 parent 4313e41 commit 40b1124

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

datafusion-postgres/src/datatypes.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use pgwire::api::results::{FieldInfo, QueryResponse};
1414
use pgwire::api::Type;
1515
use pgwire::error::{ErrorInfo, PgWireError, PgWireResult};
1616
use pgwire::messages::data::DataRow;
17+
use postgres_types::Kind;
1718
use rust_decimal::prelude::ToPrimitive;
1819
use rust_decimal::Decimal;
1920

@@ -65,10 +66,10 @@ pub(crate) fn into_pg_type(df_type: &DataType) -> PgWireResult<Type> {
6566
DataType::Float64 => Type::FLOAT8_ARRAY,
6667
DataType::Utf8 => Type::VARCHAR_ARRAY,
6768
DataType::LargeUtf8 => Type::TEXT_ARRAY,
68-
DataType::Struct(_) => Type::new(
69+
struct_type @ DataType::Struct(_) => Type::new(
6970
Type::RECORD_ARRAY.name().into(),
7071
Type::RECORD_ARRAY.oid(),
71-
Type::RECORD_ARRAY.kind().clone(),
72+
Kind::Array(into_pg_type(struct_type)?),
7273
Type::RECORD_ARRAY.schema().into(),
7374
),
7475
list_type => {
@@ -89,12 +90,16 @@ pub(crate) fn into_pg_type(df_type: &DataType) -> PgWireResult<Type> {
8990
.reduce(|a, b| a + ", " + &b)
9091
.map(|x| format!("({x})"))
9192
.unwrap_or("()".to_string());
92-
Type::new(
93-
name,
94-
Type::RECORD.oid(),
95-
Type::RECORD.kind().clone(),
96-
Type::RECORD.schema().into(),
97-
)
93+
let kind = Kind::Composite(
94+
fields
95+
.iter()
96+
.map(|x| {
97+
into_pg_type(x.data_type())
98+
.map(|_type| postgres_types::Field::new(x.name().clone(), _type))
99+
})
100+
.collect::<Result<Vec<_>, PgWireError>>()?,
101+
);
102+
Type::new(name, Type::RECORD.oid(), kind, Type::RECORD.schema().into())
98103
}
99104
_ => {
100105
return Err(PgWireError::UserError(Box::new(ErrorInfo::new(

0 commit comments

Comments
 (0)