-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
H2 201 will require JTS 1.17 for passed Geometry objects #1100
Comments
It will be necessary to have an explicit error message if this is not the case, is this technically possible? |
AFAIK, development versions of H2GIS use own snapshot builds of H2 and they throw H2 can check In H2's OSGi bundle description JTS 1.17.0+ is optionally required. |
Thanks. Maybe we could check for JTS version on call to H2GIS init db function and log a warning if < 1.17 |
@SPalominos we must build a new H2 snapshot (2.0.201-SNAPHOT) in order to use the last JTS version 1.17.1 that contains many important changes. By the way, H2GIS will be compatible with the last Geotools version that uses > 1.17 |
I'm merging H2GIS with the last H2 master. I have some trouble with a function that return a ValueArray. public class FindGeometryMetadata extends DeterministicScalarFunction{
public FindGeometryMetadata() {
addProperty(PROP_REMARKS, "Extract geometry metadata from its create table signature."
+ "eg : GEOMETRY; GEOMETRY(POINT); GEOMETRY(POINT Z); GEOMETRY(POINTZ, 4326)...");
}
@Override
public String getJavaStaticMethod() {
return "extractMetadata";
}
/**
* Extract the geometry metadata from its OGC geometry data type
*
* Examples:
*
* POINT
* POINT Z
* POINT ZM
*
* @param geometryTableSignature
* @return an array of values with the following values order
* values[0] = GEOMETRY_TYPE CODE
* values[1] = COORD_DIMENSION
* values[2] = SRID
* @throws SQLException
*/
public static ValueArray extractMetadata(String geometryTableSignature) throws SQLException {
GeometryMetaData geomMeta = GeometryMetaData.createMetadataFromGeometryType(geometryTableSignature);
Value[] values = new Value[3];
values[0] = ValueVarchar.get(String.valueOf(geomMeta.getGeometryTypeCode()));
values[1] = ValueVarchar.get(String.valueOf(geomMeta.getDimension()));
values[2] = ValueVarchar.get(geomMeta.getSfs_geometryType());
return ValueArray.get(values, null);
}
} When I try to use it as SELECT FindGeometryMetadata(GEOMETRY_TYPE)[1] as geometry_type FROM INFORMATION_SCHEMA.COLUMNS WHERE DATA_TYPE = 'GEOMETRY'; It returns org.h2.jdbc.JdbcSQLDataException: Valeur invalide "JAVA_OBJECT" pour le paramètre "Array" @katzyn ARRAY_GET(FindGeometryMetadata(GEOMETRY_TYPE),1) returns the same error |
I think your function needs to return |
Excellent ! |
With the previous H2 syntax we were able to write CREATE TABLE TABLE_PROPERTIES_READ (THE_GEOM GEOMETRY(POLYGON,0),LEQ_PROFILE ARRAY)
We use the ARRAY data type to store json array. I'm in favor of the first option but comments are welcome. |
It wasn't removed, it was aligned with the SQL Standard to revolve long-standing issues with this data type. Now you need to specify data type of elements ( |
JSON data type was introduced in 1.4.200. In 2.0 it got an optional maximum length parameter in bytes and its length was also limited to 1,048,576 bytes. |
COLUMN_NAME from INFORMATION_SCHEMA.INDEXES has be moved to another schema table select * from INFORMATION_SCHEMA.INDEXES WHERE TABLE_NAME = 'SHPTABLE' and COLUMN_NAME='THE_GEOM' must be updated |
A print on st.executeQuery("select * from INFORMATION_SCHEMA.INDEXES WHERE TABLE_NAME = 'SHPTABLE'"); returns
@katzyn can you point me where is stored the COLUMN_NAME. |
See |
Thanks |
Currently H2GIS has a workaround to return a SRID when the INFORMATION_SCHEMA.COLUMNS return a SRID equals to 0. st.execute("DROP TABLE IF EXISTS input_table,grid;"
+ "CREATE TABLE input_table(the_geom Geometry(POLYGON, 4326));"
+ "INSERT INTO input_table VALUES"
+ "(ST_GeomFromText('POLYGON((0 0, 2 0, 2 2, 0 0))', 4326));");
st.execute("CREATE TABLE grid AS SELECT * FROM st_makegrid('input_table', 1, 1);"); The srid column of the geometry_columns view is populated with the value 4326. Do we need to keep this behaviour ? Note : In postgis, user must update manually the srid with UpdateGeometrySRID function |
Please note that in H2, unlike in PostGIS, SRID=0 doesn't have any special meaning. CREATE TABLE TEST(A GEOMETRY, B GEOMETRY(GEOMETRY, 0));
SELECT COLUMN_NAME, GEOMETRY_SRID FROM INFORMATION_SCHEMA.COLUMNS WHERE DATA_TYPE = 'GEOMETRY';
> COLUMN_NAME GEOMETRY_SRID
> A null
> B 0 When In PostGIS, |
ST_IsValidDetail returns an array of Object[] (see https://github.com/orbisgis/h2gis/blob/master/h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_IsValidDetail.java#L76) Data conversion error converting "GEOMETRY, BOOLEAN"; SQL statement: @katzyn |
I have cast the GEOMETRY_SRID as int so it returns 0 in the geometry columns view. |
No, we intentionally don't support that any more. Actually a row value data type should be used for that purpose, but our API for user-defined functions doesn't support this data type yet. |
Thank you. I will use a string array while waiting for this feature to be implemented in H2. |
I don't understand what do you mean. Cast from BTW, you shouldn't use PostgreSQL-specific syntax in H2-specific code. Cast to |
You are right. It's time to take a break ;( |
About geojson or json file drivers, I propose to import array as varchar or clob, especially for this kind of array : "testArray":[49, 40.0, {"member1":1, "member2":{"member21":21,"member22":22}}, "string", [13, "string", {"member3":3, "member4":4}]],
```
Users will then have to use json functions to manipulate this string.
@SPalominos , @nicolas-f |
Everything longer than 1,048,576 bytes or characters need to use BLOB or CLOB data type in H2 2.0. |
Thanks. getObject() on Value has been remove so this kind of set preparedStatement.setObject(columnId + 1, shpDriver.getField(rowId, columnId).getObject()); doesn't work any more. Is there another way to do that ? |
What is the data type of |
You can use |
Yes but my code works also with a postgis jdbc connection so I cannot set a JdbcConnection |
This file driver is able to import data in H2 and POSTGIS |
The first two arguments of this method belong to the target database and this database isn't required to be the H2 Database. The last two arguments belong to the source database and the source database must be H2. If you read this value from PostgreSQL, why it has the |
Actually when target database is H2, the connection from the source database may be |
Note that this method passes |
I read the file and I insert the values in a PostgreSQL table. |
If you don't construct values of |
Thank you. Sorry my internet connection has some pbs. |
JdbcUtils.set(targetPreparedStatement, targetParameterIndex, yourValue, null). rocks ! |
DROP TABLE IF EXISTS json_table;
CREATE TABLE json_table (test json);
INSERT INTO json_table values('[49, 40.0, {"member1":1, "member2":{"member21":21,"member22":22}}, "string", [13, "string", {"member3":3, "member4":4}]]');
SELECT CAST (test AS Varchar) FROM json_table; returns the Varchar representation ResultSet res = stat.executeQuery("SELECT * FROM json_table;");
res.next();
res.getString(1) return a bytes representation. does it make sense to return the string representation of the JSON type ? |
H2 converts boolean values to JSON scalar boolean value, numeric values to JSON scalar number, and character string values to JSON scalar string value. You need to use the JSON literal instead of character string literal: If you want to pass a |
I use |
Test with ? FORMAT json returns a bytes representation. |
H2 converts a character string value to a JSON String value exactly as required by the SQL Standard, for example, I don't know what you mean by “bytes representation” here. try (Connection c = DriverManager.getConnection("jdbc:h2:mem:")) {
Statement s = c.createStatement();
s.execute("CREATE TABLE json_table (test json)");
s.execute("INSERT INTO json_table values(JSON '[49, 40.0, {"
+ "\"member1\":1, \"member2\":{\"member21\":21,\"member22\":22}},"
+ " \"string\", [13, \"string\", {\"member3\":3, \"member4\":4}]]')");
PreparedStatement ps = c.prepareStatement("INSERT INTO json_table VALUES ? FORMAT JSON");
ps.setString(1, "[49, 40.0, {" + "\"member1\":1, \"member2\":{\"member21\":21,\"member22\":22}},"
+ " \"string\", [13, \"string\", {\"member3\":3, \"member4\":4}]]");
ps.executeUpdate();
try (ResultSet rs = s.executeQuery("TABLE json_table")) {
while (rs.next()) {
System.out.println(rs.getString(1));
}
}
} produces [49,40.0,{"member1":1,"member2":{"member21":21,"member22":22}},"string",[13,"string",{"member3":3,"member4":4}]]
[49,40.0,{"member1":1,"member2":{"member21":21,"member22":22}},"string",[13,"string",{"member3":3,"member4":4}]] just like expected. |
I use the approach with and rs.getString(1) returns WzQ5LDQwLjAseyJtZW1iZXIxIjoxLCJtZW1iZXIyIjp7Im1lbWJlcjIxIjoyMSwibWVtYmVyMjIiOjIyfX0sInN0cmluZyIsWz.... |
I can't reproduce it with current H2. Actually you should use |
Your string is a Base64-encoded JSON. H2 does not work with Base64 at all. Something else performs Base64 encoding in your environment. |
Maybe due to java 11. |
When I try to run H2 version available in nexus.orbisgis.org, it returns org.h2.jdbc.JdbcSQLNonTransientException: Erreur générale: "java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer;" I'm not able to open any databases with a JAVA 8 version |
You need to compile H2 with Java 8. Compilation on newer versions creates incompatible jar even if you use Java 8 target of Javac. |
But your problem with Base64 isn't related with H2 on Java 11, CI tests of H2 use that Java version too. |
We are on the way to finish the H2 and JTS update. @SPalominos There is one important issue that I'm not able to fix. It's about spatial index on linked table. |
H2 returns |
Yes but it was working in the last version. see https://github.com/orbisgis/h2gis/blob/master/h2gis-functions/src/test/java/org/h2gis/functions/io/shp/SHPEngineTest.java#L298 |
Maybe I missed something. |
Migration completed. We are now in-line with the last H2 master. |
The next version of H2 will be able to accept JTS Polygon objects only with
jts-core
1.17 in the classpath due to incompatible change in JTS.The text was updated successfully, but these errors were encountered: