Skip to content

Commit 0c15b12

Browse files
committed
Fix
1 parent 40b1124 commit 0c15b12

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
.direnv
33
.envrc
4+
.vscode

datafusion-postgres/src/encoder/list_encoder.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,26 @@ pub(crate) fn encode_list(
340340
},
341341
DataType::Struct(_) => {
342342
let fields = match type_.kind() {
343-
postgres_types::Kind::Composite(fields) => fields,
344-
_ => {
345-
return Err(Box::new(PgWireError::UserError(Box::new(ErrorInfo::new(
346-
"ERROR".to_owned(),
347-
"XX000".to_owned(),
348-
format!("Failed to unwrap a composite type from type {}", type_),
349-
)))))
350-
}
351-
};
343+
postgres_types::Kind::Array(struct_type_) => Ok(struct_type_),
344+
_ => Err(format!(
345+
"Expected list type found type {} of kind {:?}",
346+
type_,
347+
type_.kind()
348+
)),
349+
}
350+
.and_then(|struct_type| match struct_type.kind() {
351+
postgres_types::Kind::Composite(fields) => Ok(fields),
352+
_ => Err(format!(
353+
"Failed to unwrap a composite type inside from type {} kind {:?}",
354+
type_,
355+
type_.kind()
356+
)),
357+
})
358+
.map_err(|err| {
359+
let err = ErrorInfo::new("ERROR".to_owned(), "XX000".to_owned(), err);
360+
Box::new(PgWireError::UserError(Box::new(err)))
361+
})?;
362+
352363
let values: Result<Vec<_>, _> = (0..arr.len())
353364
.map(|row| encode_struct(&arr, row, fields, format))
354365
.collect();

datafusion-postgres/src/encoder/struct_encoder.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub fn encode_struct(
1818
return Ok(None);
1919
}
2020
let mut row_encoder = StructEncoder::new(fields.len());
21-
for arr in arr.columns() {
22-
let field = &fields[0];
21+
for (i, arr) in arr.columns().iter().enumerate() {
22+
let field = &fields[i];
2323
let type_ = field.type_();
2424
encode_value(&mut row_encoder, arr, idx, type_, format).unwrap();
2525
}
@@ -65,6 +65,11 @@ impl super::Encoder for StructEncoder {
6565
self.row_buffer.put_slice(b",");
6666
}
6767
} else {
68+
if self.curr_col == 0 && format == FieldFormat::Binary {
69+
// Place Number of fields
70+
self.row_buffer.put_i32(self.num_cols as i32);
71+
}
72+
6873
self.row_buffer.put_u32(data_type.oid());
6974
// remember the position of the 4-byte length field
7075
let prev_index = self.row_buffer.len();

0 commit comments

Comments
 (0)