Skip to content

Commit

Permalink
Can officially write sql info
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed Dec 4, 2024
1 parent a219b84 commit 675e745
Show file tree
Hide file tree
Showing 18 changed files with 327 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ public interface IsRowNullProvider<SOURCE_CHUNK_TYPE extends Chunk<Values>> {
protected final int elementSize;
/** whether we can use the wire value as a deephaven null for clients that support dh nulls */
protected final boolean dhNullable;
/** whether the field is nullable */
protected final boolean fieldNullable;

BaseChunkWriter(
@NotNull final IsRowNullProvider<SOURCE_CHUNK_TYPE> isRowNullProvider,
@NotNull final Supplier<SOURCE_CHUNK_TYPE> emptyChunkSupplier,
final int elementSize,
final boolean dhNullable) {
final boolean dhNullable,
final boolean fieldNullable) {
this.isRowNullProvider = isRowNullProvider;
this.emptyChunkSupplier = emptyChunkSupplier;
this.elementSize = elementSize;
this.dhNullable = dhNullable;
this.fieldNullable = fieldNullable;
}

@Override
Expand Down Expand Up @@ -127,12 +131,12 @@ public int available() throws IOException {
* the consumer understands which value is the assigned NULL.
*/
protected boolean sendValidityBuffer() {
return nullCount() != 0;
return !fieldNullable || nullCount() != 0;
}

@Override
public int nullCount() {
return nullCount;
return fieldNullable ? nullCount : 0;
}

protected long writeValidityBuffer(final DataOutput dos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@

public class BooleanChunkWriter extends BaseChunkWriter<ByteChunk<Values>> {
private static final String DEBUG_NAME = "BooleanChunkWriter";
public static final BooleanChunkWriter INSTANCE = new BooleanChunkWriter();
private static final BooleanChunkWriter NULLABLE_IDENTITY_INSTANCE = new BooleanChunkWriter(true);
private static final BooleanChunkWriter NON_NULLABLE_IDENTITY_INSTANCE = new BooleanChunkWriter(false);

public BooleanChunkWriter() {
super(ByteChunk::isNull, ByteChunk::getEmptyChunk, 0, false);
public static BooleanChunkWriter getIdentity(boolean isNullable) {
return isNullable ? NULLABLE_IDENTITY_INSTANCE : NON_NULLABLE_IDENTITY_INSTANCE;
}

private BooleanChunkWriter(final boolean isNullable) {
super(ByteChunk::isNull, ByteChunk::getEmptyChunk, 0, false, isNullable);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@

public class ByteChunkWriter<SOURCE_CHUNK_TYPE extends Chunk<Values>> extends BaseChunkWriter<SOURCE_CHUNK_TYPE> {
private static final String DEBUG_NAME = "ByteChunkWriter";
public static final ByteChunkWriter<ByteChunk<Values>> IDENTITY_INSTANCE = new ByteChunkWriter<>(
ByteChunk::isNull, ByteChunk::getEmptyChunk, ByteChunk::get);
private static final ByteChunkWriter<ByteChunk<Values>> NULLABLE_IDENTITY_INSTANCE = new ByteChunkWriter<>(
ByteChunk::isNull, ByteChunk::getEmptyChunk, ByteChunk::get, false);
private static final ByteChunkWriter<ByteChunk<Values>> NON_NULLABLE_IDENTITY_INSTANCE = new ByteChunkWriter<>(
ByteChunk::isNull, ByteChunk::getEmptyChunk, ByteChunk::get, true);


public static ByteChunkWriter<ByteChunk<Values>> getIdentity(boolean isNullable) {
return isNullable ? NULLABLE_IDENTITY_INSTANCE : NON_NULLABLE_IDENTITY_INSTANCE;
}

@FunctionalInterface
public interface ToByteTransformFunction<SourceChunkType extends Chunk<Values>> {
Expand All @@ -37,8 +44,9 @@ public interface ToByteTransformFunction<SourceChunkType extends Chunk<Values>>
public ByteChunkWriter(
@NotNull final IsRowNullProvider<SOURCE_CHUNK_TYPE> isRowNullProvider,
@NotNull final Supplier<SOURCE_CHUNK_TYPE> emptyChunkSupplier,
@Nullable final ToByteTransformFunction<SOURCE_CHUNK_TYPE> transform) {
super(isRowNullProvider, emptyChunkSupplier, Byte.BYTES, true);
@Nullable final ToByteTransformFunction<SOURCE_CHUNK_TYPE> transform,
final boolean fieldNullable) {
super(isRowNullProvider, emptyChunkSupplier, Byte.BYTES, true, fieldNullable);
this.transform = transform;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@

public class CharChunkWriter<SOURCE_CHUNK_TYPE extends Chunk<Values>> extends BaseChunkWriter<SOURCE_CHUNK_TYPE> {
private static final String DEBUG_NAME = "CharChunkWriter";
public static final CharChunkWriter<CharChunk<Values>> IDENTITY_INSTANCE = new CharChunkWriter<>(
CharChunk::isNull, CharChunk::getEmptyChunk, CharChunk::get);
private static final CharChunkWriter<CharChunk<Values>> NULLABLE_IDENTITY_INSTANCE = new CharChunkWriter<>(
CharChunk::isNull, CharChunk::getEmptyChunk, CharChunk::get, false);
private static final CharChunkWriter<CharChunk<Values>> NON_NULLABLE_IDENTITY_INSTANCE = new CharChunkWriter<>(
CharChunk::isNull, CharChunk::getEmptyChunk, CharChunk::get, true);


public static CharChunkWriter<CharChunk<Values>> getIdentity(boolean isNullable) {
return isNullable ? NULLABLE_IDENTITY_INSTANCE : NON_NULLABLE_IDENTITY_INSTANCE;
}

@FunctionalInterface
public interface ToCharTransformFunction<SourceChunkType extends Chunk<Values>> {
Expand All @@ -33,8 +40,9 @@ public interface ToCharTransformFunction<SourceChunkType extends Chunk<Values>>
public CharChunkWriter(
@NotNull final IsRowNullProvider<SOURCE_CHUNK_TYPE> isRowNullProvider,
@NotNull final Supplier<SOURCE_CHUNK_TYPE> emptyChunkSupplier,
@Nullable final ToCharTransformFunction<SOURCE_CHUNK_TYPE> transform) {
super(isRowNullProvider, emptyChunkSupplier, Character.BYTES, true);
@Nullable final ToCharTransformFunction<SOURCE_CHUNK_TYPE> transform,
final boolean fieldNullable) {
super(isRowNullProvider, emptyChunkSupplier, Character.BYTES, true, fieldNullable);
this.transform = transform;
}

Expand Down
Loading

0 comments on commit 675e745

Please sign in to comment.