Skip to content

Commit 7ed14bb

Browse files
author
Paultagoras
committed
Added some null pointer checks
1 parent b3caed8 commit 7ed14bb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ protected AbstractBinaryFormatReader(InputStream inputStream, QuerySettings quer
9999
* @throws IOException
100100
*/
101101
public boolean readToPOJO(Map<String, POJOSetter> deserializers, Object obj ) throws IOException {
102+
if (columns == null || columns.length == 0) {
103+
return false;
104+
}
105+
102106
boolean firstColumn = true;
103107

104108
for (ClickHouseColumn column : columns) {
@@ -135,6 +139,10 @@ public boolean readToPOJO(Map<String, POJOSetter> deserializers, Object obj ) th
135139
* @throws IOException
136140
*/
137141
public boolean readRecord(Map<String, Object> record) throws IOException {
142+
if (columns == null || columns.length == 0) {
143+
return false;
144+
}
145+
138146
boolean firstColumn = true;
139147
for (ClickHouseColumn column : columns) {
140148
try {
@@ -157,6 +165,10 @@ public boolean readRecord(Map<String, Object> record) throws IOException {
157165
}
158166

159167
protected boolean readRecord(Object[] record) throws IOException {
168+
if (columns == null || columns.length == 0) {
169+
return false;
170+
}
171+
160172
boolean firstColumn = true;
161173
for (int i = 0; i < columns.length; i++) {
162174
try {

client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ public void testQueryAllTableNames() {
344344
Assert.assertTrue(tableNames.containsAll(expectedTableNames));
345345
}
346346

347+
@Test(groups = {"integration"})
348+
public void testQueryAllInsertSelect() {
349+
client.queryAll("CREATE TABLE IF NOT EXISTS nums (number Int16) ENGINE = MergeTree() ORDER BY number;");
350+
String sql = "INSERT INTO nums SELECT * FROM system.numbers LIMIT 100";
351+
List<GenericRecord> records = client.queryAll(sql);
352+
Assert.assertTrue(records.isEmpty());
353+
}
354+
347355
@Test(groups = {"integration"})
348356
public void testQueryJSONEachRow() throws ExecutionException, InterruptedException {
349357
Map<String, Object> datasetRecord = prepareSimpleDataSet();

0 commit comments

Comments
 (0)