@@ -155,6 +155,8 @@ public ClickHouseValue next() {
155
155
protected final ClickHouseInputStream input ;
156
156
protected final ClickHouseOutputStream output ;
157
157
158
+ protected final Map <String , Serializable > extraProps ;
159
+
158
160
protected DefaultSerDe serde ;
159
161
/**
160
162
* Column index shared by {@link #read(ClickHouseValue)}, {@link #records()},
@@ -177,7 +179,7 @@ public ClickHouseValue next() {
177
179
*/
178
180
protected boolean hasMoreToRead () throws UncheckedIOException {
179
181
try {
180
- if (input .available () <= 0 ) {
182
+ if (input .available () < 1 ) {
181
183
input .close ();
182
184
return false ;
183
185
}
@@ -389,6 +391,8 @@ protected ClickHouseDataProcessor(ClickHouseDataConfig config, ClickHouseInputSt
389
391
this .input = input ;
390
392
this .output = output ;
391
393
394
+ this .extraProps = new HashMap <>();
395
+
392
396
this .initialColumns = columns ;
393
397
this .initialSettings = settings ;
394
398
this .serde = null ;
@@ -400,6 +404,27 @@ protected ClickHouseDataProcessor(ClickHouseDataConfig config, ClickHouseInputSt
400
404
this .writePosition = 0 ;
401
405
}
402
406
407
+ /**
408
+ * Checks whether the processor contains extra property.
409
+ *
410
+ * @return true if the processor has extra property; false otherwise
411
+ */
412
+ public boolean hasExtraProperties () {
413
+ return extraProps .isEmpty ();
414
+ }
415
+
416
+ /**
417
+ * Gets a typed extra property.
418
+ *
419
+ * @param <T> type of the property value
420
+ * @param key key of the property
421
+ * @param valueClass non-null Java class of the property value
422
+ * @return typed extra property, could be null
423
+ */
424
+ public <T extends Serializable > T getExtraProperty (String key , Class <T > valueClass ) {
425
+ return valueClass .cast (extraProps .get (key ));
426
+ }
427
+
403
428
public abstract ClickHouseDeserializer getDeserializer (ClickHouseDataConfig config , ClickHouseColumn column );
404
429
405
430
public final ClickHouseDeserializer [] getDeserializers (ClickHouseDataConfig config ,
@@ -462,6 +487,25 @@ public final Iterable<ClickHouseRecord> records() {
462
487
return () -> getInitializedSerDe ().records ;
463
488
}
464
489
490
+ /**
491
+ * Returns an iterable collection of mapped objects which can be walked through
492
+ * in a foreach loop. When {@code objClass} is null or {@link ClickHouseRecord},
493
+ * it's same as calling {@link #records()}.
494
+ *
495
+ * @param <T> type of the mapped object
496
+ * @param objClass non-null class of the mapped object
497
+ * @return non-null iterable collection
498
+ * @throws UncheckedIOException when failed to read data(e.g. deserialization)
499
+ */
500
+ @ SuppressWarnings ("unchecked" )
501
+ public <T > Iterable <T > records (Class <T > objClass ) {
502
+ if (objClass == null || objClass == ClickHouseRecord .class ) {
503
+ return (Iterable <T >) records ();
504
+ }
505
+
506
+ return () -> ClickHouseRecordMapper .wrap (getColumns (), getInitializedSerDe ().records , objClass );
507
+ }
508
+
465
509
/**
466
510
* Returns an iterable collection of values which can be walked through in a
467
511
* foreach-loop. In general, this is slower than {@link #records()}, because the
0 commit comments