From e872f06104356472b50782108bacc31471eb708a Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Thu, 11 Jul 2024 19:07:43 -0500 Subject: [PATCH 1/3] refactor!: Remove gnu.trove from RowSet API (#5730) Removes usages of gnu.trove from the API of rowset related classes. These usages were previously unused, though this is technically an API breaking change. Partial #188 Co-authored-by: Ryan Caudy --- engine/rowset/build.gradle | 2 +- .../rowset/RowKeyRangeShiftCallback.java | 20 ++ .../io/deephaven/engine/rowset/RowSet.java | 10 - .../rowset/RowSetBuilderSequential.java | 9 +- .../engine/rowset/RowSetFactory.java | 17 -- .../engine/rowset/RowSetShiftCallback.java | 17 ++ .../engine/rowset/RowSetShiftData.java | 25 +- .../rowset/impl/WritableRowSetImpl.java | 6 - .../table/impl/TableUpdateValidator.java | 11 +- .../impl/sources/ArrayBackedColumnSource.java | 17 +- .../impl/sources/BooleanArraySource.java | 13 - .../table/impl/sources/ByteArraySource.java | 13 - .../impl/sources/CharacterArraySource.java | 13 - .../table/impl/sources/DoubleArraySource.java | 13 - .../table/impl/sources/FloatArraySource.java | 13 - .../impl/sources/IntegerArraySource.java | 13 - .../table/impl/sources/LongArraySource.java | 13 - .../sources/NanosBasedTimeArraySource.java | 8 +- .../NanosBasedTimeSparseArraySource.java | 4 +- .../impl/sources/NullValueColumnSource.java | 6 +- .../table/impl/sources/ShortArraySource.java | 13 - .../impl/sources/SingleValueColumnSource.java | 8 +- .../impl/sources/SparseArrayColumnSource.java | 4 +- .../ImmutableConstantByteSource.java | 6 +- .../ImmutableConstantCharSource.java | 6 +- .../ImmutableConstantDoubleSource.java | 6 +- .../ImmutableConstantFloatSource.java | 6 +- .../immutable/ImmutableConstantIntSource.java | 6 +- .../ImmutableConstantLongSource.java | 6 +- ...ImmutableConstantNanosBasedTimeSource.java | 6 +- .../ImmutableConstantObjectSource.java | 6 +- .../ImmutableConstantShortSource.java | 6 +- .../engine/table/impl/util/ShiftData.java | 142 --------- .../table/impl/util/RowSetShiftDataTest.java | 2 +- .../engine/table/impl/util/ShiftDataTest.java | 271 ------------------ 35 files changed, 69 insertions(+), 668 deletions(-) create mode 100644 engine/rowset/src/main/java/io/deephaven/engine/rowset/RowKeyRangeShiftCallback.java create mode 100644 engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftCallback.java delete mode 100644 engine/table/src/main/java/io/deephaven/engine/table/impl/util/ShiftData.java delete mode 100644 engine/table/src/test/java/io/deephaven/engine/table/impl/util/ShiftDataTest.java diff --git a/engine/rowset/build.gradle b/engine/rowset/build.gradle index ae24b9d782a..98106f51682 100644 --- a/engine/rowset/build.gradle +++ b/engine/rowset/build.gradle @@ -8,7 +8,7 @@ description 'Engine RowSets: Data structures for working with row keys' dependencies { api project(':engine-chunk') api project(':Base') - api libs.trove + implementation libs.trove implementation project(':Container') implementation project(':engine-context') diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowKeyRangeShiftCallback.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowKeyRangeShiftCallback.java new file mode 100644 index 00000000000..32b76b23994 --- /dev/null +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowKeyRangeShiftCallback.java @@ -0,0 +1,20 @@ +// +// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending +// +package io.deephaven.engine.rowset; + +/** + * Functional interface to pass to {@link RowSetShiftData#apply(RowKeyRangeShiftCallback)} or + * {@link RowSetShiftData#unapply(RowKeyRangeShiftCallback)} to get information about each shift recorded. + */ +@FunctionalInterface +public interface RowKeyRangeShiftCallback { + /** + * Process the shift. + * + * @param beginRange start of range (inclusive) + * @param endRange end of range (inclusive) + * @param shiftDelta amount range has moved by + */ + void shift(long beginRange, long endRange, long shiftDelta); +} diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSet.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSet.java index 1859a0f8c69..20eb6a7c3fc 100644 --- a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSet.java +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSet.java @@ -3,7 +3,6 @@ // package io.deephaven.engine.rowset; -import gnu.trove.list.array.TLongArrayList; import io.deephaven.base.log.LogOutputAppendable; import io.deephaven.util.SafeCloseable; import io.deephaven.util.datastructures.LongAbortableConsumer; @@ -116,15 +115,6 @@ default WritableRowSet invert(RowSet keys) { */ WritableRowSet invert(RowSet keys, long maximumPosition); - /** - * For the given keys RowSet, under the assertion that none of them are present in the current RowSet, return the - * tentative insertion points in the current RowSet with the count for each of them - * - * @param keys the keys to identify insertion locations - * @return two TLongArrayLists; [0] contains the positions, [1] contains the counts. - */ - TLongArrayList[] findMissing(RowSet keys); - /** * Returns a new RowSet representing the intersection of the current RowSet with the input RowSet */ diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetBuilderSequential.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetBuilderSequential.java index e678a514e51..aad8cad51ba 100644 --- a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetBuilderSequential.java +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetBuilderSequential.java @@ -3,7 +3,6 @@ // package io.deephaven.engine.rowset; -import gnu.trove.procedure.TLongProcedure; import io.deephaven.engine.rowset.chunkattributes.OrderedRowKeyRanges; import io.deephaven.engine.rowset.chunkattributes.OrderedRowKeys; import io.deephaven.util.datastructures.LongRangeConsumer; @@ -17,7 +16,7 @@ /** * Builder interface for {@link RowSet} construction in strict sequential order. */ -public interface RowSetBuilderSequential extends TLongProcedure, LongRangeConsumer { +public interface RowSetBuilderSequential extends LongRangeConsumer { /** * Hint to call, but if called, (a) should be called before providing any values, and (b) no value should be @@ -61,12 +60,6 @@ default void appendOrderedRowKeyRangesChunk(final LongChunk appendRanges(new LongChunkRangeIterator(chunk)); } - @Override - default boolean execute(final long value) { - appendKey(value); - return true; - } - /** * Appends a {@link RowSequence} to this builder. * diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetFactory.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetFactory.java index 78c620c661b..a6b7d6dd91e 100644 --- a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetFactory.java +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetFactory.java @@ -3,12 +3,10 @@ // package io.deephaven.engine.rowset; -import gnu.trove.list.TLongList; import io.deephaven.engine.rowset.impl.AdaptiveRowSetBuilderRandom; import io.deephaven.engine.rowset.impl.BasicRowSetBuilderSequential; import io.deephaven.engine.rowset.impl.WritableRowSetImpl; import io.deephaven.engine.rowset.impl.singlerange.SingleRange; -import org.jetbrains.annotations.NotNull; /** * Repository of factory methods for constructing {@link WritableRowSet row sets}. @@ -56,21 +54,6 @@ public static WritableRowSet fromKeys(final long rowKey) { return fromRange(rowKey, rowKey); } - /** - * Get a {@link WritableRowSet} containing the specified row keys. - *

- * The provided {@link TLongList} is sorted and then passed to a {@link RowSetBuilderSequential}. - * - * @param rowKeys A {@link TLongList}. Note that this list is mutated within the method! - * @return A new {@link WritableRowSet} containing the values from {@code rowKeys} - */ - public static RowSet fromKeys(@NotNull final TLongList rowKeys) { - rowKeys.sort(); - final RowSetBuilderSequential builder = builderSequential(); - rowKeys.forEach(builder); - return builder.build(); - } - /** * Create a {@link WritableRowSet} containing the continuous range [firstRowKey, lastRowKey]. * diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftCallback.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftCallback.java new file mode 100644 index 00000000000..08e0c7685b3 --- /dev/null +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftCallback.java @@ -0,0 +1,17 @@ +// +// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending +// +package io.deephaven.engine.rowset; + +/** + * Callback interface for propagating shifts over entire {@link RowSet RowSets}. + */ +public interface RowSetShiftCallback { + /** + * Signals that the row keys in {@code rowSet} should be shifted by the provided {@code shiftDelta}. + * + * @param rowSet The row keys to shift + * @param shiftDelta The shift delta to apply to each row key in {@code rowSet} + */ + void shift(RowSet rowSet, long shiftDelta); +} diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftData.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftData.java index 9e1c20247b1..8db68e8e0fe 100644 --- a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftData.java +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftData.java @@ -18,10 +18,11 @@ import java.io.Serializable; /** - * A set of sorted shifts. To apply shifts without losing data, use {@link RowSetShiftData#apply(Callback)}. The - * callback will be invoked with shifts in an order that will preserve data when applied immediately using memmove - * semantics. Internally the shifts are ordered by rangeStart. The {@link RowSetShiftData.Builder} will verify that no - * two ranges overlap before or after shifting and assert that the constructed {@code RowSetShiftData} will be valid. + * A set of sorted shifts. To apply shifts without losing data, use + * {@link RowSetShiftData#apply(RowKeyRangeShiftCallback)}. The callback will be invoked with shifts in an order that + * will preserve data when applied immediately using memmove semantics. Internally the shifts are ordered by rangeStart. + * The {@link RowSetShiftData.Builder} will verify that no two ranges overlap before or after shifting and assert that + * the constructed {@code RowSetShiftData} will be valid. */ public final class RowSetShiftData implements Serializable, LogOutputAppendable { @@ -224,18 +225,6 @@ public boolean equals(final Object obj) { */ public static final RowSetShiftData EMPTY = new RowSetShiftData(); - @FunctionalInterface - public interface Callback { - /** - * Process the shift. - * - * @param beginRange start of range (inclusive) - * @param endRange end of range (inclusive) - * @param shiftDelta amount range has moved by - */ - void shift(long beginRange, long endRange, long shiftDelta); - } - /** * Apply all shifts in a memmove-semantics-safe ordering through the provided {@code shiftCallback}. *

@@ -243,7 +232,7 @@ public interface Callback { * * @param shiftCallback the callback that will process all shifts */ - public void apply(final Callback shiftCallback) { + public void apply(final RowKeyRangeShiftCallback shiftCallback) { final int polaritySwapSize = polaritySwapIndices.size(); for (int idx = 0; idx < polaritySwapSize; ++idx) { int start = (idx == 0) ? 0 : polaritySwapIndices.get(idx - 1); @@ -267,7 +256,7 @@ public void apply(final Callback shiftCallback) { * * @param shiftCallback the callback that will process all reverse shifts */ - public void unapply(final Callback shiftCallback) { + public void unapply(final RowKeyRangeShiftCallback shiftCallback) { final int polaritySwapSize = polaritySwapIndices.size(); for (int idx = 0; idx < polaritySwapSize; ++idx) { int start = (idx == 0) ? 0 : polaritySwapIndices.get(idx - 1); diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/impl/WritableRowSetImpl.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/impl/WritableRowSetImpl.java index 1d4ced7aae8..487d9bae220 100644 --- a/engine/rowset/src/main/java/io/deephaven/engine/rowset/impl/WritableRowSetImpl.java +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/impl/WritableRowSetImpl.java @@ -3,7 +3,6 @@ // package io.deephaven.engine.rowset.impl; -import gnu.trove.list.array.TLongArrayList; import io.deephaven.base.log.LogOutput; import io.deephaven.base.verify.Assert; import io.deephaven.engine.rowset.*; @@ -260,11 +259,6 @@ public final WritableRowSet invert(final RowSet keys, final long maximumPosition return new WritableRowSetImpl(innerSet.ixInvertOnNew(getInnerSet(keys), maximumPosition)); } - @Override - public final TLongArrayList[] findMissing(final RowSet keys) { - return RowSetUtils.findMissing(this, keys); - } - @NotNull @Override public final WritableRowSet intersect(@NotNull final RowSet range) { diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/TableUpdateValidator.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/TableUpdateValidator.java index c09fa9ce61d..b4f9b7e817b 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/TableUpdateValidator.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/TableUpdateValidator.java @@ -10,14 +10,14 @@ import io.deephaven.chunk.attributes.Values; import io.deephaven.chunk.util.hashing.ChunkEquals; import io.deephaven.configuration.Configuration; +import io.deephaven.engine.rowset.RowKeyRangeShiftCallback; import io.deephaven.engine.rowset.RowSequence; import io.deephaven.engine.rowset.RowSet; -import io.deephaven.engine.rowset.RowSetShiftData; import io.deephaven.engine.rowset.TrackingWritableRowSet; import io.deephaven.engine.table.*; import io.deephaven.engine.table.impl.sources.SparseArrayColumnSource; import io.deephaven.engine.table.impl.util.ChunkUtils; -import io.deephaven.engine.table.impl.util.ShiftData; +import io.deephaven.engine.rowset.RowSetShiftCallback; import io.deephaven.util.SafeCloseable; import io.deephaven.util.SafeCloseableList; import io.deephaven.vector.*; @@ -325,7 +325,7 @@ public void dontValidateColumns(String[] columnNames) { columnInfos = ciBuilder.toArray(new ColumnInfo[0]); } - private class ColumnInfo implements RowSetShiftData.Callback, SafeCloseable { + private class ColumnInfo implements RowKeyRangeShiftCallback, SafeCloseable { final String name; final boolean isPrimitive; final ModifiedColumnSet modifiedColumnSet; @@ -351,7 +351,7 @@ private ColumnInfo(QueryTable tableToValidate, String columnName) { this.isPrimitive = source.getType().isPrimitive(); this.expectedSource = SparseArrayColumnSource.getSparseMemoryColumnSource(source.getType(), source.getComponentType()); - Assert.eqTrue(this.expectedSource instanceof ShiftData.RowSetShiftCallback, + Assert.eqTrue(this.expectedSource instanceof RowSetShiftCallback, "expectedSource instanceof ShiftData.RowSetShiftCallback"); this.chunkEquals = ChunkEquals.makeEqual(source.getChunkType()); @@ -401,8 +401,7 @@ private WritableBooleanChunk equalValuesDest() { @Override public void shift(final long beginRange, final long endRange, final long shiftDelta) { - ((ShiftData.RowSetShiftCallback) expectedSource).shift( - rowSet.subSetByKeyRange(beginRange, endRange), shiftDelta); + ((RowSetShiftCallback) expectedSource).shift(rowSet.subSetByKeyRange(beginRange, endRange), shiftDelta); } public void remove(final RowSet toRemove) { diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ArrayBackedColumnSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ArrayBackedColumnSource.java index 0d5fda89395..090cb61677c 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ArrayBackedColumnSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ArrayBackedColumnSource.java @@ -14,7 +14,6 @@ import io.deephaven.chunk.attributes.Values; import io.deephaven.engine.rowset.RowSequence; import io.deephaven.engine.rowset.RowSequenceFactory; -import io.deephaven.engine.table.impl.util.ShiftData; import io.deephaven.qst.array.Array; import io.deephaven.qst.array.BooleanArray; import io.deephaven.qst.array.ByteArray; @@ -47,7 +46,7 @@ */ public abstract class ArrayBackedColumnSource extends AbstractColumnSource - implements FillUnordered, ShiftData.ShiftCallback, WritableColumnSource, InMemoryColumnSource, + implements FillUnordered, WritableColumnSource, InMemoryColumnSource, ChunkedBackingStoreExposedWritableSource { static final int DEFAULT_RECYCLER_CAPACITY = 1024; @@ -426,20 +425,6 @@ public static WritableColumnSource getMemoryColumnSource(final long size, @Override public abstract void ensureCapacity(long size, boolean nullFill); - @Override - public void shift(final long start, final long end, final long offset) { - if (offset > 0) { - for (long i = end; i >= start; i--) { - set((i + offset), get(i)); - } - } else { - for (long i = start; i <= end; i++) { - set((i + offset), get(i)); - } - } - - } - /** * Creates an in-memory ColumnSource from the supplied dataArray, using instanceof checks to determine the * appropriate type of column source to produce. diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/BooleanArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/BooleanArraySource.java index f7a5760fe24..72e41f33e71 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/BooleanArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/BooleanArraySource.java @@ -196,19 +196,6 @@ public Boolean getPrev(long rowKey) { return BooleanUtils.byteAsBoolean(getPrevByte(rowKey)); } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getByte(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getByte(i)); - } - } - } - @Override byte[] allocateNullFilledBlock(int size) { final byte[] result = new byte[size]; diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ByteArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ByteArraySource.java index 76693de2f90..03a29432654 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ByteArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ByteArraySource.java @@ -193,19 +193,6 @@ public final byte getPrevByte(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getByte(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getByte(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/CharacterArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/CharacterArraySource.java index 088cc63a4ef..fbbc84ed6dc 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/CharacterArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/CharacterArraySource.java @@ -190,19 +190,6 @@ public final char getPrevChar(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getChar(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getChar(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/DoubleArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/DoubleArraySource.java index 2343325982d..74a523a1e73 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/DoubleArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/DoubleArraySource.java @@ -193,19 +193,6 @@ public final double getPrevDouble(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getDouble(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getDouble(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/FloatArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/FloatArraySource.java index bd01ec0ee0e..5579e8d2159 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/FloatArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/FloatArraySource.java @@ -193,19 +193,6 @@ public final float getPrevFloat(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getFloat(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getFloat(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/IntegerArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/IntegerArraySource.java index b4172cc7794..07a4f676c33 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/IntegerArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/IntegerArraySource.java @@ -193,19 +193,6 @@ public final int getPrevInt(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getInt(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getInt(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/LongArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/LongArraySource.java index 2cbb16cd130..5296629e4d0 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/LongArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/LongArraySource.java @@ -216,19 +216,6 @@ public final long getPrevLong(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getLong(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getLong(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeArraySource.java index 0d91720ef27..e351b8da09f 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeArraySource.java @@ -16,13 +16,12 @@ import io.deephaven.engine.table.WritableColumnSource; import io.deephaven.engine.table.WritableSourceWithPrepareForParallelPopulation; import io.deephaven.engine.table.impl.AbstractColumnSource; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import java.time.*; public abstract class NanosBasedTimeArraySource extends AbstractColumnSource - implements FillUnordered, ShiftData.ShiftCallback, WritableColumnSource, + implements FillUnordered, WritableColumnSource, InMemoryColumnSource, WritableSourceWithPrepareForParallelPopulation, ConvertibleTimeSource { protected final LongArraySource nanoSource; @@ -79,11 +78,6 @@ public long getPrevLong(long rowKey) { public final long getAndSetUnsafe(long rowKey, long newValue) { return nanoSource.getAndSetUnsafe(rowKey, newValue); } - - @Override - public void shift(long start, long end, long offset) { - nanoSource.shift(start, end, offset); - } // endregion // region ArraySource impl diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeSparseArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeSparseArraySource.java index 02abc54a547..30d4e490a9b 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeSparseArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeSparseArraySource.java @@ -16,7 +16,7 @@ import io.deephaven.engine.table.WritableColumnSource; import io.deephaven.engine.table.WritableSourceWithPrepareForParallelPopulation; import io.deephaven.engine.table.impl.AbstractColumnSource; -import io.deephaven.engine.table.impl.util.ShiftData; +import io.deephaven.engine.rowset.RowSetShiftCallback; import org.jetbrains.annotations.NotNull; import java.time.Instant; @@ -30,7 +30,7 @@ */ public abstract class NanosBasedTimeSparseArraySource extends AbstractColumnSource implements FillUnordered, WritableColumnSource, InMemoryColumnSource, - PossiblyImmutableColumnSource, WritableSourceWithPrepareForParallelPopulation, ShiftData.RowSetShiftCallback, + PossiblyImmutableColumnSource, WritableSourceWithPrepareForParallelPopulation, RowSetShiftCallback, ConvertibleTimeSource { protected final LongSparseArraySource nanoSource; diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NullValueColumnSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NullValueColumnSource.java index aec4b545db7..2c2e873e58d 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NullValueColumnSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NullValueColumnSource.java @@ -18,7 +18,6 @@ import io.deephaven.hash.KeyedObjectHashMap; import io.deephaven.hash.KeyedObjectKey; import io.deephaven.chunk.WritableChunk; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,7 +36,7 @@ * A column source that returns null for all keys. Trivially "writable" since it can only contain null values. */ public final class NullValueColumnSource extends AbstractColumnSource - implements ShiftData.ShiftCallback, InMemoryColumnSource, RowKeyAgnosticChunkSource, + implements InMemoryColumnSource, RowKeyAgnosticChunkSource, WritableColumnSource { private static final KeyedObjectKey.Basic, Class>, NullValueColumnSource> KEY_TYPE = @@ -167,9 +166,6 @@ public short getPrevShort(long rowKey) { return NULL_SHORT; } - @Override - public void shift(long start, long end, long offset) {} - @Override public boolean isImmutable() { return true; diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ShortArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ShortArraySource.java index 928b9ec20bf..6ac23b0db31 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ShortArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ShortArraySource.java @@ -193,19 +193,6 @@ public final short getPrevShort(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getShort(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getShort(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SingleValueColumnSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SingleValueColumnSource.java index dadb09f9be4..bf343470884 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SingleValueColumnSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SingleValueColumnSource.java @@ -8,12 +8,9 @@ import io.deephaven.engine.table.ChunkSink; import io.deephaven.engine.table.WritableColumnSource; import io.deephaven.engine.table.impl.AbstractColumnSource; -import io.deephaven.engine.table.impl.util.ShiftData; - -import static io.deephaven.util.QueryConstants.NULL_BYTE; public abstract class SingleValueColumnSource extends AbstractColumnSource - implements WritableColumnSource, ChunkSink, ShiftData.ShiftCallback, InMemoryColumnSource, + implements WritableColumnSource, ChunkSink, InMemoryColumnSource, RowKeyAgnosticChunkSource { protected transient long changeTime; @@ -28,9 +25,6 @@ public final void startTrackingPrevValues() { isTrackingPrevValues = true; } - @Override - public void shift(long start, long end, long offset) {} - public static SingleValueColumnSource getSingleValueColumnSource(Class type) { SingleValueColumnSource result; if (type == Byte.class || type == byte.class) { diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SparseArrayColumnSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SparseArrayColumnSource.java index d67858056f9..2394e07c17e 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SparseArrayColumnSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SparseArrayColumnSource.java @@ -8,7 +8,7 @@ import io.deephaven.engine.table.WritableColumnSource; import io.deephaven.engine.table.WritableSourceWithPrepareForParallelPopulation; import io.deephaven.engine.table.impl.AbstractColumnSource; -import io.deephaven.engine.table.impl.util.ShiftData; +import io.deephaven.engine.rowset.RowSetShiftCallback; import io.deephaven.util.type.ArrayTypeUtils; import io.deephaven.engine.rowset.chunkattributes.RowKeys; import io.deephaven.chunk.attributes.Values; @@ -74,7 +74,7 @@ public abstract class SparseArrayColumnSource extends AbstractColumnSource implements FillUnordered, WritableColumnSource, InMemoryColumnSource, PossiblyImmutableColumnSource, - WritableSourceWithPrepareForParallelPopulation, ShiftData.RowSetShiftCallback { + WritableSourceWithPrepareForParallelPopulation, RowSetShiftCallback { static final int DEFAULT_RECYCLER_CAPACITY = 1024; diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantByteSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantByteSource.java index 6e8b5e8a813..05475da83ae 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantByteSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantByteSource.java @@ -18,7 +18,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -32,7 +31,7 @@ */ public class ImmutableConstantByteSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForByte, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForByte, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final byte value; @@ -70,9 +69,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantCharSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantCharSource.java index 0788b2cb9c3..9ea61d9946d 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantCharSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantCharSource.java @@ -12,7 +12,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -26,7 +25,7 @@ */ public class ImmutableConstantCharSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForChar, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForChar, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final char value; @@ -64,9 +63,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantDoubleSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantDoubleSource.java index c75d5f2faba..75c3dd0b441 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantDoubleSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantDoubleSource.java @@ -16,7 +16,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -30,7 +29,7 @@ */ public class ImmutableConstantDoubleSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForDouble, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForDouble, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final double value; @@ -68,9 +67,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantFloatSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantFloatSource.java index 81e961dbfec..9b895d41bdd 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantFloatSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantFloatSource.java @@ -16,7 +16,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -30,7 +29,7 @@ */ public class ImmutableConstantFloatSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForFloat, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForFloat, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final float value; @@ -68,9 +67,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantIntSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantIntSource.java index ea4a6a8a82c..e9fd8c3938c 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantIntSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantIntSource.java @@ -16,7 +16,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -30,7 +29,7 @@ */ public class ImmutableConstantIntSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForInt, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForInt, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final int value; @@ -68,9 +67,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantLongSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantLongSource.java index 7d9e322f6d3..14c235bd509 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantLongSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantLongSource.java @@ -25,7 +25,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -39,7 +38,7 @@ */ public class ImmutableConstantLongSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForLong, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForLong, InMemoryColumnSource, RowKeyAgnosticChunkSource , ConvertibleTimeSource { private final long value; @@ -77,9 +76,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantNanosBasedTimeSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantNanosBasedTimeSource.java index 075b786b412..bf55d4f5fde 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantNanosBasedTimeSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantNanosBasedTimeSource.java @@ -13,7 +13,6 @@ import io.deephaven.engine.table.ColumnSource; import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import java.time.Instant; @@ -23,7 +22,7 @@ import java.time.ZonedDateTime; public abstract class ImmutableConstantNanosBasedTimeSource extends AbstractColumnSource - implements ShiftData.ShiftCallback, InMemoryColumnSource, RowKeyAgnosticChunkSource, + implements InMemoryColumnSource, RowKeyAgnosticChunkSource, ConvertibleTimeSource { protected final ImmutableConstantLongSource nanoSource; @@ -61,9 +60,6 @@ public long getLong(long rowKey) { public long getPrevLong(long rowKey) { return nanoSource.getPrevLong(rowKey); } - - @Override - public final void shift(final long start, final long end, final long offset) {} // endregion // region Chunking diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantObjectSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantObjectSource.java index 5971e14e61f..952559d98fd 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantObjectSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantObjectSource.java @@ -16,7 +16,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -29,7 +28,7 @@ */ public class ImmutableConstantObjectSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForObject, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForObject, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final T value; @@ -67,9 +66,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantShortSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantShortSource.java index cdf53c08c05..95eb2ea4989 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantShortSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantShortSource.java @@ -16,7 +16,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -30,7 +29,7 @@ */ public class ImmutableConstantShortSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForShort, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForShort, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final short value; @@ -68,9 +67,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/util/ShiftData.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/util/ShiftData.java deleted file mode 100644 index 1e3f9859561..00000000000 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/util/ShiftData.java +++ /dev/null @@ -1,142 +0,0 @@ -// -// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending -// -package io.deephaven.engine.table.impl.util; - -import gnu.trove.list.TLongList; -import gnu.trove.list.array.TLongArrayList; -import io.deephaven.engine.rowset.RowSet; - -public class ShiftData { - - private final TLongArrayList startIndex; - private final TLongArrayList endIndex; - private final TLongArrayList offsets; - private final int size; - private int runningSize = 0; - private long runningOffset = 0; - - public RowSet getAddedPos() { - return addedPos; - } - - private RowSet addedPos; - - public ShiftData(RowSet rowSet, RowSet removed, RowSet added) { - TLongList[] removedKeys = rowSet.findMissing(removed); - addedPos = rowSet.invert(added); - endIndex = new TLongArrayList(); - startIndex = new TLongArrayList(); - offsets = new TLongArrayList(); - int removedIndex = 0; - TLongList removedPositions = removedKeys[0]; - TLongList removedCount = removedKeys[1]; - for (RowSet.RangeIterator addedIt = addedPos.rangeIterator(); addedIt.hasNext();) { - addedIt.next(); - int startOffset = (int) addedIt.currentRangeStart(); - int endOffset = (int) addedIt.currentRangeEnd(); - while (removedIndex < removedPositions.size() && removedPositions.get(removedIndex) < startOffset) { - removeRange(removedPositions.get(removedIndex), removedCount.get(removedIndex)); - removedIndex++; - } - int deleteCount = 0; - while (removedIndex < removedPositions.size() && removedPositions.get(removedIndex) <= endOffset) { - deleteCount += removedCount.get(removedIndex); - removedIndex++; - } - addRange(startOffset, endOffset, deleteCount); - } - while (removedIndex < removedPositions.size()) { - removeRange(removedPositions.get(removedIndex), removedCount.get(removedIndex)); - removedIndex++; - } - if (runningSize > 0) { - if (startIndex.get(runningSize - 1) <= (rowSet.size() - added.size() + removed.size() - 1)) { - endIndex.set(runningSize - 1, (int) (rowSet.size() - added.size() + removed.size() - 1)); - } else { - runningSize--; - } - } - size = runningSize; - } - - void addRange(long firstIndex, long lastIndex, long deletionCount) { - if (lastIndex - firstIndex + 1 == deletionCount) { - return; - } - if (runningSize > 0) { - endIndex.set(runningSize - 1, firstIndex - runningOffset - 1); - } - - - long newStartIndex = firstIndex + deletionCount - runningOffset; - runningOffset = lastIndex + runningOffset + 1 - (deletionCount + firstIndex); - - if (runningSize > 0 && ((newStartIndex + runningOffset) == (startIndex.get(runningSize - 1) - + offsets.get(runningSize - 1)))) { - startIndex.set(runningSize - 1, newStartIndex); - offsets.set(runningSize - 1, runningOffset); - } else { - startIndex.add(newStartIndex); - offsets.add(runningOffset); - endIndex.add(0); - runningSize++; - } - } - - void removeRange(long firstIndex, long count) { - if (runningSize > 0) { - endIndex.set(runningSize - 1, firstIndex - runningOffset - 1); - } - - long newStartIndex = firstIndex - runningOffset + count; - runningOffset = runningOffset - count; - - if (runningSize > 0 - && (newStartIndex + runningOffset == startIndex.get(runningSize - 1) + offsets.get(runningSize - 1))) { - startIndex.set(runningSize - 1, newStartIndex); - offsets.set(runningSize - 1, runningOffset); - } else { - startIndex.add(newStartIndex); - offsets.add(runningOffset); - endIndex.add(0); - runningSize++; - } - } - - public interface ShiftCallback { - void shift(long start, long end, long offset); - } - - public interface RowSetShiftCallback { - void shift(RowSet rowSet, long offset); - } - - public void applyDataShift(ShiftCallback shiftCallback) { - int startPos = 0; - int currentPos = 0; - while (currentPos < size) { - if (offsets.get(startPos) > 0) { - while (currentPos < size && offsets.get(currentPos) > 0) { - currentPos++; - } - for (int ii = currentPos - 1; ii >= startPos; ii--) { - shiftCallback.shift(startIndex.get(ii), endIndex.get(ii), offsets.get(ii)); - } - } else if (offsets.get(startPos) < 0) { - while (currentPos < size && offsets.get(currentPos) < 0) { - currentPos++; - } - for (int ii = startPos; ii < currentPos; ii++) { - shiftCallback.shift(startIndex.get(ii), endIndex.get(ii), offsets.get(ii)); - } - } else { - while (currentPos < size && offsets.get(currentPos) == 0) { - currentPos++; - } - } - startPos = currentPos; - } - } - -} diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/util/RowSetShiftDataTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/util/RowSetShiftDataTest.java index 97ec38f5cea..2e8e68934a8 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/util/RowSetShiftDataTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/util/RowSetShiftDataTest.java @@ -458,7 +458,7 @@ private long[] fromValues(long... values) { return values; } - private RowSetShiftData.Callback createMemMovCallback(final long[] arr) { + private RowKeyRangeShiftCallback createMemMovCallback(final long[] arr) { return (start, end, delta) -> { final long dir = (delta > 0) ? -1 : 1; if (dir < 0) { diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/util/ShiftDataTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/util/ShiftDataTest.java deleted file mode 100644 index 1e3573b9567..00000000000 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/util/ShiftDataTest.java +++ /dev/null @@ -1,271 +0,0 @@ -// -// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending -// -package io.deephaven.engine.table.impl.util; - -import io.deephaven.engine.rowset.RowSet; -import io.deephaven.engine.rowset.RowSetBuilderRandom; -import io.deephaven.engine.rowset.RowSetBuilderSequential; -import io.deephaven.engine.rowset.RowSetFactory; -import junit.framework.TestCase; - -import java.util.*; - -public class ShiftDataTest extends TestCase { - - public void testSystematic() { - RowSet rowSet = getSortedIndex(); - RowSet removed = getSortedIndex(); - RowSet added = getSortedIndex(); - ShiftData shiftData = new ShiftData(rowSet, removed, added); - shiftData.applyDataShift(new ShiftData.ShiftCallback() { - @Override - public void shift(long start, long end, long offset) { - assertTrue("Should not call it", false); - } - }); - rowSet = getSortedIndex(1L); - testNoNotification(rowSet, removed, added); - added = getSortedIndex(1L); - testNoNotification(rowSet, removed, added); - rowSet = getSortedIndex(1L, 2); - added = getSortedIndex(1L, 2); - testNoNotification(rowSet, removed, added); - - rowSet = getSortedIndex(1L, 2, 3); - added = getSortedIndex(2, 3); - testNoNotification(rowSet, removed, added); - - removed = getSortedIndex(4, 5); - testNoNotification(rowSet, removed, added); - - rowSet = getSortedIndex(); - added = getSortedIndex(); - removed = getSortedIndex(4, 5); - testNoNotification(rowSet, removed, added); - - rowSet = getSortedIndex(1L, 2, 4); - added = getSortedIndex(2); - removed = getSortedIndex(3); - testNoNotification(rowSet, removed, added); - - rowSet = getSortedIndex(1L, 3, 4); - added = getSortedIndex(3); - removed = getSortedIndex(2); - testNoNotification(rowSet, removed, added); - - rowSet = getSortedIndex(); - added = getSortedIndex(); - removed = getSortedIndex(1, 2, 4); - testNoNotification(rowSet, removed, added); - - - rowSet = getSortedIndex(4); - added = getSortedIndex(); - removed = getSortedIndex(1); - checkExpectations(rowSet, removed, added, new long[][] {{1, 1, -1}}); - - rowSet = getSortedIndex(4, 5); - added = getSortedIndex(4); - removed = getSortedIndex(); - checkExpectations(rowSet, removed, added, new long[][] {{0, 0, 1}}); - - rowSet = getSortedIndex(4, 5, 6, 7); - added = getSortedIndex(4); - removed = getSortedIndex(); - checkExpectations(rowSet, removed, added, new long[][] {{0, 2, 1}}); - - rowSet = getSortedIndex(4, 5, 6, 7); - added = getSortedIndex(4, 5); - removed = getSortedIndex(); - checkExpectations(rowSet, removed, added, new long[][] {{0, 1, 2}}); - - rowSet = getSortedIndex(4, 5, 6, 7); - added = getSortedIndex(5, 6); - removed = getSortedIndex(); - checkExpectations(rowSet, removed, added, new long[][] {{1, 1, 2}}); - // was 1,4,7 - rowSet = getSortedIndex(4, 5, 6, 7); - added = getSortedIndex(5, 6); - removed = getSortedIndex(1); - checkExpectations(rowSet, removed, added, new long[][] {{1, 1, -1}, {2, 2, 1}}); - - // was 1,2,4,6,7 - rowSet = getSortedIndex(4, 5, 6, 7); - added = getSortedIndex(5); - removed = getSortedIndex(1, 2); - checkExpectations(rowSet, removed, added, new long[][] {{2, 2, -2}, {3, 4, -1}}); - - // was 6,7,9,11 - rowSet = getSortedIndex(4, 5, 9, 10, 11); - added = getSortedIndex(4, 5, 10); - removed = getSortedIndex(6, 7); - checkExpectations(rowSet, removed, added, new long[][] {{3, 3, 1}}); - - // was 6,7,9,11 - rowSet = getSortedIndex(4, 9, 10, 11); - added = getSortedIndex(4, 10); - removed = getSortedIndex(6, 7); - checkExpectations(rowSet, removed, added, new long[][] {{2, 2, -1}}); - - // was 2,4,6,8 - rowSet = getSortedIndex(1, 2, 3, 4, 5, 6, 7, 8); - added = getSortedIndex(1, 3, 5, 7); - removed = getSortedIndex(); - checkExpectations(rowSet, removed, added, new long[][] {{3, 3, 4}, {2, 2, 3}, {1, 1, 2}, {0, 0, 1}}); - - // was 2,4,6,8,10,12,16 - rowSet = getSortedIndex(1, 2, 3, 4, 8, 16); - added = getSortedIndex(1, 3); - removed = getSortedIndex(6, 10, 12); - checkExpectations(rowSet, removed, added, new long[][] {{3, 3, 1}, {1, 1, 2}, {0, 0, 1}, {6, 6, -1}}); - - // was 100,200,300,400,500,600,700 - rowSet = getSortedIndex(100, 200, 230, 240, 250, 260, 270, 500, 550, 700); - added = getSortedIndex(230, 240, 250, 260, 270, 550); - removed = getSortedIndex(300, 400, 600); - checkExpectations(rowSet, removed, added, new long[][] {{6, 6, 3}, {4, 4, 3}}); - } - - private void checkExpectations(RowSet rowSet, RowSet removed, RowSet added, long[][] expected) { - ShiftData shiftData; - class Expectations implements ShiftData.ShiftCallback { - - private final long[][] expected; - private int i = 0; - - Expectations(long[][] expected) { - this.expected = expected; - } - - @Override - public void shift(long start, long end, long offset) { - long[] current = expected[i++]; - assertEquals(current[0], start); - assertEquals(current[1], end); - assertEquals(current[2], offset); - } - - public void allMet() { - assertEquals(i, expected.length); - } - } - shiftData = new ShiftData(rowSet, removed, added); - final Expectations expectations = new Expectations(expected); - shiftData.applyDataShift(expectations); - expectations.allMet(); - } - - private void testNoNotification(RowSet rowSet, RowSet removed, RowSet added) { - ShiftData shiftData; - shiftData = new ShiftData(rowSet, removed, added); - shiftData.applyDataShift(new ShiftData.ShiftCallback() { - @Override - public void shift(long start, long end, long offset) { - assertTrue("Should not call it", false); - } - }); - } - - Random random = new Random(123); - - public void testRandom() { - for (int k = 0; k < 100; k++) { - RowSet initialRowSet = getBaseIndex(100, 10); - RowSet added = getRandomIndex(20, 1, 10); - RowSet removed = getRandomRemoves(initialRowSet, 2); - RowSet finalRowSet = getFinalIndex(initialRowSet, added, removed); - final long resultKeys[] = new long[(int) Math.max(initialRowSet.size(), finalRowSet.size())]; - int pos = 0; - for (RowSet.Iterator it = initialRowSet.iterator(); it.hasNext();) { - resultKeys[pos++] = it.nextLong(); - } - ShiftData shiftData = new ShiftData(finalRowSet, removed, added); - shiftData.applyDataShift(new ShiftData.ShiftCallback() { - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (int i = (int) end; i >= start; i--) { - resultKeys[((int) (i + offset))] = resultKeys[i]; - } - } else { - for (int i = (int) start; i <= end; i++) { - resultKeys[((int) (i + offset))] = resultKeys[i]; - } - } - } - }); - RowSet addedPos = shiftData.getAddedPos(); - - for (RowSet.Iterator iterator = addedPos.iterator(), valueIt = added.iterator(); iterator.hasNext();) { - resultKeys[((int) iterator.nextLong())] = valueIt.nextLong(); - } - - pos = 0; - for (RowSet.Iterator iterator = finalRowSet.iterator(); iterator.hasNext();) { - assertEquals(iterator.nextLong(), resultKeys[pos++]); - } - } - } - - private RowSet getFinalIndex(RowSet initialRowSet, RowSet added, RowSet removed) { - TreeSet finalKeys = new TreeSet(); - for (RowSet.Iterator iterator = initialRowSet.iterator(); iterator.hasNext();) { - Long next = iterator.nextLong(); - finalKeys.add(next); - } - for (RowSet.Iterator iterator = removed.iterator(); iterator.hasNext();) { - Long next = iterator.nextLong(); - finalKeys.remove(next); - } - for (RowSet.Iterator iterator = added.iterator(); iterator.hasNext();) { - Long next = iterator.nextLong(); - finalKeys.add(next); - } - RowSetBuilderRandom builder = RowSetFactory.builderRandom(); - for (Long finalKey : finalKeys) { - builder.addKey(finalKey); - } - return builder.build(); - } - - private RowSet getRandomRemoves(RowSet rowSet, int prob) { - RowSetBuilderRandom builder = RowSetFactory.builderRandom(); - for (RowSet.Iterator iterator = rowSet.iterator(); iterator.hasNext();) { - long next = iterator.nextLong(); - if (random.nextInt(prob) == 0) { - builder.addKey(next); - } - } - return builder.build(); - } - - - private RowSet getBaseIndex(int base, int size) { - RowSetBuilderSequential builder = RowSetFactory.builderSequential(); - for (int i = 0; i < size; i++) { - builder.appendKey(i * size); - } - return builder.build(); - } - - private RowSet getRandomIndex(int base, int offset, int size) { - RowSetBuilderRandom builder = RowSetFactory.builderRandom(); - for (int i = 0; i < size; i++) { - if (random.nextInt(2) == 0) { - builder.addKey(i * base + offset); - } - } - return builder.build(); - } - - - protected RowSet getSortedIndex(long... keys) { - RowSetBuilderRandom builder = RowSetFactory.builderRandom(); - for (long key : keys) { - builder.addKey(key); - } - return builder.build(); - } - -} From 3171feffc1123498b4e6c6e8d335de3efecfa841 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Jul 2024 09:08:11 -0700 Subject: [PATCH 2/3] chore(gradle): bump javax.annotation:javax.annotation-api from 1.3.1 to 1.3.2 (#5762) Bumps [javax.annotation:javax.annotation-api](https://github.com/javaee/javax.annotation) from 1.3.1 to 1.3.2.

Commits
  • 5000694 [maven-release-plugin] prepare release 1.3.2
  • 6e026c3 Revert the maven plugin changes
  • b830155 [maven-release-plugin] prepare release 1.3.2
  • 82038fc Modified POM to add Javadoc and GPG plugin
  • 8b6e48e Revert the maven plugin changes
  • fa04c4e [maven-release-plugin] prepare release 1.3.2
  • 5c4f8e4 Merge pull request #2 from jayasheelankumar/master
  • 15ed457 Modifying Copyright with Latest URL
  • 62c945c [maven-release-plugin] prepare for next development iteration
  • See full diff in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=javax.annotation:javax.annotation-api&package-manager=gradle&previous-version=1.3.1&new-version=1.3.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8764c0f7d04..480e2ac1310 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -45,7 +45,7 @@ jakarta-servlet = "5.0.0" jakarta-websocket = "2.0.0" jama = "1.1.1" javaparser = "3.23.0" -javax-annotation = "1.3.1" +javax-annotation = "1.3.2" javax-inject = "1" javax-validation = "1.0.0.GA" jdom2 = "2.0.6.1" From 4fdad152ba3a1b37eb45e657d59d15c8f73ae45c Mon Sep 17 00:00:00 2001 From: Andrew <3199649+abaranec@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:43:46 -0400 Subject: [PATCH 3/3] feat: Extract Codec & friends from Util into separate modules (#5727) This fixes #5726 by removing ObjectCodec and ObjectDecoder, their implementations, as well as CodecCache and it's exception from the Util module and into their own separate packages, codec-base, codec-builtin and codec-cache. --- codec/api/build.gradle | 10 ++++ codec/api/gradle.properties | 1 + .../io/deephaven/util/codec/ObjectCodec.java | 6 +- .../deephaven/util/codec/ObjectDecoder.java | 8 ++- codec/builtin/build.gradle | 17 ++++++ codec/builtin/gradle.properties | 1 + .../deephaven/util/codec/BigDecimalCodec.java | 20 +++---- .../deephaven/util/codec/BigIntegerCodec.java | 7 +-- .../io/deephaven/util/codec/CodecUtil.java | 59 ++----------------- .../util/codec/ExternalizableCodec.java | 11 ++-- .../deephaven/util/codec/LocalDateCodec.java | 5 +- .../deephaven/util/codec/LocalTimeCodec.java | 5 +- .../io/deephaven/util/codec/MapCodec.java | 11 ++-- .../util/codec/SerializableCodec.java | 5 +- .../util/codec/SimpleByteArrayCodec.java | 9 +-- .../util/codec/StringBooleanMapCodec.java | 0 .../util/codec/StringDoubleMapCodec.java | 0 .../util/codec/StringFloatMapCodec.java | 0 .../util/codec/StringIntMapCodec.java | 0 .../util/codec/StringKeyedMapCodec.java | 6 +- .../util/codec/StringLongMapCodec.java | 0 .../util/codec/StringStringMapCodec.java | 5 +- .../codec/UTF8StringAsByteArrayCodec.java | 5 +- .../util/codec/ZonedDateTimeCodec.java | 8 +-- .../util/codec/BigDecimalCodecTest.java | 0 .../util/codec/BigIntegerCodecTest.java | 0 .../util/codec/LocalDateCodecTest.java | 0 .../util/codec/LocalTimeCodecTest.java | 0 .../util/codec/ZonedDateTimeCodecTest.java | 4 +- codec/cache/build.gradle | 12 ++++ codec/cache/gradle.properties | 1 + .../io/deephaven/util/codec/CodecCache.java | 32 +--------- .../util/codec/CodecCacheException.java | 0 engine/chunk/build.gradle | 7 ++- engine/table/build.gradle | 3 + extensions/parquet/base/build.gradle | 1 + extensions/parquet/table/build.gradle | 5 +- settings.gradle | 7 +++ 38 files changed, 116 insertions(+), 155 deletions(-) create mode 100644 codec/api/build.gradle create mode 100644 codec/api/gradle.properties rename {Util => codec/api}/src/main/java/io/deephaven/util/codec/ObjectCodec.java (89%) rename {Util => codec/api}/src/main/java/io/deephaven/util/codec/ObjectDecoder.java (90%) create mode 100644 codec/builtin/build.gradle create mode 100644 codec/builtin/gradle.properties rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/BigDecimalCodec.java (92%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/BigIntegerCodec.java (90%) rename Util/src/main/java/io/deephaven/util/EncodingUtil.java => codec/builtin/src/main/java/io/deephaven/util/codec/CodecUtil.java (54%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/ExternalizableCodec.java (84%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/LocalDateCodec.java (97%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/LocalTimeCodec.java (97%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/MapCodec.java (93%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/SerializableCodec.java (93%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/SimpleByteArrayCodec.java (88%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/StringBooleanMapCodec.java (100%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/StringDoubleMapCodec.java (100%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/StringFloatMapCodec.java (100%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/StringIntMapCodec.java (100%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/StringKeyedMapCodec.java (88%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/StringLongMapCodec.java (100%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/StringStringMapCodec.java (89%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/UTF8StringAsByteArrayCodec.java (93%) rename {Util => codec/builtin}/src/main/java/io/deephaven/util/codec/ZonedDateTimeCodec.java (90%) rename {Util => codec/builtin}/src/test/java/io/deephaven/util/codec/BigDecimalCodecTest.java (100%) rename {Util => codec/builtin}/src/test/java/io/deephaven/util/codec/BigIntegerCodecTest.java (100%) rename {Util => codec/builtin}/src/test/java/io/deephaven/util/codec/LocalDateCodecTest.java (100%) rename {Util => codec/builtin}/src/test/java/io/deephaven/util/codec/LocalTimeCodecTest.java (100%) rename {Util => codec/builtin}/src/test/java/io/deephaven/util/codec/ZonedDateTimeCodecTest.java (97%) create mode 100644 codec/cache/build.gradle create mode 100644 codec/cache/gradle.properties rename {Util => codec/cache}/src/main/java/io/deephaven/util/codec/CodecCache.java (69%) rename {Util => codec/cache}/src/main/java/io/deephaven/util/codec/CodecCacheException.java (100%) diff --git a/codec/api/build.gradle b/codec/api/build.gradle new file mode 100644 index 00000000000..8de35953673 --- /dev/null +++ b/codec/api/build.gradle @@ -0,0 +1,10 @@ +plugins { + id 'java-library' + id 'io.deephaven.project.register' +} + +description 'Codec API: The base package for column codecs' + +dependencies { + compileOnly libs.jetbrains.annotations +} diff --git a/codec/api/gradle.properties b/codec/api/gradle.properties new file mode 100644 index 00000000000..c186bbfdde1 --- /dev/null +++ b/codec/api/gradle.properties @@ -0,0 +1 @@ +io.deephaven.project.ProjectType=JAVA_PUBLIC diff --git a/Util/src/main/java/io/deephaven/util/codec/ObjectCodec.java b/codec/api/src/main/java/io/deephaven/util/codec/ObjectCodec.java similarity index 89% rename from Util/src/main/java/io/deephaven/util/codec/ObjectCodec.java rename to codec/api/src/main/java/io/deephaven/util/codec/ObjectCodec.java index e1c96338778..def0542d264 100644 --- a/Util/src/main/java/io/deephaven/util/codec/ObjectCodec.java +++ b/codec/api/src/main/java/io/deephaven/util/codec/ObjectCodec.java @@ -24,14 +24,12 @@ public interface ObjectCodec extends ObjectDecoder { /** * Encode the specified input as an array of bytes. Note that it is up to the implementation how to encode null - * inputs. The use of a zero-length byte array (e.g. - * {@link io.deephaven.datastructures.util.CollectionUtil#ZERO_LENGTH_BYTE_ARRAY}) is strongly encouraged. + * inputs. The use of a zero-length byte array is strongly encouraged. * * @param input The input object, possibly null * @return The output byte array */ - @NotNull - byte[] encode(@Nullable TYPE input); + byte @NotNull [] encode(@Nullable TYPE input); /** * Does this codec support encoding of null values? diff --git a/Util/src/main/java/io/deephaven/util/codec/ObjectDecoder.java b/codec/api/src/main/java/io/deephaven/util/codec/ObjectDecoder.java similarity index 90% rename from Util/src/main/java/io/deephaven/util/codec/ObjectDecoder.java rename to codec/api/src/main/java/io/deephaven/util/codec/ObjectDecoder.java index 72728684abd..033a7b876f4 100644 --- a/Util/src/main/java/io/deephaven/util/codec/ObjectDecoder.java +++ b/codec/api/src/main/java/io/deephaven/util/codec/ObjectDecoder.java @@ -3,7 +3,6 @@ // package io.deephaven.util.codec; -import io.deephaven.base.verify.Assert; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,7 +35,7 @@ public interface ObjectDecoder { * @return The output object, possibly null */ @Nullable - TYPE decode(@NotNull byte[] input, int offset, int length); + TYPE decode(byte @NotNull [] input, int offset, int length); /** * Decode an object from a ByteBuffer. The position of the input buffer may or may not be modified by this method. @@ -72,6 +71,9 @@ default TYPE decode(@NotNull final ByteBuffer buffer) { */ default void checkWidth(int actualWidth) throws IllegalArgumentException { final int expectedWidth = expectedObjectWidth(); - Assert.eq(expectedWidth, "expectedWidth", actualWidth, "actualWidth"); + if (expectedWidth != actualWidth) { + throw new IllegalArgumentException( + "Expected width `" + expectedWidth + "` does not match actual width `" + actualWidth + "`"); + } } } diff --git a/codec/builtin/build.gradle b/codec/builtin/build.gradle new file mode 100644 index 00000000000..055cd8de79e --- /dev/null +++ b/codec/builtin/build.gradle @@ -0,0 +1,17 @@ +plugins { + id 'java-library' + id 'io.deephaven.project.register' +} + +description 'Codec Builtin: Deephaven builtin codec implementations' + +dependencies { + api project(":codec-api") + + implementation project(":Base") + implementation project(":engine-query-constants") + + compileOnly libs.jetbrains.annotations + + testImplementation libs.junit4 +} diff --git a/codec/builtin/gradle.properties b/codec/builtin/gradle.properties new file mode 100644 index 00000000000..c186bbfdde1 --- /dev/null +++ b/codec/builtin/gradle.properties @@ -0,0 +1 @@ +io.deephaven.project.ProjectType=JAVA_PUBLIC diff --git a/Util/src/main/java/io/deephaven/util/codec/BigDecimalCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/BigDecimalCodec.java similarity index 92% rename from Util/src/main/java/io/deephaven/util/codec/BigDecimalCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/BigDecimalCodec.java index 697b9acfa50..2f0d9fcdfa2 100644 --- a/Util/src/main/java/io/deephaven/util/codec/BigDecimalCodec.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/BigDecimalCodec.java @@ -3,7 +3,6 @@ // package io.deephaven.util.codec; -import io.deephaven.datastructures.util.CollectionUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -73,18 +72,18 @@ public BigDecimalCodec(@Nullable String arguments) { try { int _precision = 0, _scale = 0; // zero indicates unlimited precision/scale, variable width encoding boolean _strict = true; - if (arguments != null && arguments.trim().length() > 0) { + if (arguments != null && !arguments.trim().isEmpty()) { final String[] tokens = arguments.split(","); - if (tokens.length > 0 && tokens[0].trim().length() > 0) { + if (tokens.length > 0 && !tokens[0].trim().isEmpty()) { _precision = Integer.parseInt(tokens[0].trim()); if (_precision < 1) { throw new IllegalArgumentException("Specified precision must be >= 1"); } } - if (tokens.length > 1 && tokens[1].trim().length() > 0) { + if (tokens.length > 1 && !tokens[1].trim().isEmpty()) { _scale = Integer.parseInt(tokens[1].trim()); } - if (tokens.length > 2 && tokens[2].trim().length() > 0) { + if (tokens.length > 2 && !tokens[2].trim().isEmpty()) { String mode = tokens[2].trim(); switch (mode.toLowerCase()) { case "allowrounding": @@ -141,13 +140,12 @@ private void init() { final byte[] unscaledZero = BigDecimal.ZERO.unscaledValue().toByteArray(); zeroBytes = new byte[Integer.BYTES + unscaledZero.length]; Arrays.fill(zeroBytes, (byte) 0); - nullBytes = CollectionUtil.ZERO_LENGTH_BYTE_ARRAY; + nullBytes = CodecUtil.ZERO_LENGTH_BYTE_ARRAY; } } - @NotNull @Override - public byte[] encode(@Nullable final BigDecimal input) { + public byte @NotNull [] encode(@Nullable final BigDecimal input) { if (input == null) { return nullBytes; } @@ -173,7 +171,7 @@ public byte[] encode(@Nullable final BigDecimal input) { // (i.e. too high a scale requires reducing precision to "make room") if ((value.precision() > this.precision || value.scale() > scale)) { if (strict) { - throw new IllegalArgumentException("Unable to encode value " + value.toString() + " with precision " + throw new IllegalArgumentException("Unable to encode value " + value + " with precision " + precision + " scale " + scale); } final int targetPrecision = Math.min(precision, value.precision() - Math.max(0, value.scale() - scale)); @@ -194,7 +192,7 @@ public byte[] encode(@Nullable final BigDecimal input) { // copy unscaled bytes to proper size array final byte[] unscaledValue = value.unscaledValue().toByteArray(); if (unscaledValue.length >= bytes.length) { // unscaled value must be at most one less than length of our buffer - throw new IllegalArgumentException("Value " + input.toString() + " is too large to encode with precision " + throw new IllegalArgumentException("Value " + input + " is too large to encode with precision " + precision + " and scale " + scale); } @@ -213,7 +211,7 @@ public byte[] encode(@Nullable final BigDecimal input) { @Nullable @Override - public BigDecimal decode(@NotNull final byte[] input, final int offset, final int length) { + public BigDecimal decode(final byte @NotNull [] input, final int offset, final int length) { // variable size value if (precision == 0) { diff --git a/Util/src/main/java/io/deephaven/util/codec/BigIntegerCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/BigIntegerCodec.java similarity index 90% rename from Util/src/main/java/io/deephaven/util/codec/BigIntegerCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/BigIntegerCodec.java index 024632e66cd..f9b19918cfe 100644 --- a/Util/src/main/java/io/deephaven/util/codec/BigIntegerCodec.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/BigIntegerCodec.java @@ -32,7 +32,7 @@ public BigIntegerCodec(@Nullable String arguments) { // noinspection ConstantConditions try { int _precision = 0; // zero indicates unlimited precision, variable width encoding - if (arguments != null && arguments.trim().length() > 0) { + if (arguments != null && !arguments.trim().isEmpty()) { _precision = Integer.parseInt(arguments.trim()); if (_precision < 1) { throw new IllegalArgumentException("Specified precision must be >= 1"); @@ -61,9 +61,8 @@ public int getScale() { return 0; } - @NotNull @Override - public byte[] encode(@Nullable final BigInteger input) { + public byte @NotNull [] encode(@Nullable final BigInteger input) { return input == null ? codec.encodedNullValue() : codec.encode(new BigDecimal(input)); @@ -71,7 +70,7 @@ public byte[] encode(@Nullable final BigInteger input) { @Nullable @Override - public BigInteger decode(@NotNull final byte[] input, final int offset, final int length) { + public BigInteger decode(final byte @NotNull [] input, final int offset, final int length) { final BigDecimal bd = codec.decode(input, offset, length); return bd == null ? null : bd.toBigInteger(); } diff --git a/Util/src/main/java/io/deephaven/util/EncodingUtil.java b/codec/builtin/src/main/java/io/deephaven/util/codec/CodecUtil.java similarity index 54% rename from Util/src/main/java/io/deephaven/util/EncodingUtil.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/CodecUtil.java index 81009c7774d..27c02c81625 100644 --- a/Util/src/main/java/io/deephaven/util/EncodingUtil.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/CodecUtil.java @@ -1,10 +1,9 @@ // // Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending // -package io.deephaven.util; +package io.deephaven.util.codec; import io.deephaven.base.string.EncodingInfo; -import org.apache.commons.io.ByteOrderMark; import org.jetbrains.annotations.NotNull; import java.nio.BufferOverflowException; @@ -12,63 +11,13 @@ import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; -import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; -import java.util.Arrays; -public class EncodingUtil { - @SuppressWarnings("WeakerAccess") - public static final ByteOrderMark[] EMPTY_BOM_ARRAY = new ByteOrderMark[0]; +class CodecUtil { + public static final byte[] ZERO_LENGTH_BYTE_ARRAY = new byte[0]; - /** - * Get the {@link EncodingInfo} associated with a particular {@link Charset} - * - * @param charSet The charset - * @return the matching {@link EncodingInfo} - * @throws IllegalArgumentException if there is no associated encoding - */ - @NotNull - public static EncodingInfo getEncodingInfoForCharset(@NotNull Charset charSet) throws IllegalArgumentException { - return getEncodingInfoForCharset(charSet.name()); - } - - /** - * Get the {@link EncodingInfo} associated with a particular charset name - * - * @param charsetName the charset - * @return the matching {@link EncodingInfo} - * @throws IllegalArgumentException if there is no associated encoding - */ - public static EncodingInfo getEncodingInfoForCharset(@NotNull String charsetName) { - return Arrays.stream(EncodingInfo.values()) - .filter(info -> info.getCharset().name().equals(charsetName)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException("No EncodingInfo for " + charsetName)); - } - - /** - * Get an array containing the possible {@link ByteOrderMark byte order marks} that could be present within a file - * of the specified encoding. This is intended for use with {@link org.apache.commons.io.input.BOMInputStream} - * - * @param encoding The encoding. - * @return An array containing the possible {@link ByteOrderMark BOMs} for the encoding. - */ - @NotNull - public static ByteOrderMark[] getBOMsForEncoding(EncodingInfo encoding) { - switch (encoding) { - case UTF_8: - return new ByteOrderMark[] {ByteOrderMark.UTF_8}; - case UTF_16BE: - return new ByteOrderMark[] {ByteOrderMark.UTF_16BE}; - case UTF_16LE: - return new ByteOrderMark[] {ByteOrderMark.UTF_16LE}; - case UTF_16: - return new ByteOrderMark[] {ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE}; - } - - return EMPTY_BOM_ARRAY; - } + private CodecUtil() {} /** * Encode the given string in UTF-8 format into the given ByteBuffer. The string is encoded as an int length diff --git a/Util/src/main/java/io/deephaven/util/codec/ExternalizableCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/ExternalizableCodec.java similarity index 84% rename from Util/src/main/java/io/deephaven/util/codec/ExternalizableCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/ExternalizableCodec.java index eb2d42a2d9c..79585c8fc3b 100644 --- a/Util/src/main/java/io/deephaven/util/codec/ExternalizableCodec.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/ExternalizableCodec.java @@ -7,6 +7,7 @@ import org.jetbrains.annotations.Nullable; import java.io.*; +import java.lang.reflect.InvocationTargetException; public class ExternalizableCodec implements ObjectCodec { @@ -21,9 +22,8 @@ public ExternalizableCodec(String className) { } } - @NotNull @Override - public byte[] encode(@Nullable T input) { + public byte @NotNull [] encode(@Nullable T input) { if (input == null) { throw new UnsupportedOperationException(getClass() + " does not support null input"); } @@ -55,16 +55,17 @@ public int getScale() { @Nullable @Override - public T decode(@NotNull byte[] input, int offset, int length) { + public T decode(byte @NotNull [] input, int offset, int length) { try { final ByteArrayInputStream byteInput = new ByteArrayInputStream(input, offset, length); final ObjectInputStream objectInput = new ObjectInputStream(byteInput); - T result = externalizableClass.newInstance(); + T result = externalizableClass.getDeclaredConstructor().newInstance(); result.readExternal(objectInput); return result; } catch (IOException e) { throw new UncheckedIOException(e); - } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) { + } catch (IllegalAccessException | InstantiationException | ClassNotFoundException | InvocationTargetException + | NoSuchMethodException e) { throw new RuntimeException(e); } } diff --git a/Util/src/main/java/io/deephaven/util/codec/LocalDateCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/LocalDateCodec.java similarity index 97% rename from Util/src/main/java/io/deephaven/util/codec/LocalDateCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/LocalDateCodec.java index 3870fa3ac57..20f60c42dd3 100644 --- a/Util/src/main/java/io/deephaven/util/codec/LocalDateCodec.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/LocalDateCodec.java @@ -104,9 +104,8 @@ public int getScale() { return 0; } - @NotNull @Override - public byte[] encode(@Nullable final LocalDate input) { + public byte @NotNull [] encode(@Nullable final LocalDate input) { if (input == null) { if (nullBytes != null) { return nullBytes; @@ -157,7 +156,7 @@ public byte[] encode(@Nullable final LocalDate input) { @Nullable @Override - public LocalDate decode(@NotNull final byte[] input, final int offset, final int length) { + public LocalDate decode(final byte @NotNull [] input, final int offset, final int length) { final int year, month, dayOfMonth; if (input[offset] == NULL_INDICATOR) { return null; diff --git a/Util/src/main/java/io/deephaven/util/codec/LocalTimeCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/LocalTimeCodec.java similarity index 97% rename from Util/src/main/java/io/deephaven/util/codec/LocalTimeCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/LocalTimeCodec.java index 24aa7a9784c..013ebd01de4 100644 --- a/Util/src/main/java/io/deephaven/util/codec/LocalTimeCodec.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/LocalTimeCodec.java @@ -99,9 +99,8 @@ public int getScale() { return 0; } - @NotNull @Override - public byte[] encode(@Nullable final LocalTime input) { + public byte @NotNull [] encode(@Nullable final LocalTime input) { if (input == null) { if (nullBytes != null) { @@ -130,7 +129,7 @@ public byte[] encode(@Nullable final LocalTime input) { @Nullable @Override - public LocalTime decode(@NotNull final byte[] input, final int offset, final int length) { + public LocalTime decode(final byte @NotNull [] input, final int offset, final int length) { // test for null indicator (leading bit) if ((input[offset] & NULL_INDICATOR) != 0) { return null; diff --git a/Util/src/main/java/io/deephaven/util/codec/MapCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/MapCodec.java similarity index 93% rename from Util/src/main/java/io/deephaven/util/codec/MapCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/MapCodec.java index 2c1c85cae69..45dbd324b09 100644 --- a/Util/src/main/java/io/deephaven/util/codec/MapCodec.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/MapCodec.java @@ -3,7 +3,6 @@ // package io.deephaven.util.codec; -import io.deephaven.datastructures.util.CollectionUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -23,7 +22,6 @@ */ @SuppressWarnings("unused") public abstract class MapCodec implements ObjectCodec> { - private static final byte[] nullBytes = CollectionUtil.ZERO_LENGTH_BYTE_ARRAY; private static final byte[] zeroBytes = new byte[4]; private static final int MINIMUM_SCRATCH_CAPACITY = 4096; @@ -47,13 +45,12 @@ public int getScale() { return 0; } - @NotNull @Override - public byte[] encode(@Nullable final Map input) { + public byte @NotNull [] encode(@Nullable final Map input) { if (input == null) { - return nullBytes; + return CodecUtil.ZERO_LENGTH_BYTE_ARRAY; } - if (input.size() == 0) { + if (input.isEmpty()) { return zeroBytes; } @@ -137,7 +134,7 @@ public Map decode(@NotNull final ByteBuffer byteBuffer) { @Nullable @Override - public Map decode(@NotNull final byte[] input, final int offset, final int length) { + public Map decode(final byte @NotNull [] input, final int offset, final int length) { if (input.length == 0) { return null; } diff --git a/Util/src/main/java/io/deephaven/util/codec/SerializableCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/SerializableCodec.java similarity index 93% rename from Util/src/main/java/io/deephaven/util/codec/SerializableCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/SerializableCodec.java index b9570299a49..9cd08f24abf 100644 --- a/Util/src/main/java/io/deephaven/util/codec/SerializableCodec.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/SerializableCodec.java @@ -21,9 +21,8 @@ private SerializableCodec() {} public SerializableCodec(@SuppressWarnings("unused") String dummy) {} - @NotNull @Override - public byte[] encode(@Nullable T input) { + public byte @NotNull [] encode(@Nullable T input) { try { final ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); final ObjectOutputStream objectOutput = new ObjectOutputStream(byteOutput); @@ -52,7 +51,7 @@ public int getScale() { @Nullable @Override - public T decode(@NotNull byte[] input, int offset, int length) { + public T decode(byte @NotNull [] input, int offset, int length) { try { final ByteArrayInputStream byteInput = new ByteArrayInputStream(input, offset, length); final ObjectInputStream objectInput = new ObjectInputStream(byteInput); diff --git a/Util/src/main/java/io/deephaven/util/codec/SimpleByteArrayCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/SimpleByteArrayCodec.java similarity index 88% rename from Util/src/main/java/io/deephaven/util/codec/SimpleByteArrayCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/SimpleByteArrayCodec.java index 8bf70622a03..1dae95849ff 100644 --- a/Util/src/main/java/io/deephaven/util/codec/SimpleByteArrayCodec.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/SimpleByteArrayCodec.java @@ -3,7 +3,6 @@ // package io.deephaven.util.codec; -import io.deephaven.datastructures.util.CollectionUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -43,9 +42,8 @@ public SimpleByteArrayCodec(@Nullable final String arguments) { expectedWidth = size; } - @NotNull @Override - public byte[] encode(@Nullable final byte[] input) { + public byte @NotNull [] encode(final byte @Nullable [] input) { if (input == null) { throw new IllegalArgumentException(SimpleByteArrayCodec.class.getSimpleName() + " cannot encode nulls"); } @@ -69,11 +67,10 @@ public int getScale() { return 0; } - @Nullable @Override - public byte[] decode(@NotNull final byte[] input, final int offset, final int length) { + public byte @Nullable [] decode(final byte @NotNull [] input, final int offset, final int length) { if (input.length == 0) { - return CollectionUtil.ZERO_LENGTH_BYTE_ARRAY; + return CodecUtil.ZERO_LENGTH_BYTE_ARRAY; } final byte[] output = new byte[length]; System.arraycopy(input, offset, output, 0, length); diff --git a/Util/src/main/java/io/deephaven/util/codec/StringBooleanMapCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/StringBooleanMapCodec.java similarity index 100% rename from Util/src/main/java/io/deephaven/util/codec/StringBooleanMapCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/StringBooleanMapCodec.java diff --git a/Util/src/main/java/io/deephaven/util/codec/StringDoubleMapCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/StringDoubleMapCodec.java similarity index 100% rename from Util/src/main/java/io/deephaven/util/codec/StringDoubleMapCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/StringDoubleMapCodec.java diff --git a/Util/src/main/java/io/deephaven/util/codec/StringFloatMapCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/StringFloatMapCodec.java similarity index 100% rename from Util/src/main/java/io/deephaven/util/codec/StringFloatMapCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/StringFloatMapCodec.java diff --git a/Util/src/main/java/io/deephaven/util/codec/StringIntMapCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/StringIntMapCodec.java similarity index 100% rename from Util/src/main/java/io/deephaven/util/codec/StringIntMapCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/StringIntMapCodec.java diff --git a/Util/src/main/java/io/deephaven/util/codec/StringKeyedMapCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/StringKeyedMapCodec.java similarity index 88% rename from Util/src/main/java/io/deephaven/util/codec/StringKeyedMapCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/StringKeyedMapCodec.java index 50650f1668d..a38124e360a 100644 --- a/Util/src/main/java/io/deephaven/util/codec/StringKeyedMapCodec.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/StringKeyedMapCodec.java @@ -3,8 +3,6 @@ // package io.deephaven.util.codec; -import io.deephaven.util.EncodingUtil; - import java.nio.ByteBuffer; import java.util.Map; @@ -36,11 +34,11 @@ int estimateSize(Map input) { @Override String decodeKey(ByteBuffer byteBuffer) { - return EncodingUtil.getUtf8String(byteBuffer); + return CodecUtil.getUtf8String(byteBuffer); } @Override void encodeKey(ByteBuffer scratch, String key) { - EncodingUtil.putUtf8String(scratch, key); + CodecUtil.putUtf8String(scratch, key); } } diff --git a/Util/src/main/java/io/deephaven/util/codec/StringLongMapCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/StringLongMapCodec.java similarity index 100% rename from Util/src/main/java/io/deephaven/util/codec/StringLongMapCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/StringLongMapCodec.java diff --git a/Util/src/main/java/io/deephaven/util/codec/StringStringMapCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/StringStringMapCodec.java similarity index 89% rename from Util/src/main/java/io/deephaven/util/codec/StringStringMapCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/StringStringMapCodec.java index f85a6914759..4229d583460 100644 --- a/Util/src/main/java/io/deephaven/util/codec/StringStringMapCodec.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/StringStringMapCodec.java @@ -3,7 +3,6 @@ // package io.deephaven.util.codec; -import io.deephaven.util.EncodingUtil; import org.jetbrains.annotations.Nullable; import java.nio.ByteBuffer; @@ -40,11 +39,11 @@ int getValueSize() { @Override String decodeValue(ByteBuffer byteBuffer) { - return EncodingUtil.getUtf8String(byteBuffer); + return CodecUtil.getUtf8String(byteBuffer); } @Override void encodeValue(ByteBuffer scratch, String value) { - EncodingUtil.putUtf8String(scratch, value); + CodecUtil.putUtf8String(scratch, value); } } diff --git a/Util/src/main/java/io/deephaven/util/codec/UTF8StringAsByteArrayCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/UTF8StringAsByteArrayCodec.java similarity index 93% rename from Util/src/main/java/io/deephaven/util/codec/UTF8StringAsByteArrayCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/UTF8StringAsByteArrayCodec.java index 5f32d7568d9..df29640baee 100644 --- a/Util/src/main/java/io/deephaven/util/codec/UTF8StringAsByteArrayCodec.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/UTF8StringAsByteArrayCodec.java @@ -44,9 +44,8 @@ public UTF8StringAsByteArrayCodec(@Nullable final String arguments) { expectedWidth = size; } - @NotNull @Override - public byte[] encode(@Nullable final String input) { + public byte @NotNull [] encode(@Nullable final String input) { if (input == null) { throw new IllegalArgumentException( UTF8StringAsByteArrayCodec.class.getSimpleName() + " cannot encode nulls"); @@ -71,7 +70,7 @@ public int getScale() { @Nullable @Override - public String decode(@NotNull final byte[] input, final int offset, final int length) { + public String decode(final byte @NotNull [] input, final int offset, final int length) { return new String(input, offset, length, StandardCharsets.UTF_8); } diff --git a/Util/src/main/java/io/deephaven/util/codec/ZonedDateTimeCodec.java b/codec/builtin/src/main/java/io/deephaven/util/codec/ZonedDateTimeCodec.java similarity index 90% rename from Util/src/main/java/io/deephaven/util/codec/ZonedDateTimeCodec.java rename to codec/builtin/src/main/java/io/deephaven/util/codec/ZonedDateTimeCodec.java index e5092332dcf..c928ff6b71f 100644 --- a/Util/src/main/java/io/deephaven/util/codec/ZonedDateTimeCodec.java +++ b/codec/builtin/src/main/java/io/deephaven/util/codec/ZonedDateTimeCodec.java @@ -3,7 +3,6 @@ // package io.deephaven.util.codec; -import io.deephaven.datastructures.util.CollectionUtil; import io.deephaven.util.QueryConstants; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -19,11 +18,10 @@ public class ZonedDateTimeCodec implements ObjectCodec { public ZonedDateTimeCodec(String args) {} - @NotNull @Override - public byte[] encode(@Nullable ZonedDateTime input) { + public byte @NotNull [] encode(@Nullable ZonedDateTime input) { if (input == null) { - return CollectionUtil.ZERO_LENGTH_BYTE_ARRAY; + return CodecUtil.ZERO_LENGTH_BYTE_ARRAY; } final int bufSize = computeSize(input); @@ -40,7 +38,7 @@ public byte[] encode(@Nullable ZonedDateTime input) { @Nullable @Override - public ZonedDateTime decode(@NotNull byte[] input, int offset, int length) { + public ZonedDateTime decode(byte @NotNull [] input, int offset, int length) { if (length == 0) { return null; } diff --git a/Util/src/test/java/io/deephaven/util/codec/BigDecimalCodecTest.java b/codec/builtin/src/test/java/io/deephaven/util/codec/BigDecimalCodecTest.java similarity index 100% rename from Util/src/test/java/io/deephaven/util/codec/BigDecimalCodecTest.java rename to codec/builtin/src/test/java/io/deephaven/util/codec/BigDecimalCodecTest.java diff --git a/Util/src/test/java/io/deephaven/util/codec/BigIntegerCodecTest.java b/codec/builtin/src/test/java/io/deephaven/util/codec/BigIntegerCodecTest.java similarity index 100% rename from Util/src/test/java/io/deephaven/util/codec/BigIntegerCodecTest.java rename to codec/builtin/src/test/java/io/deephaven/util/codec/BigIntegerCodecTest.java diff --git a/Util/src/test/java/io/deephaven/util/codec/LocalDateCodecTest.java b/codec/builtin/src/test/java/io/deephaven/util/codec/LocalDateCodecTest.java similarity index 100% rename from Util/src/test/java/io/deephaven/util/codec/LocalDateCodecTest.java rename to codec/builtin/src/test/java/io/deephaven/util/codec/LocalDateCodecTest.java diff --git a/Util/src/test/java/io/deephaven/util/codec/LocalTimeCodecTest.java b/codec/builtin/src/test/java/io/deephaven/util/codec/LocalTimeCodecTest.java similarity index 100% rename from Util/src/test/java/io/deephaven/util/codec/LocalTimeCodecTest.java rename to codec/builtin/src/test/java/io/deephaven/util/codec/LocalTimeCodecTest.java diff --git a/Util/src/test/java/io/deephaven/util/codec/ZonedDateTimeCodecTest.java b/codec/builtin/src/test/java/io/deephaven/util/codec/ZonedDateTimeCodecTest.java similarity index 97% rename from Util/src/test/java/io/deephaven/util/codec/ZonedDateTimeCodecTest.java rename to codec/builtin/src/test/java/io/deephaven/util/codec/ZonedDateTimeCodecTest.java index 6c17e3cba49..5564ab4f660 100644 --- a/Util/src/test/java/io/deephaven/util/codec/ZonedDateTimeCodecTest.java +++ b/codec/builtin/src/test/java/io/deephaven/util/codec/ZonedDateTimeCodecTest.java @@ -3,6 +3,7 @@ // package io.deephaven.util.codec; +import org.junit.Assert; import org.junit.Test; import java.time.Instant; @@ -10,7 +11,6 @@ import java.time.ZonedDateTime; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; public class ZonedDateTimeCodecTest { private void roundTripWithOffset(final ZonedDateTime value, final int offset) { @@ -42,7 +42,7 @@ public void testMax() { roundTripWithOffset(ZonedDateTime.ofInstant( Instant.ofEpochSecond(ZonedDateTimeCodec.MAX_CONVERTIBLE_SECONDS + 1), ZoneId.of("America/New_York")), 0); - fail(); + Assert.fail(); } catch (IllegalArgumentException ignored) { } diff --git a/codec/cache/build.gradle b/codec/cache/build.gradle new file mode 100644 index 00000000000..d28f2793e9c --- /dev/null +++ b/codec/cache/build.gradle @@ -0,0 +1,12 @@ +plugins { + id 'java-library' + id 'io.deephaven.project.register' +} + +description 'Codec Cache: Deephaven Codec Cache' + +dependencies { + api project(":codec-api") + + compileOnly libs.jetbrains.annotations +} diff --git a/codec/cache/gradle.properties b/codec/cache/gradle.properties new file mode 100644 index 00000000000..c186bbfdde1 --- /dev/null +++ b/codec/cache/gradle.properties @@ -0,0 +1 @@ +io.deephaven.project.ProjectType=JAVA_PUBLIC diff --git a/Util/src/main/java/io/deephaven/util/codec/CodecCache.java b/codec/cache/src/main/java/io/deephaven/util/codec/CodecCache.java similarity index 69% rename from Util/src/main/java/io/deephaven/util/codec/CodecCache.java rename to codec/cache/src/main/java/io/deephaven/util/codec/CodecCache.java index ee920c5171d..10c2517090f 100644 --- a/Util/src/main/java/io/deephaven/util/codec/CodecCache.java +++ b/codec/cache/src/main/java/io/deephaven/util/codec/CodecCache.java @@ -3,25 +3,19 @@ // package io.deephaven.util.codec; -import io.deephaven.base.verify.Require; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.time.LocalDate; -import java.time.LocalTime; -import java.time.ZonedDateTime; import java.util.HashMap; import java.util.Map; +import java.util.Objects; /** * Cache for {@link ObjectCodec} instances. */ public enum CodecCache { - DEFAULT; /** @@ -34,7 +28,7 @@ private static class Item { private Item(@NotNull final String className, @Nullable final String arguments) { - Require.neqNull(className, "className"); + Objects.requireNonNull(className); final Class codecClass; try { @@ -79,26 +73,4 @@ public synchronized ObjectCodec getCodec(@NotNull final String clas .computeIfAbsent(className, (cn) -> new HashMap<>()) .computeIfAbsent(arguments, (a) -> new Item(className, a)).codec; } - - /** - * Get the default {@link ObjectCodec} class to use for the given column type. - * - * @param dataType The column data type - * @return The name of the default {@link ObjectCodec} subclass to use for encoding the given type - */ - public static String getDefaultCodecClass(@NotNull final Class dataType) { - if (dataType.equals(LocalDate.class)) { - return LocalDateCodec.class.getName(); - } else if (dataType.equals(LocalTime.class)) { - return LocalTimeCodec.class.getName(); - } else if (dataType.equals(BigDecimal.class)) { - return BigDecimalCodec.class.getName(); - } else if (dataType.equals(BigInteger.class)) { - return BigIntegerCodec.class.getName(); - } else if (dataType.equals(ZonedDateTime.class)) { - return ZonedDateTimeCodec.class.getName(); - } else { - return null; - } - } } diff --git a/Util/src/main/java/io/deephaven/util/codec/CodecCacheException.java b/codec/cache/src/main/java/io/deephaven/util/codec/CodecCacheException.java similarity index 100% rename from Util/src/main/java/io/deephaven/util/codec/CodecCacheException.java rename to codec/cache/src/main/java/io/deephaven/util/codec/CodecCacheException.java diff --git a/engine/chunk/build.gradle b/engine/chunk/build.gradle index c883653c1ed..f359693611c 100644 --- a/engine/chunk/build.gradle +++ b/engine/chunk/build.gradle @@ -7,12 +7,13 @@ description 'Engine Chunks: Array-like data structures for dense, efficient data dependencies { api project(':Util') + api project(':codec-api:') implementation project(':Base') testImplementation libs.junit4 - testRuntimeOnly project(':log-to-slf4j'), - project(path: ':configs'), - project(path: ':test-configs') + testRuntimeOnly project(':log-to-slf4j') + testRuntimeOnly project(path: ':configs') + testRuntimeOnly project(path: ':test-configs') testRuntimeOnly libs.slf4j.simple } diff --git a/engine/table/build.gradle b/engine/table/build.gradle index fe9be770f49..0cf5fe712d5 100644 --- a/engine/table/build.gradle +++ b/engine/table/build.gradle @@ -21,6 +21,7 @@ dependencies { api project(':deephaven-jpy-ext') api project(':hotspot') api project(':IO') + api project(':codec-api') implementation project(':DHProcess') implementation project(':engine-function') @@ -28,6 +29,8 @@ dependencies { implementation project(':Configuration') implementation project(':log-factory') implementation project(':Stats') + implementation project(':codec-builtin') + implementation project(':codec-cache') implementation libs.f4b6a3.uuid.creator // TODO(deephaven-core#3204): t-digest 3.3 appears to have higher errors than 3.2 diff --git a/extensions/parquet/base/build.gradle b/extensions/parquet/base/build.gradle index 9a71ac9382c..7b63f37014b 100644 --- a/extensions/parquet/base/build.gradle +++ b/extensions/parquet/base/build.gradle @@ -7,6 +7,7 @@ description 'Parquet Base: Libraries for working with Parquet files' dependencies { api project(':util-channel') + api project(':codec-api') implementation libs.parquet.hadoop diff --git a/extensions/parquet/table/build.gradle b/extensions/parquet/table/build.gradle index caec0e66a29..5b7d43ddf67 100644 --- a/extensions/parquet/table/build.gradle +++ b/extensions/parquet/table/build.gradle @@ -24,6 +24,7 @@ dependencies { api project(':engine-api') api project(':engine-stringset') api project(':engine-table') + api project(':codec-api') implementation project(':extensions-parquet-base') implementation libs.parquet.hadoop @@ -32,9 +33,11 @@ dependencies { implementation project(':extensions-csv') implementation project(':log-factory') implementation project(':Configuration') - implementation libs.commons.lang3 implementation project(':Util') + implementation project(':codec-builtin') + implementation project(':codec-cache') + implementation libs.commons.lang3 implementation libs.commons.text implementation libs.commons.compress diff --git a/settings.gradle b/settings.gradle index deef79359aa..9db07a453c4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -415,6 +415,13 @@ include ':clock-impl' include ':sql' +include(':codec-api') +project(':codec-api').projectDir = file('codec/api') +include(':codec-builtin') +project(':codec-builtin').projectDir = file('codec/builtin') +include(':codec-cache') +project(':codec-cache').projectDir = file('codec/cache') + file("${rootDir}/docker/registry").list().each { name -> if (file("${rootDir}/docker/registry/${name}/build.gradle").exists()) { include(":docker-${name}")