You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sedona.apache.org by "conect (via GitHub)" <gi...@apache.org> on 2023/03/22 16:06:49 UTC
[GitHub] [sedona] conect opened a new issue, #807: Writing dataframe to Postgresql (Postgis-Extension) DB fails
conect opened a new issue, #807:
URL: https://github.com/apache/sedona/issues/807
## Expected behavior
Geojson is read and then written as dataframe to Postgresql DB
## Actual behavior
Following error occurs:
java.lang.IllegalArgumentException: Can't get JDBC type for array<tinyint>
at org.apache.spark.sql.errors.QueryExecutionErrors$.cannotGetJdbcTypeError(QueryExecutionErrors.scala:674)
at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$.$anonfun$getJdbcType$2(JdbcUtils.scala:181)
at scala.Option.getOrElse(Option.scala:189)
at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$.getJdbcType(JdbcUtils.scala:181)
at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$.$anonfun$savePartition$5(JdbcUtils.scala:705)
at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$.$anonfun$savePartition$5$adapted(JdbcUtils.scala:705)
## Steps to reproduce the problem
```
SparkSession spark = SparkSession.builder()
.master("local[*]") // Delete this if run in cluster mode
.appName("readTestScala") // Change this to a proper name
// Enable Sedona custom Kryo serializer
.config("spark.serializer", KryoSerializer.class.getName())
.config("spark.kryo.registrator", SedonaKryoRegistrator.class.getName())
.getOrCreate(); // org.apache.sedona.core.serde.SedonaKryoRegistrator
SedonaSQLRegistrator.registerAll(spark);
SedonaVizRegistrator.registerAll(spark);
SpatialRDD spatialRDD1 = GeoJsonReader.readToGeometryRDD(JavaSparkContext.fromSparkContext(spark.sparkContext()),"./src/main/resources/features.json",false,false);
spatialRDD1.CRSTransform("epsg:4326","epsg:3857");
Dataset<Row> d2 = Adapter.toDf(spatialRDD1,spark);
d2.show();
System.out.println(d2.schema());
d2.write()
.format("jdbc")
.mode(SaveMode.Append )
.option("url", "jdbc:postgresql://somedb")
.option("dbtable", "sometable")
.option("user", "someuser")
.option("password", "somepw")
.save();
```
## Settings
Sedona version =
<dependency>
<groupId>org.apache.sedona</groupId>
<artifactId>sedona-python-adapter-3.0_2.12</artifactId>
<version>1.3.1-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.sedona</groupId>
<artifactId>sedona-viz-3.0_2.12</artifactId>
<version>1.3.1-incubating</version>
</dependency>
Apache Spark version =
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.12</artifactId>
<version>3.2.1</version>
</dependency>
Apache Flink version = ?
API type = Java
JRE version = 1.8
Environment = Standalone
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [sedona] conect commented on issue #807: Writing dataframe to Postgresql (Postgis-Extension) DB fails
Posted by "conect (via GitHub)" <gi...@apache.org>.
conect commented on issue #807:
URL: https://github.com/apache/sedona/issues/807#issuecomment-1481393363
Hi @umartin,
Thank you for your fast reply!
Hm when inserting it your way (slightly java adapted)
`Dataset<Row> d2 = Adapter.toDf(spatialRDD1,spark).withColumn("geometry", functions.expr("ST_AsEWKT(geometry)"));`
The type within the postgres db gets:
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+-------+-----------+----------+---------+----------+--------------+-------------
geometry | **bytea** | | | | extended | |
id | text | | | | extended | |
some_prop| text | | | | extended | |
but bytea is not a geometric representation within postgres.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [sedona] umartin commented on issue #807: Writing dataframe to Postgresql (Postgis-Extension) DB fails
Posted by "umartin (via GitHub)" <gi...@apache.org>.
umartin commented on issue #807:
URL: https://github.com/apache/sedona/issues/807#issuecomment-1479903031
Hi @conect!
Postgis doesn't understand the Sedona internal serialization format. The native postgis protocol uses EWKB for geometries. Try converting the geometry with ST_AsEWKB before writing to postgis.
`Dataset<Row> d2 = Adapter.toDf(spatialRDD1,spark).withColumn("geometry", expr("ST_AsEWKB(geometry)"));`
Br,
Martin Andersson
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [sedona] umartin commented on issue #807: Writing dataframe to Postgresql (Postgis-Extension) DB fails
Posted by "umartin (via GitHub)" <gi...@apache.org>.
umartin commented on issue #807:
URL: https://github.com/apache/sedona/issues/807#issuecomment-1481405797
Hi,
If you create the table externally to Spark before writing you can set the column type to geometry and Postgis will accept the EWKB as geometry. If you let Spark create the table you can change the column type post insert. Execute something like this in Postgis: "alter table my_table alter column geometry type geometry;".
Let me know if that works for you!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [sedona] conect commented on issue #807: Writing dataframe to Postgresql (Postgis-Extension) DB fails
Posted by "conect (via GitHub)" <gi...@apache.org>.
conect commented on issue #807:
URL: https://github.com/apache/sedona/issues/807#issuecomment-1494225161
Thank you this may be indeed be caused by the client (QGIS) that I used. Would have thought QGIS does understand this...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [sedona] umartin commented on issue #807: Writing dataframe to Postgresql (Postgis-Extension) DB fails
Posted by "umartin (via GitHub)" <gi...@apache.org>.
umartin commented on issue #807:
URL: https://github.com/apache/sedona/issues/807#issuecomment-1490437146
That's weird. I did some testing on my setup. Using "geometry" as type works fine for me. "geometry(<geometry type>, <srid>)" is the specialized version of "geometry". "geometry" should work for any geometry.
Some gis clients like QGIS works better when the type is more specialized but Postgis should be fine without specialization.
Should we close this issue our do you want to dig deaper?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [sedona] conect closed issue #807: Writing dataframe to Postgresql (Postgis-Extension) DB fails
Posted by "conect (via GitHub)" <gi...@apache.org>.
conect closed issue #807: Writing dataframe to Postgresql (Postgis-Extension) DB fails
URL: https://github.com/apache/sedona/issues/807
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [sedona] conect commented on issue #807: Writing dataframe to Postgresql (Postgis-Extension) DB fails
Posted by "conect (via GitHub)" <gi...@apache.org>.
conect commented on issue #807:
URL: https://github.com/apache/sedona/issues/807#issuecomment-1485505762
Hi,
postgis doesn't seem to understand geometry, but when i use e.g. linegeometries:
`alter table my_table alter column geometry type geometry(LineString,3857);`
than it works.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org