Skip to content

Commit 825d1e1

Browse files
committed
RTT tests:
rtt for arrow Duration type Fix FMRTT#testLongColumnWithFactor rtt for Time rtt for Date incomplete Interval
1 parent da44dde commit 825d1e1

File tree

5 files changed

+567
-145
lines changed

5 files changed

+567
-145
lines changed

extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/DefaultChunkReaderFactory.java

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ protected DefaultChunkReaderFactory() {
147147
register(ArrowType.ArrowTypeID.FixedSizeBinary, ByteBuffer.class,
148148
DefaultChunkReaderFactory::fixedSizeBinaryToByteBuffer);
149149
register(ArrowType.ArrowTypeID.Date, LocalDate.class, DefaultChunkReaderFactory::dateToLocalDate);
150-
register(ArrowType.ArrowTypeID.Interval, long.class, DefaultChunkReaderFactory::intervalToDurationLong);
151150
register(ArrowType.ArrowTypeID.Interval, Duration.class, DefaultChunkReaderFactory::intervalToDuration);
152151
register(ArrowType.ArrowTypeID.Interval, Period.class, DefaultChunkReaderFactory::intervalToPeriod);
153152
register(ArrowType.ArrowTypeID.Interval, PeriodDuration.class,
@@ -1630,38 +1629,6 @@ private static ChunkReader<WritableObjectChunk<LocalDate, Values>> dateToLocalDa
16301629
}
16311630
}
16321631

1633-
private static ChunkReader<WritableLongChunk<Values>> intervalToDurationLong(
1634-
final ArrowType arrowType,
1635-
final BarrageTypeInfo<Field> typeInfo,
1636-
final BarrageOptions options) {
1637-
// See intervalToPeriod's comment for more information on wire format.
1638-
1639-
final ArrowType.Interval intervalType = (ArrowType.Interval) arrowType;
1640-
switch (intervalType.getUnit()) {
1641-
case YEAR_MONTH:
1642-
case MONTH_DAY_NANO:
1643-
throw Exceptions.statusRuntimeException(Code.INVALID_ARGUMENT, String.format(
1644-
"Do not support %s interval to Duration as long conversion", intervalType));
1645-
1646-
case DAY_TIME:
1647-
return LongChunkReader
1648-
.transformFrom(new FixedWidthChunkReader<>(Integer.BYTES * 2, false, options, dataInput -> {
1649-
final int days = dataInput.readInt();
1650-
final int millis = dataInput.readInt();
1651-
return Duration.ofDays(days).plusMillis(millis);
1652-
}), (src, dst, dstOffset) -> {
1653-
for (int ii = 0; ii < src.size(); ++ii) {
1654-
final Duration value = src.get(ii);
1655-
dst.set(dstOffset + ii, value == null ? QueryConstants.NULL_LONG : value.toNanos());
1656-
}
1657-
});
1658-
1659-
default:
1660-
throw Exceptions.statusRuntimeException(Code.INVALID_ARGUMENT,
1661-
"Unexpected interval unit: " + intervalType.getUnit());
1662-
}
1663-
}
1664-
16651632
private static ChunkReader<WritableObjectChunk<Duration, Values>> intervalToDuration(
16661633
final ArrowType arrowType,
16671634
final BarrageTypeInfo<Field> typeInfo,
@@ -1676,7 +1643,7 @@ private static ChunkReader<WritableObjectChunk<Duration, Values>> intervalToDura
16761643
"Do not support %s interval to Duration conversion", intervalType));
16771644

