Esri / spatial-framework-for-hadoop

The Spatial Framework for Hadoop allows developers and data scientists to use the Hadoop data processing system for spatial data analysis.
Apache License 2.0
367 stars 159 forks source link

Tranforming array<array<double>> to ST_MultiPolygon #132

Closed Andarius closed 3 years ago

Andarius commented 6 years ago

I'm trying to load a valid Geojson file using SPARK SQL and then transforming the coordinates to ST_MultiPolygon.

The jars I use are:

esri-geometry-api-2.0.0.jar
spatial-sdk-json-1.2.0.jar
spatial-sdk-hive-1.2.0.jar

The schema of the input data is:

 |-- geometry: struct (nullable = true)
 |    |-- coordinates: array (nullable = true)
 |    |    |-- element: array (containsNull = true)
 |    |    |    |-- element: array (containsNull = true)
 |    |    |    |    |-- element: array (containsNull = true)
 |    |    |    |    |    |-- element: double (containsNull = true)
 |    |-- type: string (nullable = true)
 |-- properties: struct (nullable = true)
 |-- type: string (nullable = true)

The process fails when I try the following:

SELECT
    st_multipolygon(geometry.coordinates[0][0]) as geo
FROM test

I get:

No handler for Hive UDF 'com.esri.hadoop.hive.ST_MultiPolygon': org.apache.hadoop.hive.ql.exec.NoMatchingMethodException: No matching method for class com.esri.hadoop.hive.ST_MultiPolygon with (array<array<double>>). Possible choices: _FUNC_(array<array<double>>) _FUNC_(string) ;

So I pass an array<array> and it expects an array<array>.

It works if I try:

SELECT
    st_multipolygon(geometry.coordinates[0][0][0], geometry.coordinates[0][0][1], ...) as geo
FROM test

Any idea of what's wrong (or what I'm doing wrong ?)

randallwhitman commented 6 years ago

Spatial-Framework documentation says ST_MultiPolygon(array(x1, y1, x2, y2, ... ), array(x1, y1, x2, y2, ... ), ... ), so it looks like st_multipolygon(geometry.coordinates[0][0][0], geometry.coordinates[0][0][1], ...) passes array<double> as expected and works correctly.

Maybe the only oddity is - is Spark-SQL presenting a botched error message?

randallwhitman commented 6 years ago

Cross-reference #36, #126.

randallwhitman commented 4 years ago

Try ST_GeomFromGeoJson.