Skip to content

Commit

Permalink
JavaClient: Encode Packed Booleans Instead of Reinterpretted Bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed May 8, 2023
1 parent 184720e commit f56c4cf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
1 change: 1 addition & 0 deletions java-client/flight/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ description = 'The Deephaven client flight library'
dependencies {
api project(':java-client-session')
implementation project(':proto:proto-backplane-grpc-flight')
implementation project(':qst')

Classpaths.inheritArrow(project, 'flight-core', 'api')
Classpaths.inheritArrow(project, 'flight-grpc', 'implementation')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public static Field byteField(String name) {
}

public static Field booleanField(String name) {
// TODO(deephaven-core#43): Do not reinterpret bool as byte
return field(name, MinorType.TINYINT.getType(), "boolean");
return field(name, MinorType.BIT.getType(), "boolean");
}

public static Field charField(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@
import io.deephaven.qst.type.InstantType;
import io.deephaven.qst.type.StringType;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.BigIntVector;
import org.apache.arrow.vector.FieldVector;
import org.apache.arrow.vector.Float4Vector;
import org.apache.arrow.vector.Float8Vector;
import org.apache.arrow.vector.IntVector;
import org.apache.arrow.vector.SmallIntVector;
import org.apache.arrow.vector.TimeStampNanoTZVector;
import org.apache.arrow.vector.TinyIntVector;
import org.apache.arrow.vector.UInt2Vector;
import org.apache.arrow.vector.VarCharVector;
import org.apache.arrow.vector.*;
import org.apache.arrow.vector.types.pojo.Field;

import java.time.Instant;
Expand Down Expand Up @@ -118,9 +109,8 @@ public void visit(ByteArray byteArray) {

@Override
public void visit(BooleanArray booleanArray) {
// TODO(deephaven-core#43): Do not reinterpret bool as byte
Field field = FieldAdapter.booleanField(name);
TinyIntVector vector = new TinyIntVector(field, allocator);
BitVector vector = new BitVector(field, allocator);
VectorHelper.fill(vector, booleanArray.values(), 0, booleanArray.size());
out = vector;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@
*/
package io.deephaven.client.impl;

import org.apache.arrow.vector.BigIntVector;
import org.apache.arrow.vector.Float4Vector;
import org.apache.arrow.vector.Float8Vector;
import org.apache.arrow.vector.IntVector;
import org.apache.arrow.vector.SmallIntVector;
import org.apache.arrow.vector.TimeStampNanoTZVector;
import org.apache.arrow.vector.TinyIntVector;
import org.apache.arrow.vector.UInt2Vector;
import org.apache.arrow.vector.VarCharVector;
import io.deephaven.qst.array.Util;
import org.apache.arrow.vector.*;

import java.nio.charset.StandardCharsets;
import java.time.Instant;
Expand All @@ -30,6 +23,14 @@ public static void fill(TinyIntVector vector, byte[] array, int offset, int len)
vector.setValueCount(len);
}

public static void fill(BitVector vector, byte[] array, int offset, int len) {
vector.allocateNew(len);
for (int i = 0; i < len; i++) {
vector.set(i, array[offset + i] != Util.NULL_BOOL ? 1 : 0, array[offset + i] == Util.TRUE_BOOL ? 1 : 0);
}
vector.setValueCount(len);
}

public static void fill(UInt2Vector vector, char[] array, int offset, int len) {
vector.allocateNew(len);
for (int i = 0; i < len; i++) {
Expand Down
8 changes: 4 additions & 4 deletions qst/src/main/java/io/deephaven/qst/array/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
*/
package io.deephaven.qst.array;

class Util {
public class Util {
static final int DEFAULT_BUILDER_INITIAL_CAPACITY = 16;

// TODO(deephaven-core#895): Consolidate NULL_X paths

static final byte NULL_BYTE = Byte.MIN_VALUE;

static final byte NULL_BOOL = NULL_BYTE;
static final byte TRUE_BOOL = (byte) 1;
static final byte FALSE_BOOL = (byte) 0;
public static final byte NULL_BOOL = NULL_BYTE;
public static final byte TRUE_BOOL = (byte) 1;
public static final byte FALSE_BOOL = (byte) 0;

static final char NULL_CHAR = Character.MAX_VALUE;

Expand Down

0 comments on commit f56c4cf

Please sign in to comment.