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
JDBC support for Object array #5620
Comments
thanks @ramach for reporting this. we will have a look at it. |
@ramach, you can find a working implementation here: https://github.com/crate/crate-jdbc/blob/master/driver/test/java/io/crate/client/jdbc/integrationtests/CrateJDBCTypesTest.java#L71-L77 |
thanks a lot
…On Wed, May 24, 2017 at 5:40 AM, Johannes Moser ***@***.***> wrote:
@ramach <https://github.com/ramach>, you can find a working
implementation here: https://github.com/crate/
crate-jdbc/blob/master/driver/test/java/io/crate/client/
jdbc/integrationtests/CrateJDBCTypesTest.java#L71-L77
hope that helps you.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5620 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFcNjKVPHkBzA7iKNVl4DfDmShT7l4iJks5r9CVPgaJpZM4Nkcqx>
.
|
Your example still internally uses String [] in value field.
|
this happens during my set block is statement.setArray(2,
connection.createArrayOf("object", new Object[] {new HashMap<String, Object>() {
private static final long serialVersionUID = 1L;
{
put("entity", entityObject);
}}, new HashMap<String, Object>() {{
put("entity2", entityObject2);
}}
})); |
@ramach I'm not sure if I get you right, but it seems that you want to insert an "already" jsonified value into a field of type This is what this error is indicating. The value seems to be a
You should instead work with the CrateDB Data Types directly. new HashMap<String, Object>() {{
put("id", "foo");
put("count", 1L);
...
}}, new HashMap<String, Object>() {{
put("id", "bar");
put("count", 2L);
...
}} |
hi @ramach can you provide an answer to @mikethebeer? |
Now am seeing this error. Looks like auto table create during test initialization does not happen(though I do exactly the way you have in your integration test) - with @BeforeClass code snippet for array creation is shown below
2017-05-30 07:36:13,220 ERROR [main] jdbc.PreparedStatementBinder (PreparedStatementBinder.java:bindRecord(94)) - error {} |
@ramach are you using the official crate-jdbc driver? The driver you are using wants to query a meta table You will find the repo here: https://github.com/crate/crate-jdbc |
I am positive am using only Crate JDBC driver. I include this
In my build file (pom) that is only reference to crate. No explicit call to postgres. postgres library is only while creating dynamic Objects using json and PGObject as shown in your example import org.postgresql.util.PGobject;
|
for connection I use |
@ramach pls consider to use the latest stable release of It can be that you run into this issue that has been fixed since 2.1.0. |
Thanks - that error is resolved with 2.1.7 Now I see this io.crate.shade.org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of org.postgresql.util.PGobject. Use setObject() with an explicit Types value to specify the type to use. the relevant code is private void setCustomType(int position, Gson gson, List values) throws SQLException { |
the copy paste did not show the correct |
List is a generic array - I am not able to copy paste with < |
List |
The way am using to setObject is identical to what you have in your crate-sample-app (Guestbook) |
At least with 2.0.2 setObject worked (though array had error) the sql looks like entity object as ( I can create a map and put all attributes inside - I prefer not doing that using Gson() is more compact as we have several fields in some objects |
I see another problem. In latest version 2.1.7 f preparedStatement.executeBatch() causes an error though executeUpdate() works fine |
@ramach I have an example app here that uses the field type package io.crate.sampleapp;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
public class ObjectArrayApplication {
public static void main(String[] args) {
// CREATE TABLE t1 (
// obj_col OBJECT AS (
// col_int INTEGER,
// col_str STRING
// ),
// obj_arr_col ARRAY(OBJECT AS (
// col_int INTEGER,
// col_str STRING
// ))
// );
try (Connection conn = DriverManager.getConnection("crate://localhost:5432/doc")) {
System.out.println("INSERT");
PreparedStatement insertStatement = conn.prepareStatement("INSERT INTO t1 (obj_col, obj_arr_col) VALUES (?, ?)");
insertStatement.setObject(1, new HashMap<String, Object>(){{
put("col_int", 1);
put("col_str", "some text");
}});
insertStatement.setArray(2, conn.createArrayOf("object", new Map[]{
new HashMap<String, Object>() {{
put("col_int", 2);
put("col_str", "some other text");
}},
new HashMap<String, Object>() {{
put("col_int", 3);
put("col_str", "another text");
}}
}));
insertStatement.execute();
System.out.println("REFRESH");
Statement refreshStatement = conn.createStatement();
refreshStatement.execute("REFRESH TABLE t1");
System.out.println("SELECT");
Statement selectStatement = conn.createStatement();
ResultSet rs = selectStatement.executeQuery("SELECT obj_col, obj_arr_col FROM t1");
while (rs.next()) {
Map<String, Object> obj_col = (Map<String, Object>) rs.getObject("obj_col");
System.out.println(obj_col);
Array obj_arr_col = rs.getArray("obj_arr_col");
System.out.println(obj_arr_col);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
} |
thanks this was very helpful. Looks like your sample application (guestbook) has not been updated - setObject still uses json & PGobject |
@ramach yes you are right. It depends on an older version where this was still necessary. https://github.com/crate/crate-sample-apps/blob/master/java/pom.xml#L19 |
CrateDB version:
0.57.8
JVM version:
1.8.0_74
OS version / environment description:
MAC-OS X 10.11.6
Problem description:
Not able to insert a column (using JDBC preparedStatement) of Type -> Array of Object
Steps to reproduce:
A simple code shown below will show this error.
relevant part of the schema
Use case:
Feature description:
The text was updated successfully, but these errors were encountered: