1010import io .deephaven .chunk .attributes .Values ;
1111import io .deephaven .chunk .util .pools .PoolableChunk ;
1212import io .deephaven .engine .rowset .RowSet ;
13- import io .deephaven .extensions .barrage .ColumnConversionMode ;
1413import io .deephaven .extensions .barrage .util .DefensiveDrainable ;
1514import io .deephaven .extensions .barrage .util .StreamReaderOptions ;
1615import io .deephaven .time .DateTimeUtils ;
1918import io .deephaven .chunk .Chunk ;
2019import io .deephaven .chunk .ChunkType ;
2120import io .deephaven .util .SafeCloseable ;
22- import io .deephaven .util .type .TypeUtils ;
2321import io .deephaven .vector .Vector ;
2422import org .jetbrains .annotations .Nullable ;
2523
3129import java .time .LocalDate ;
3230import java .time .LocalTime ;
3331import java .time .ZonedDateTime ;
34- import java .util .Arrays ;
3532import java .util .Iterator ;
3633import java .util .PrimitiveIterator ;
3734
@@ -187,6 +184,7 @@ static <T> ChunkInputStreamGenerator makeInputStreamGenerator(
187184 }
188185 }
189186
187+ @ Deprecated
190188 static WritableChunk <Values > extractChunkFromInputStream (
191189 final StreamReaderOptions options ,
192190 final ChunkType chunkType , final Class <?> type , final Class <?> componentType ,
@@ -195,10 +193,10 @@ static WritableChunk<Values> extractChunkFromInputStream(
195193 final DataInput is ,
196194 final WritableChunk <Values > outChunk , final int offset , final int totalRows ) throws IOException {
197195 return extractChunkFromInputStream (options , 1 , chunkType , type , componentType , fieldNodeIter , bufferInfoIter ,
198- is ,
199- outChunk , offset , totalRows );
196+ is , outChunk , offset , totalRows );
200197 }
201198
199+ @ Deprecated
202200 static WritableChunk <Values > extractChunkFromInputStream (
203201 final StreamReaderOptions options ,
204202 final int factor ,
@@ -207,170 +205,9 @@ static WritableChunk<Values> extractChunkFromInputStream(
207205 final PrimitiveIterator .OfLong bufferInfoIter ,
208206 final DataInput is ,
209207 final WritableChunk <Values > outChunk , final int outOffset , final int totalRows ) throws IOException {
210- // TODO (deephaven-core#5453): pass in ArrowType to enable ser/deser of single java class in multiple formats
211- switch (chunkType ) {
212- case Boolean :
213- throw new UnsupportedOperationException ("Booleans are reinterpreted as bytes" );
214- case Char :
215- return CharChunkInputStreamGenerator .extractChunkFromInputStream (
216- Character .BYTES , options , fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
217- case Byte :
218- if (type == Boolean .class || type == boolean .class ) {
219- return BooleanChunkInputStreamGenerator .extractChunkFromInputStream (
220- options , fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
221- }
222- return ByteChunkInputStreamGenerator .extractChunkFromInputStream (
223- Byte .BYTES , options , fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
224- case Short :
225- return ShortChunkInputStreamGenerator .extractChunkFromInputStream (
226- Short .BYTES , options , fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
227- case Int :
228- return IntChunkInputStreamGenerator .extractChunkFromInputStream (
229- Integer .BYTES , options , fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
230- case Long :
231- if (factor == 1 ) {
232- return LongChunkInputStreamGenerator .extractChunkFromInputStream (
233- Long .BYTES , options ,
234- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
235- }
236- return LongChunkInputStreamGenerator .extractChunkFromInputStreamWithConversion (
237- Long .BYTES , options ,
238- (long v ) -> v == QueryConstants .NULL_LONG ? QueryConstants .NULL_LONG : (v * factor ),
239- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
240- case Float :
241- return FloatChunkInputStreamGenerator .extractChunkFromInputStream (
242- Float .BYTES , options , fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
243- case Double :
244- return DoubleChunkInputStreamGenerator .extractChunkFromInputStream (
245- Double .BYTES , options , fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
246- case Object :
247- if (type .isArray ()) {
248- if (componentType == byte .class ) {
249- return VarBinaryChunkInputStreamGenerator .extractChunkFromInputStream (
250- is ,
251- fieldNodeIter ,
252- bufferInfoIter ,
253- (buf , off , len ) -> Arrays .copyOfRange (buf , off , off + len ),
254- outChunk , outOffset , totalRows );
255- } else {
256- return VarListChunkInputStreamGenerator .extractChunkFromInputStream (
257- options , type , fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
258- }
259- }
260- if (Vector .class .isAssignableFrom (type )) {
261- // noinspection unchecked
262- return VectorChunkInputStreamGenerator .extractChunkFromInputStream (
263- options , (Class <Vector <?>>) type , componentType , fieldNodeIter , bufferInfoIter , is ,
264- outChunk , outOffset , totalRows );
265- }
266- if (type == BigInteger .class ) {
267- return VarBinaryChunkInputStreamGenerator .extractChunkFromInputStream (
268- is ,
269- fieldNodeIter ,
270- bufferInfoIter ,
271- BigInteger ::new ,
272- outChunk , outOffset , totalRows );
273- }
274- if (type == BigDecimal .class ) {
275- return VarBinaryChunkInputStreamGenerator .extractChunkFromInputStream (
276- is ,
277- fieldNodeIter ,
278- bufferInfoIter ,
279- (final byte [] buf , final int offset , final int length ) -> {
280- // read the int scale value as little endian, arrow's endianness.
281- final byte b1 = buf [offset ];
282- final byte b2 = buf [offset + 1 ];
283- final byte b3 = buf [offset + 2 ];
284- final byte b4 = buf [offset + 3 ];
285- final int scale = b4 << 24 | (b3 & 0xFF ) << 16 | (b2 & 0xFF ) << 8 | (b1 & 0xFF );
286- return new BigDecimal (new BigInteger (buf , offset + 4 , length - 4 ), scale );
287- },
288- outChunk , outOffset , totalRows );
289- }
290- if (type == Instant .class ) {
291- return FixedWidthChunkInputStreamGenerator .extractChunkFromInputStreamWithTypeConversion (
292- Long .BYTES , options , io -> {
293- final long value = io .readLong ();
294- if (value == QueryConstants .NULL_LONG ) {
295- return null ;
296- }
297- return DateTimeUtils .epochNanosToInstant (value * factor );
298- },
299- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
300- }
301- if (type == ZonedDateTime .class ) {
302- return FixedWidthChunkInputStreamGenerator .extractChunkFromInputStreamWithTypeConversion (
303- Long .BYTES , options , io -> {
304- final long value = io .readLong ();
305- if (value == QueryConstants .NULL_LONG ) {
306- return null ;
307- }
308- return DateTimeUtils .epochNanosToZonedDateTime (
309- value * factor , DateTimeUtils .timeZone ());
310- },
311- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
312- }
313- if (type == Byte .class ) {
314- return FixedWidthChunkInputStreamGenerator .extractChunkFromInputStreamWithTypeConversion (
315- Byte .BYTES , options , io -> TypeUtils .box (io .readByte ()),
316- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
317- }
318- if (type == Character .class ) {
319- return FixedWidthChunkInputStreamGenerator .extractChunkFromInputStreamWithTypeConversion (
320- Character .BYTES , options , io -> TypeUtils .box (io .readChar ()),
321- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
322- }
323- if (type == Double .class ) {
324- return FixedWidthChunkInputStreamGenerator .extractChunkFromInputStreamWithTypeConversion (
325- Double .BYTES , options , io -> TypeUtils .box (io .readDouble ()),
326- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
327- }
328- if (type == Float .class ) {
329- return FixedWidthChunkInputStreamGenerator .extractChunkFromInputStreamWithTypeConversion (
330- Float .BYTES , options , io -> TypeUtils .box (io .readFloat ()),
331- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
332- }
333- if (type == Integer .class ) {
334- return FixedWidthChunkInputStreamGenerator .extractChunkFromInputStreamWithTypeConversion (
335- Integer .BYTES , options , io -> TypeUtils .box (io .readInt ()),
336- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
337- }
338- if (type == Long .class ) {
339- return FixedWidthChunkInputStreamGenerator .extractChunkFromInputStreamWithTypeConversion (
340- Long .BYTES , options , io -> TypeUtils .box (io .readLong ()),
341- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
342- }
343- if (type == Short .class ) {
344- return FixedWidthChunkInputStreamGenerator .extractChunkFromInputStreamWithTypeConversion (
345- Short .BYTES , options , io -> TypeUtils .box (io .readShort ()),
346- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
347- }
348- if (type == LocalDate .class ) {
349- return LongChunkInputStreamGenerator .extractChunkFromInputStreamWithTransform (
350- Long .BYTES , options ,
351- value -> value == QueryConstants .NULL_LONG
352- ? null
353- : LocalDate .ofEpochDay (value / MS_PER_DAY ),
354- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
355- }
356- if (type == LocalTime .class ) {
357- return LongChunkInputStreamGenerator .extractChunkFromInputStreamWithTransform (
358- Long .BYTES , options ,
359- value -> value == QueryConstants .NULL_LONG ? null : LocalTime .ofNanoOfDay (value ),
360- fieldNodeIter , bufferInfoIter , is , outChunk , outOffset , totalRows );
361- }
362- if (type == String .class ||
363- options .columnConversionMode ().equals (ColumnConversionMode .Stringify )) {
364- return VarBinaryChunkInputStreamGenerator .extractChunkFromInputStream (is , fieldNodeIter ,
365- bufferInfoIter ,
366- (buf , off , len ) -> new String (buf , off , len , Charsets .UTF_8 ), outChunk , outOffset ,
367- totalRows );
368- }
369- throw new UnsupportedOperationException (
370- "Do not yet support column conversion mode: " + options .columnConversionMode ());
371- default :
372- throw new UnsupportedOperationException ();
373- }
208+ return DefaultChunkReadingFactory .INSTANCE .extractChunkFromInputStream (options , factor ,
209+ new ChunkReadingFactory .ChunkTypeInfo (chunkType , type , componentType , null ), fieldNodeIter ,
210+ bufferInfoIter , is , outChunk , outOffset , totalRows );
374211 }
375212
376213 /**
0 commit comments