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 not mapping properly in 4.5.0 #11325
Comments
My suspicion is that this is connected to the change how Object arrays are handled from 4.2
The query SELECT allowed_users FROM myproject.projects WHERE allowed_users != [NULL] returns 1 row in 4.0.10 and 4.1.8 Steps do reproduce CREATE TABLE myproject.projects (
allowed_users ARRAY(OBJECT(IGNORED))
);
INSERT INTO myproject.projects (
allowed_users) VALUES (['{"accepted":false,"role":"developer","email":"email@gmail.com"}']);
SELECT allowed_users FROM myproject.projects WHERE allowed_users != [NULL] |
btw ... using CREATE TABLE myproject.projects (
allowed_users ARRAY(OBJECT(DYNAMIC))
); SELECT allowed_users FROM myproject.projects WHERE allowed_users != [NULL] returns 1 row |
could be related to #10746 |
Hi, thanks for the reply. I forgot to mention, I'm using io.crate.client.jdbc.CrateDriver not the PostgreSQL one.
ARRAY(OBJECT(DYNAMIC)) did not solve the issue, the same error still occurs. The error occurs when trying to read the data, insertion works perfectly. If I try and query the data via curl it always returns the same number of rows as the 4.0.10 version. The error is dropped in Java from CrateDriver when I try to read the inserted data. When preparing a statement for the insertion the following line was used:
The getSQLConnection method is defined as:
I used the not NULL query to simply filter out the other data, to keep the question as short as possible. In the actual project that part is never used, I just query all the data like so:
|
@harispdev I can't really reproduce this unfortunately. Object[] array = (Object[]) rs.getArray("allowed_users").getArray(); works as intended import java.sql.*;
import java.util.Properties;
public class Main {
public static void main(String[] args) {
try {
Properties props = new Properties();
props.put("user","crate");
Connection conn = DriverManager.getConnection("crate://localhost:5432/",props);
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT allowed_users FROM myproject.projects3 where allowed_users != [null];");
resultSet.next();
Object[] array = (Object[]) resultSet.getArray("allowed_users").getArray();
System.out.println(array.length);
} catch (SQLException e) {
System.out.println( e);
}
}
} returns This seems to me more like a problem with the mapping, but not crate / jdbc. Could you maybe share a minimal example to reproduce this and the complete exception? |
@proddata Georg you seem to be right, after some additional tests, it looks like the error actually occurs indeed when trying to map the data:
|
So this is indeed this to be related to this change to make CrateDB more compatible with standard PostgreSQL
|
Something like that: public class Main {
public static void main(String[] args) {
try {
Properties props = new Properties();
props.put("user","crate");
Connection conn = DriverManager.getConnection("crate://localhost:5432/",props);
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT allowed_users FROM myproject.projects where allowed_users != [null];");
resultSet.next();
Object[] array = (Object[]) resultSet.getArray("allowed_users").getArray();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
AllowedUser p = objectMapper.readValue( array[0].toString(), AllowedUser.class);
System.out.println("Email: "+p.email);
System.out.println("Role: "+p.role);
System.out.println("Accepted: "+p.accepted);
} catch (SQLException e) {
System.out.println( e);
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
class AllowedUser {
@JsonProperty
String email;
@JsonProperty
String role;
@JsonProperty
Boolean accepted;
} I will close this issue now, as this is neither a bug report, nor feature request for CrateDB. |
@proddata thank you so much for your patience and your assistance Georg. I've managed to solve the issue and
|
Curl request on the database:
Result:
Java line on which error occurs:
Java model AllowedUser:
Error that Crate returns:
Column allowed_users defined as:
Locally and on the QA server Crate doesn't return any errors and works as expected. The issue occurs only on the production server. The dataset is identical on all envs.
Local and QA Crate version: 4.0.10
Production Crate version: 4.5.0
The text was updated successfully, but these errors were encountered: