Skip to content

Commit

Permalink
address
Browse files Browse the repository at this point in the history
  • Loading branch information
aykut-bozkurt committed Nov 22, 2024
1 parent b408fac commit ced1479
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 109 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ SELECT * FROM parquet.schema('/tmp/product_example.parquet') LIMIT 10;
/tmp/product_example.parquet | name | BYTE_ARRAY | | OPTIONAL | | UTF8 | | | 3 | STRING
/tmp/product_example.parquet | items | | | OPTIONAL | 1 | LIST | | | 4 | LIST
/tmp/product_example.parquet | list | | | REPEATED | 1 | | | | |
/tmp/product_example.parquet | items | | | OPTIONAL | 3 | | | | 5 |
/tmp/product_example.parquet | element | | | OPTIONAL | 3 | | | | 5 |
/tmp/product_example.parquet | id | INT32 | | OPTIONAL | | | | | 6 |
/tmp/product_example.parquet | name | BYTE_ARRAY | | OPTIONAL | | UTF8 | | | 7 | STRING
(10 rows)
Expand Down
26 changes: 14 additions & 12 deletions src/arrow_parquet/schema_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,16 @@ fn parse_list_schema(typoid: Oid, typmod: i32, array_name: &str, field_id: &mut

*field_id += 1;

let element_name = "element";

let elem_field = if is_composite_type(typoid) {
let tupledesc = tuple_desc(typoid, typmod);
parse_struct_schema(tupledesc, array_name, field_id)
parse_struct_schema(tupledesc, element_name, field_id)
} else if is_map_type(typoid) {
let base_elem_typoid = domain_array_base_elem_typoid(typoid);
parse_map_schema(base_elem_typoid, typmod, array_name, field_id)
parse_map_schema(base_elem_typoid, typmod, element_name, field_id)
} else {
parse_primitive_schema(typoid, typmod, array_name, field_id)
parse_primitive_schema(typoid, typmod, element_name, field_id)
};

let nullable = true;
Expand Down Expand Up @@ -292,17 +294,13 @@ fn parse_primitive_schema(
}

fn adjust_map_entries_field(field: FieldRef) -> FieldRef {
let name = field.deref().name();
let data_type = field.deref().data_type();
let metadata = field.deref().metadata().clone();

let not_nullable_key_field;
let nullable_value_field;

match data_type {
match field.deref().data_type() {
arrow::datatypes::DataType::Struct(fields) => {
let key_field = fields.find("key").expect("expected key field").1;
let value_field = fields.find("val").expect("expected val field").1;
let value_field = fields.find("val").expect("expected value field").1;

let key_nullable = false;

Expand All @@ -323,14 +321,18 @@ fn adjust_map_entries_field(field: FieldRef) -> FieldRef {
.with_metadata(value_field.metadata().clone());
}
_ => {
panic!("expected struct data type for map entries")
panic!("expected struct data type for map key_value field")
}
};

let entries_nullable = false;

let entries_name = "key_value";

let metadata = field.deref().metadata().clone();

let entries_field = Field::new(
name,
entries_name,
arrow::datatypes::DataType::Struct(Fields::from(vec![
not_nullable_key_field,
nullable_value_field,
Expand Down Expand Up @@ -392,7 +394,7 @@ pub(crate) fn ensure_arrow_schema_match_tupledesc_schema(
pgrx::PgLogLevel::ERROR,
PgSqlErrorCode::ERRCODE_CANNOT_COERCE,
type_mismatch_message,
"Try COPY FROM '..' WITH (cast_mode = 'relaxed') to allow lossy casts with runtime checks."
"Try COPY FROM '..' WITH (cast_mode 'relaxed') to allow lossy casts with runtime checks."
),
CoercionError::NoCoercionPath => ereport!(
pgrx::PgLogLevel::ERROR,
Expand Down
Loading

0 comments on commit ced1479

Please sign in to comment.