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 7fa0477
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 108 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
24 changes: 13 additions & 11 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)

Check warning on line 165 in src/arrow_parquet/schema_parser.rs

View check run for this annotation

Codecov / codecov/patch

src/arrow_parquet/schema_parser.rs#L165

Added line #L165 was not covered by tests
} 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,14 +294,10 @@ 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() {

Check warning on line 300 in src/arrow_parquet/schema_parser.rs

View check run for this annotation

Codecov / codecov/patch

src/arrow_parquet/schema_parser.rs#L300

Added line #L300 was not covered by tests
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;
Expand All @@ -323,14 +321,18 @@ fn adjust_map_entries_field(field: FieldRef) -> FieldRef {
.with_metadata(value_field.metadata().clone());

Check warning on line 321 in src/arrow_parquet/schema_parser.rs

View check run for this annotation

Codecov / codecov/patch

src/arrow_parquet/schema_parser.rs#L316-L321

Added lines #L316 - L321 were not covered by tests
}
_ => {
panic!("expected struct data type for map entries")
panic!("expected struct data type for map key_value field")

Check warning on line 324 in src/arrow_parquet/schema_parser.rs

View check run for this annotation

Codecov / codecov/patch

src/arrow_parquet/schema_parser.rs#L324

Added line #L324 was not covered by tests
}
};

let entries_nullable = false;

let entries_name = "key_value";

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

Check warning on line 333 in src/arrow_parquet/schema_parser.rs

View check run for this annotation

Codecov / codecov/patch

src/arrow_parquet/schema_parser.rs#L328-L333

Added lines #L328 - L333 were not covered by tests
let entries_field = Field::new(
name,
entries_name,

Check warning on line 335 in src/arrow_parquet/schema_parser.rs

View check run for this annotation

Codecov / codecov/patch

src/arrow_parquet/schema_parser.rs#L335

Added line #L335 was not covered by tests
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 7fa0477

Please sign in to comment.