Skip to content

Commit 901c8ab

Browse files
authored
Fix handling JSON type when reading FlatGeobuf (#901)
Closes #821
1 parent 29d3491 commit 901c8ab

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

fixtures/flatgeobuf/alldatatypes.fgb

880 Bytes
Binary file not shown.

rust/geoarrow/src/io/flatgeobuf/reader/sync.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -189,29 +189,32 @@ mod test {
189189
));
190190
}
191191

192-
#[ignore = "fails on JSON columns"]
193192
#[test]
194193
fn test_all_datatypes() {
195194
let mut filein =
196195
BufReader::new(File::open("fixtures/flatgeobuf/alldatatypes.fgb").unwrap());
197196
let table = read_flatgeobuf(&mut filein, Default::default()).unwrap();
198197

199-
let _geom_col = table.geometry_column(None).unwrap();
200-
// assert!(matches!(geom_col.data_type(), NativeType::Polygon(_, _)));
201-
202-
// let (batches, schema) = table.into_inner();
203-
// assert_eq!(batches[0].num_rows(), 10);
204-
// assert!(matches!(
205-
// schema.field_with_name("AREA").unwrap().data_type(),
206-
// DataType::Float64
207-
// ));
208-
// assert!(matches!(
209-
// schema.field_with_name("EAS_ID").unwrap().data_type(),
210-
// DataType::Int64
211-
// ));
212-
// assert!(matches!(
213-
// schema.field_with_name("PRFEDEA").unwrap().data_type(),
214-
// DataType::Utf8
215-
// ));
198+
let geom_col = table.geometry_column(None).unwrap();
199+
assert!(matches!(geom_col.data_type(), NativeType::Point(_, _)));
200+
201+
let (batches, schema) = table.into_inner();
202+
assert_eq!(batches[0].num_rows(), 1);
203+
assert!(matches!(
204+
schema.field_with_name("byte").unwrap().data_type(),
205+
DataType::Int8
206+
));
207+
assert!(matches!(
208+
schema.field_with_name("float").unwrap().data_type(),
209+
DataType::Float32
210+
));
211+
assert!(matches!(
212+
schema.field_with_name("json").unwrap().data_type(),
213+
DataType::Utf8
214+
));
215+
assert!(matches!(
216+
schema.field_with_name("binary").unwrap().data_type(),
217+
DataType::Binary
218+
));
216219
}
217220
}

rust/geoarrow/src/io/geozero/table/builder/anyvalue.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,17 @@ impl AnyBuilder {
125125
}
126126
}
127127

128-
pub fn from_data_type_with_capacity(data_type: &DataType, capacity: usize) -> Self {
128+
pub fn from_field_with_capacity(field: &Field, capacity: usize) -> Self {
129129
use AnyBuilder::*;
130-
match data_type {
130+
131+
// Short circuit check for JSON type
132+
if let Some(ext_val) = field.metadata().get("ARROW:extension:name") {
133+
if ext_val.as_str() == "arrow.json" {
134+
return Json(StringBuilder::with_capacity(capacity, 0));
135+
}
136+
}
137+
138+
match field.data_type() {
131139
DataType::Boolean => Bool(BooleanBuilder::with_capacity(capacity)),
132140
DataType::Int8 => Int8(Int8Builder::with_capacity(capacity)),
133141
DataType::UInt8 => Uint8(UInt8Builder::with_capacity(capacity)),
@@ -146,7 +154,7 @@ impl AnyBuilder {
146154
TimestampMicrosecondBuilder::with_capacity(capacity),
147155
tz.clone(),
148156
)),
149-
_ => todo!("Unsupported type {data_type}"),
157+
_ => todo!("Unsupported type {}", field.data_type()),
150158
}
151159
}
152160

rust/geoarrow/src/io/geozero/table/builder/properties.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl PropertiesBatchBuilder {
9898
for field in schema.fields().iter() {
9999
columns.insert(
100100
field.name().clone(),
101-
AnyBuilder::from_data_type_with_capacity(field.data_type(), capacity),
101+
AnyBuilder::from_field_with_capacity(field, capacity),
102102
);
103103
}
104104

0 commit comments

Comments
 (0)