@@ -52,14 +52,19 @@ public ClickHouseResponseSummary getSummary() {
52
52
53
53
@ Override
54
54
public ClickHouseInputStream getInputStream () {
55
- return null ;
55
+ return ClickHouseInputStream . empty () ;
56
56
}
57
57
58
58
@ Override
59
59
public Iterable <ClickHouseRecord > records () {
60
60
return Collections .emptyList ();
61
61
}
62
62
63
+ @ Override
64
+ public <T > Iterable <T > records (Class <T > objClass ) {
65
+ return Collections .emptyList ();
66
+ }
67
+
63
68
@ Override
64
69
public void close () {
65
70
// do nothing
@@ -93,7 +98,7 @@ public boolean isClosed() {
93
98
* also means additional work is required for deserialization, especially when
94
99
* using a binary format.
95
100
*
96
- * @return input stream for getting raw data returned from server
101
+ * @return non-null input stream for getting raw data returned from server
97
102
*/
98
103
ClickHouseInputStream getInputStream ();
99
104
@@ -109,6 +114,20 @@ default ClickHouseRecord firstRecord() {
109
114
return records ().iterator ().next ();
110
115
}
111
116
117
+ /**
118
+ * Gets the first record as mapped object. Please use {@link #records(Class)}
119
+ * instead if you need to access the rest of records.
120
+ *
121
+ * @param <T> type of the mapped object
122
+ * @param objClass non-null class of the mapped object
123
+ * @return mapped object of the first record
124
+ * @throws NoSuchElementException when there's no record at all
125
+ * @throws UncheckedIOException when failed to read data(e.g. deserialization)
126
+ */
127
+ default <T > T firstRecord (Class <T > objClass ) {
128
+ return records (objClass ).iterator ().next ();
129
+ }
130
+
112
131
/**
113
132
* Returns an iterable collection of records which can be walked through in a
114
133
* foreach loop. Please pay attention that: 1) {@link UncheckedIOException}
@@ -120,6 +139,18 @@ default ClickHouseRecord firstRecord() {
120
139
*/
121
140
Iterable <ClickHouseRecord > records ();
122
141
142
+ /**
143
+ * Returns an iterable collection of mapped objects which can be walked through
144
+ * in a foreach loop. When {@code objClass} is null or {@link ClickHouseRecord},
145
+ * it's same as calling {@link #records()}.
146
+ *
147
+ * @param <T> type of the mapped object
148
+ * @param objClass non-null class of the mapped object
149
+ * @return non-null iterable collection
150
+ * @throws UncheckedIOException when failed to read data(e.g. deserialization)
151
+ */
152
+ <T > Iterable <T > records (Class <T > objClass );
153
+
123
154
/**
124
155
* Pipes the contents of this response into the given output stream. Keep in
125
156
* mind that it's caller's responsibility to flush and close the output stream.
@@ -146,6 +177,16 @@ default Stream<ClickHouseRecord> stream() {
146
177
Spliterator .IMMUTABLE | Spliterator .NONNULL | Spliterator .ORDERED ), false );
147
178
}
148
179
180
+ /**
181
+ * Gets stream of mapped objects to process.
182
+ *
183
+ * @return stream of mapped objects
184
+ */
185
+ default <T > Stream <T > stream (Class <T > objClass ) {
186
+ return StreamSupport .stream (Spliterators .spliteratorUnknownSize (records (objClass ).iterator (),
187
+ Spliterator .IMMUTABLE | Spliterator .NONNULL | Spliterator .ORDERED ), false );
188
+ }
189
+
149
190
@ Override
150
191
void close ();
151
192
0 commit comments