16781645
case DAY_TIME:
1679-
return new FixedWidthChunkReader<>(Integer.BYTES * 2 + Long.BYTES, false, options, dataInput -> {
1646+
return new FixedWidthChunkReader<>(Integer.BYTES * 2, false, options, dataInput -> {
16801647
final int days = dataInput.readInt();
16811648
final int millis = dataInput.readInt();
16821649
return Duration.ofDays(days).plusMillis(millis);

extensions/barrage/src/main/java/io/deephaven/extensions/barrage/chunk/DefaultChunkWriterFactory.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,8 +1501,12 @@ protected void writePayload(
15011501
@NotNull final DataOutput dos,
15021502
@NotNull final RowSequence subset) {
15031503
final ObjectChunk<byte[], Values> objectChunk = context.getChunk().asObjectChunk();
1504+
final byte[] nullValue = new byte[elementWidth];
15041505
subset.forAllRowKeys(row -> {
1505-
final byte[] data = objectChunk.get((int) row);
1506+
byte[] data = objectChunk.get((int) row);
1507+
if (data == null) {
1508+
data = nullValue;
1509+
}
15061510
if (data.length != elementWidth) {
15071511
throw new IllegalArgumentException(String.format(
15081512
"Expected fixed size binary of %d bytes, but got %d bytes when serializing %s",
@@ -1531,8 +1535,10 @@ protected void writePayload(
15311535
@NotNull final DataOutput dos,
15321536
@NotNull final RowSequence subset) {
15331537
final ObjectChunk<ByteVector, Values> objectChunk = context.getChunk().asObjectChunk();
1538+
final byte[] nullValue = new byte[elementWidth];
15341539
subset.forAllRowKeys(row -> {
1535-
final byte[] data = objectChunk.get((int) row).toArray();
1540+
final ByteVector rowValue = objectChunk.get((int) row);
1541+
final byte[] data = rowValue == null ? nullValue : rowValue.toArray();
15361542
if (data.length != elementWidth) {
15371543
throw new IllegalArgumentException(String.format(
15381544
"Expected fixed size binary of %d bytes, but got %d bytes when serializing %s",
@@ -1561,8 +1567,10 @@ protected void writePayload(
15611567
@NotNull final DataOutput dos,
15621568
@NotNull final RowSequence subset) {
15631569
final ObjectChunk<ByteBuffer, Values> objectChunk = context.getChunk().asObjectChunk();
1570+
final byte[] nullValue = new byte[elementWidth];
15641571
subset.forAllRowKeys(row -> {
1565-
final byte[] data = objectChunk.get((int) row).array();
1572+
final ByteBuffer rowValue = objectChunk.get((int) row);
1573+
final byte[] data = rowValue == null ? nullValue : rowValue.array();
15661574
if (data.length != elementWidth) {
15671575
throw new IllegalArgumentException(String.format(
15681576
"Expected fixed size binary of %d bytes, but got %d bytes when serializing %s",

extensions/barrage/src/main/java/io/deephaven/extensions/barrage/util/BarrageUtil.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.apache.arrow.flatbuf.KeyValue;
5858
import org.apache.arrow.flatbuf.Message;
5959
import org.apache.arrow.util.Collections2;
60+
import org.apache.arrow.vector.PeriodDuration;
6061
import org.apache.arrow.vector.types.TimeUnit;
6162
import org.apache.arrow.vector.types.Types;
6263
import org.apache.arrow.vector.types.pojo.ArrowType;
@@ -72,9 +73,11 @@
7273
import java.lang.reflect.Method;
7374
import java.math.BigDecimal;
7475
import java.math.BigInteger;
76+
import java.time.Duration;
7577
import java.time.Instant;
7678
import java.time.LocalDate;
7779
import java.time.LocalTime;
80+
import java.time.Period;
7881
import java.time.ZonedDateTime;
7982
import java.util.Arrays;
8083
import java.util.BitSet;
@@ -549,7 +552,11 @@ private static Class<?> getDefaultType(
549552
}
550553
return boolean.class;
551554
case Duration:
552-
return long.class;
555+
return Duration.class;
556+
case Time:
557+
return LocalTime.class;
558+
case Date:
559+
return LocalDate.class;
553560
case Timestamp:
554561
final ArrowType.Timestamp timestampType = (ArrowType.Timestamp) arrowField.getType();
555562
final String tz = timestampType.getTimezone();
@@ -571,12 +578,32 @@ private static Class<?> getDefaultType(
571578
return explicitType;
572579
}
573580
throw Exceptions.statusRuntimeException(Code.INVALID_ARGUMENT, exMsg +
574-
" of floatingPointType(Precision=" + floatingPointType.getPrecision().toString() + ")");
581+
" of floatingPointType(Precision=" + floatingPointType.getPrecision() + ")");
575582
}
576583
case Decimal:
577584
return BigDecimal.class;
578585
case Utf8:
579586
return java.lang.String.class;
587+
case Binary:
588+
case FixedSizeBinary:
589+
return byte[].class;
590+
case Interval:
591+
final ArrowType.Interval intervalType = (ArrowType.Interval) arrowField.getType();
592+
switch (intervalType.getUnit()) {
593+
case DAY_TIME:
594+
return Duration.class;
595+
case YEAR_MONTH:
596+
return Period.class;
597+
case MONTH_DAY_NANO:
598+
return PeriodDuration.class;
599+
default:
600+
if (explicitType != null) {
601+
return explicitType;
602+
}
603+
throw Exceptions.statusRuntimeException(Code.INVALID_ARGUMENT, exMsg +
604+
" of intervalType(IntervalUnit=" + intervalType.getUnit() + ")");
605+
}
606+
580607
default:
581608
if (explicitType != null) {
582609
return explicitType;

0 commit comments

Comments
 (0)