Skip to content

Document that from_arrow_array uses GeoArrowType::from_arrow_field internally #1414

@kylebarron

Description

@kylebarron

See here, making from_arrow_field return Result<Option<GeoArrowType>> means that from_arrow_array must return Result<Option<Arc<dyn GeoArrowArray>>>.

But because from_arrow_field never returns Ok(None), so also from_arrow_field will never return Ok(None). So this feels like it needlessly infects all downstream code to require it to handle Option when it doesn't have to.

Alternatively, perhaps from_arrow_array should use GeoArrowType::from_extension_type internally.

Originally posted by @kylebarron in #1394 (comment)

/// Construct a new [GeoArrowArray] from an Arrow [Array] and [Field].
pub fn from_arrow_array(
array: &dyn Array,
field: &Field,
) -> GeoArrowResult<Arc<dyn GeoArrowArray>> {
use GeoArrowType::*;
let result: Arc<dyn GeoArrowArray> = match GeoArrowType::from_arrow_field(field)? {
Point(_) => Arc::new(PointArray::try_from((array, field))?),
LineString(_) => Arc::new(LineStringArray::try_from((array, field))?),
Polygon(_) => Arc::new(PolygonArray::try_from((array, field))?),
MultiPoint(_) => Arc::new(MultiPointArray::try_from((array, field))?),
MultiLineString(_) => Arc::new(MultiLineStringArray::try_from((array, field))?),
MultiPolygon(_) => Arc::new(MultiPolygonArray::try_from((array, field))?),
GeometryCollection(_) => Arc::new(GeometryCollectionArray::try_from((array, field))?),
Rect(_) => Arc::new(RectArray::try_from((array, field))?),
Geometry(_) => Arc::new(GeometryArray::try_from((array, field))?),
Wkb(_) => Arc::new(WkbArray::try_from((array, field))?),
LargeWkb(_) => Arc::new(LargeWkbArray::try_from((array, field))?),
WkbView(_) => Arc::new(WkbViewArray::try_from((array, field))?),
Wkt(_) => Arc::new(WktArray::try_from((array, field))?),
LargeWkt(_) => Arc::new(LargeWktArray::try_from((array, field))?),
WktView(_) => Arc::new(WktViewArray::try_from((array, field))?),
};
Ok(result)
}

We should document that currently this applies data type coercion without requiring extension metadata to exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions