jOOQ / jOOQ

jOOQ is the best way to write SQL in Java
https://www.jooq.org
Other
6.17k stars 1.21k forks source link

Add support for GeoJSON in jOOQ's spatial APIs #16845

Open lukaseder opened 5 months ago

lukaseder commented 5 months ago

Numerous RDBMS support the GeoJSON notation in addition to WKT and WKB, e.g. Oracle, and many others: https://docs.oracle.com/en/database/oracle/oracle-database/23/adjsn/using-GeoJSON-geographic-data.html

jOOQ currently doesn't support this format through jOOQ API. This issue is to collect user interest in the topic.

mbach979 commented 1 month ago

Also, this relates to sort of a regression. Prior to Snowflake Spatial support in 3.18.x the following used to work for inserting into a GEOGRAPHY type:

        getJooqContext().insertInto(onlyGeogTable, DSL.field("geog1", SQLDataType.GEOGRAPHY))
                        .values(Geography.valueOf("{\n" +
                                "  \"coordinates\": [\n" +
                                "    [\n" +
                                "      [\n" +
                                "        -8.863857899999999e+01,\n" +
                                "        4.256637700000000e+01\n" +
                                "      ]\n" +
                                "    ],\n" +
                                "  ],\n" +
                                "  \"type\": \"Polygon\"\n" +
                                "}")).execute();

However this now fails because this gets translated to a call to ST_GEOMFROMTEXT (see other bug about the mis-translation). ST_GEOMFROMTEXT only excepts WKT and EWKT. Snowflake seems to accept and translate GeoJSON just fine just by either binding a string to the column or using TO_GEOMETRY or a cast.

At least for Snowflake GeoJSON support MAY be as simple as using a different translation for text to geometry/geography. I'm sure there are other implications that I'm not seeing.

I can follow a separate bug for this, but since GeoJSON doesn't seem to be explicitly supported, I didn't want to raise an issue against an unsupported feature.

lukaseder commented 1 month ago

Also, this relates to sort of a regression.

This type of "regression" always happens when jOOQ introduces support for a dialect, as previously, you relied on jOOQ's usage of JDBC methods like PreparedStatement.setObject(), whereas now jOOQ has an opinion on how to bind these types for a given dialect.

The workaround in this case could be to implement your own data type binding and use that instead of SQLDataType.GEOGRAPHY, e.g. SQLDataType.GEOGRAPHY.asConvertedDataType(binding). Let me know if you need more information about data type bindings.