-
Notifications
You must be signed in to change notification settings - Fork 543
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
Incorrect parsing of complex types (Arrays and Tuples) #103
Comments
Thanks. |
Nested arrays are quite straightforward as I see. It just needs careful implementation. |
As Tuple is not a part of standard JDBC, I think it's reasonable to return tuple as |
@serebrserg Hello, Is this issue actual? |
any updates? |
The first two work now but not the last. I agree with Aivean that we do need ClickHouseTuple(in addition to ClickHouseArray and ClickHouseBitmap etc.). Let me see if I can address the issue using RowBinary format. |
I cannot find However, the Nested type is internally discrete array columns. |
Most data types including // create table test_table(
// array_column Array(Tuple(UInt8, LowCardinality(String))),
// array_tuple Tuple(Map(String, String), String)
// )engine=Memory
// insert into test_table values([(1,'a'), (2,'b')], ({'a':'1','b':'2'},'c'))
ClickHouseNode server = ClickHouseNode.of("localhost", ClickHouseProtocol.GRPC, 9100, "default");
try (ClickHouseClient client = ClickHouseClient.newInstance(server.getProtocol());
ClickHouseResponse resp = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
.query("select * from test_table").execute().get()) {
for (ClickHouseRecord r : resp.records()) {
List<?>[] array = (List<?>[]) r.getValue(0).asObject();
List<?> tuple = r.getValue(1).asObject(List.class);
Map<String, String> map = (Map<String, String>) tuple.get(0);
...
}
} JDBC driver will be enhanced accordingly. |
Starting from 0.3.2-test1, JDBC driver supports both grpc and http protocol, and mixed used of nested types are supported. For examples: @Test(groups = "integration")
public void testArray() throws SQLException {
try (ClickHouseConnection conn = newConnection(new Properties());
Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select [1,2,3] v1, ['a','b', 'c'] v2, arrayZip(v1, v2) v3");
Assert.assertTrue(rs.next());
Assert.assertEquals(rs.getObject(1), new short[] { 1, 2, 3 });
Assert.assertEquals(rs.getArray(1).getArray(), new short[] { 1, 2, 3 });
Assert.assertTrue(rs.getArray(1).getArray() == rs.getObject(1));
Assert.assertEquals(rs.getObject(2), new String[] { "a", "b", "c" });
Assert.assertEquals(rs.getArray(2).getArray(), new String[] { "a", "b", "c" });
Assert.assertTrue(rs.getArray(2).getArray() == rs.getObject(2));
Assert.assertEquals(rs.getObject(3), new List[] { Arrays.asList((short) 1, "a"),
Arrays.asList((short) 2, "b"), Arrays.asList((short) 3, "c") });
Assert.assertEquals(rs.getArray(3).getArray(), new List[] { Arrays.asList((short) 1, "a"),
Arrays.asList((short) 2, "b"), Arrays.asList((short) 3, "c") });
Assert.assertTrue(rs.getArray(3).getArray() == rs.getObject(3));
Assert.assertFalse(rs.next());
}
}
@Test(groups = "integration")
public void testTuple() throws SQLException {
try (ClickHouseConnection conn = newConnection(new Properties());
Statement stmt = conn.createStatement()) {
ResultSet rs = stmt
.executeQuery(
"select (1::Int16, 'a', 1.2::Float32, [1,2]::Array(Nullable(UInt8)), map(toUInt32(1),'a')) v");
Assert.assertTrue(rs.next());
List<?> v = rs.getObject(1, List.class);
Assert.assertEquals(v.size(), 5);
Assert.assertEquals(v.get(0), Short.valueOf((short) 1));
Assert.assertEquals(v.get(1), "a");
Assert.assertEquals(v.get(2), Float.valueOf(1.2F));
Assert.assertEquals(v.get(3), new Short[] { 1, 2 });
Assert.assertEquals(v.get(4), Collections.singletonMap(1L, "a"));
Assert.assertFalse(rs.next());
}
} |
Here are some cases that I've found (
rs
is aResultSet
instance):Tuple:
can only be extracted as
String
:Nested arrays:
cannot be extracted as
Array
:Tuples nested in Array:
strange parsing behavior when parsed as
Array
:The text was updated successfully, but these errors were encountered: