-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1826 from ClickHouse/clientv2_primitive_reader
[client-v2] primitive reading into pojo
- Loading branch information
Showing
7 changed files
with
526 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
374 changes: 286 additions & 88 deletions
374
...-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java
Large diffs are not rendered by default.
Oops, something went wrong.
327 changes: 171 additions & 156 deletions
327
client-v2/src/main/java/com/clickhouse/client/api/internal/SerializerUtils.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 12 additions & 46 deletions
58
client-v2/src/test/java/com/clickhouse/client/internal/SerializerUtilsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,28 @@ | ||
package com.clickhouse.client.internal; | ||
|
||
import com.clickhouse.client.api.internal.SerializerUtils; | ||
import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader; | ||
import com.clickhouse.client.api.query.POJOSetter; | ||
import com.clickhouse.client.query.SamplePOJO; | ||
import com.clickhouse.client.query.QuerySamplePOJO; | ||
import com.clickhouse.client.query.SimplePOJO; | ||
import com.clickhouse.data.ClickHouseColumn; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.lang.reflect.Method; | ||
import java.math.BigInteger; | ||
import java.io.IOException; | ||
import java.time.LocalDateTime; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.time.ZonedDateTime; | ||
|
||
public class SerializerUtilsTests { | ||
|
||
@Test(enabled = false) | ||
public void testDeserialize() throws Exception { | ||
|
||
Map<String, POJOSetter> pojoSetterList = new HashMap<>(); | ||
for (Method method : SamplePOJOForSerialization.class.getDeclaredMethods()) { | ||
if (method.getName().startsWith("set")) { | ||
pojoSetterList.put(method.getName().substring(3).toLowerCase(), | ||
SerializerUtils.compilePOJOSetter(method, ClickHouseColumn.of(method.getName(), | ||
"String"))); | ||
} | ||
} | ||
|
||
SamplePOJOForSerialization pojo = new SamplePOJOForSerialization(); | ||
pojoSetterList.get("string").setValue(pojo, "John Doe"); | ||
pojoSetterList.get("int32").setValue(pojo, Integer.valueOf(30)); | ||
pojoSetterList.get("int16").setValue(pojo, 22); | ||
|
||
Assert.assertEquals(pojo.getString(), "John Doe"); | ||
Assert.assertEquals(pojo.getInt32(), 30); | ||
Assert.assertEquals(pojo.getInt16(), 22); | ||
} | ||
|
||
public static class SamplePOJOInt256Setter implements POJOSetter { | ||
|
||
|
||
|
||
|
||
/* | ||
public void setValue(java.lang.Object, java.lang.Object); | ||
Code: | ||
0: aload_1 | ||
1: checkcast #7 // class com/clickhouse/client/query/SamplePOJO | ||
4: aload_2 | ||
5: checkcast #25 // class java/math/BigInteger | ||
8: invokevirtual #27 // Method com/clickhouse/client/query/SamplePOJO.setInt256:(Ljava/math/BigInteger;)V | ||
11: return | ||
*/ | ||
@Override | ||
public void setValue(Object obj, Object value) { | ||
Arrays.stream(((Object[]) value)).collect(Collectors.toList()); | ||
public void setValue(Object obj, BinaryStreamReader reader, ClickHouseColumn column) throws IOException { | ||
((QuerySamplePOJO)obj).setDateTime(((ZonedDateTime)reader.readValue(column)).toLocalDateTime()); | ||
} | ||
|
||
public void readValue(Object obj, BinaryStreamReader reader, ClickHouseColumn column) throws IOException { | ||
// ((SamplePOJO)obj).setDateTime(((ZonedDateTime)reader.readValue(column)).toLocalDateTime()); | ||
((SimplePOJO)obj).setId(reader.readIntLE()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters