Skip to content

Commit 478655c

Browse files
committed
manual cleanups here and there
1 parent 8aa6612 commit 478655c

14 files changed

Lines changed: 76 additions & 117 deletions

File tree

core/src/test/java/io/github/dfa1/vortex/encoding/ByteBoolEncodingTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.dfa1.vortex.encoding;
22

3-
import io.github.dfa1.vortex.core.DType;
43
import io.github.dfa1.vortex.core.array.Array;
54
import io.github.dfa1.vortex.core.array.BoolArray;
65
import org.junit.jupiter.api.Nested;
@@ -16,8 +15,6 @@
1615

1716
class ByteBoolEncodingTest {
1817

19-
private static final DType BOOL_DTYPE = new DType.Bool(false);
20-
2118
@Nested
2219
class Encode {
2320

@@ -30,8 +27,8 @@ void encodeDecode_isLossless(boolean[] data) {
3027
registry.register(sut);
3128

3229
// When
33-
EncodeResult encoded = sut.encode(BOOL_DTYPE, data, EncodeTestHelper.testCtx());
34-
DecodeContext ctx = EncodeTestHelper.toDecodeContext(encoded, data.length, BOOL_DTYPE, registry);
30+
EncodeResult encoded = sut.encode(DTypes.BOOL, data, EncodeTestHelper.testCtx());
31+
DecodeContext ctx = EncodeTestHelper.toDecodeContext(encoded, data.length, DTypes.BOOL, registry);
3532
Array result = sut.decode(ctx);
3633

3734
// Then
@@ -90,7 +87,7 @@ private static DecodeContext buildCtx(byte[] byteValues) {
9087
ArrayNode node = ArrayNode.of(EncodingId.VORTEX_BYTEBOOL, null, new ArrayNode[0], new int[]{0}, null);
9188
EncodingRegistry registry = EncodingRegistry.empty();
9289
registry.register(new ByteBoolEncoding());
93-
return new DecodeContext(node, BOOL_DTYPE, byteValues.length, new MemorySegment[]{buf}, registry,
90+
return new DecodeContext(node, DTypes.BOOL, byteValues.length, new MemorySegment[]{buf}, registry,
9491
Arena.ofAuto());
9592
}
9693
}

core/src/test/java/io/github/dfa1/vortex/encoding/DateTimePartsEncodingTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@
2020

2121
class DateTimePartsEncodingTest {
2222

23-
private static final DType EXT_TIMESTAMP_MS = timestampDType(TimeUnit.Milliseconds, false);
24-
private static final DType EXT_TIMESTAMP_NS = timestampDType(TimeUnit.Nanoseconds, false);
25-
private static final DType EXT_TIMESTAMP_S = timestampDType(TimeUnit.Seconds, false);
23+
private static final DType EXT_TIMESTAMP_MS = timestampDType(TimeUnit.Milliseconds);
24+
private static final DType EXT_TIMESTAMP_NS = timestampDType(TimeUnit.Nanoseconds);
2625

27-
private static DType timestampDType(TimeUnit unit, boolean nullable) {
26+
private static DType timestampDType(TimeUnit unit) {
2827
// Rust hand-rolled: byte[0]=unit tag, bytes[1-2]=tz_len u16 LE (0 = no tz)
2928
ByteBuffer meta = ByteBuffer.allocate(3).order(ByteOrder.LITTLE_ENDIAN);
3029
meta.put((byte) unit.ordinal());
3130
meta.putShort((short) 0); // no timezone
3231
meta.flip();
3332
return new DType.Extension("vortex.timestamp",
34-
new DType.Primitive(PType.I64, nullable), meta, nullable);
33+
new DType.Primitive(PType.I64, false), meta, false);
3534
}
3635

3736
private static ArrayNode toArrayNode(EncodeNode node) {
@@ -210,7 +209,7 @@ void roundTrip_multipleTimestamps_allRowsPreserved() {
210209
@EnumSource(value = TimeUnit.class, names = {"Nanoseconds", "Microseconds", "Milliseconds", "Seconds"})
211210
void roundTrip_allUnits_epochIsZero(TimeUnit unit) {
212211
// Given
213-
DType dtype = timestampDType(unit, false);
212+
DType dtype = timestampDType(unit);
214213
long[] timestamps = {0L};
215214
DateTimePartsData data = new DateTimePartsData(timestamps, false);
216215
DateTimePartsEncoding sut = new DateTimePartsEncoding();

core/src/test/java/io/github/dfa1/vortex/encoding/DecimalBytePartsEncodingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DecimalBytePartsEncodingTest {
1515
class Encode {
1616

1717
@Test
18-
void roundTrip_longArray_preservesMspValues() throws Exception {
18+
void roundTrip_longArray_preservesMspValues() {
1919
// Given
2020
long[] values = {1L, -2L, 3L};
2121
DType dtype = new DType.Decimal((byte) 18, (byte) 0, false);

core/src/test/java/io/github/dfa1/vortex/encoding/DecimalEncodingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DecimalEncodingTest {
2222
class Encode {
2323

2424
@Test
25-
void roundTrip_i64Precision_preservesBuffer() throws Exception {
25+
void roundTrip_i64Precision_preservesBuffer() {
2626
// Given
2727
long[] values = {100L, -200L, 300L};
2828
MemorySegment input = TestSegments.leLongs(values);

core/src/test/java/io/github/dfa1/vortex/encoding/DictEncodingTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ private static int[] repeat(int[] pattern, int times) {
162162
return result;
163163
}
164164

165-
private static String[] repeat(String[] pattern, int times) {
165+
@SuppressWarnings("SameParameterValue")
166+
private static String[] repeat(String[] pattern, int times) {
166167
String[] result = new String[pattern.length * times];
167168
for (int i = 0; i < times; i++) {
168169
System.arraycopy(pattern, 0, result, i * pattern.length, pattern.length);

core/src/test/java/io/github/dfa1/vortex/encoding/ExtEncodingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void decode_extensionWrappingI64_returnsStorageArray() {
106106

107107
// Then
108108
assertThat(result).isInstanceOf(LongArray.class);
109-
assertThat(result.length()).isEqualTo((long) values.length);
109+
assertThat(result.length()).isEqualTo(values.length);
110110
for (int i = 0; i < values.length; i++) {
111111
LongArray longArray = (LongArray) result;
112112
assertThat(longArray.getLong(i)).isEqualTo(values[i]);

core/src/test/java/io/github/dfa1/vortex/encoding/FsstEncodingTest.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.dfa1.vortex.encoding;
22

3-
import io.github.dfa1.vortex.core.DType;
43
import io.github.dfa1.vortex.core.PType;
54
import io.github.dfa1.vortex.core.VortexException;
65
import io.github.dfa1.vortex.core.array.VarBinArray;
@@ -24,10 +23,6 @@
2423

2524
class FsstEncodingTest {
2625

27-
private static final DType UTF8 = new DType.Utf8(false);
28-
private static final DType BINARY = new DType.Binary(false);
29-
private static final DType I32 = new DType.Primitive(PType.I32, false);
30-
3126
@Nested
3227
class Encode {
3328

@@ -37,7 +32,7 @@ void accepts_utf8_true() {
3732
var sut = new FsstEncoding();
3833

3934
// When / Then
40-
assertThat(sut.accepts(UTF8)).isTrue();
35+
assertThat(sut.accepts(DTypes.UTF8)).isTrue();
4136
}
4237

4338
@Test
@@ -46,7 +41,7 @@ void accepts_binary_true() {
4641
var sut = new FsstEncoding();
4742

4843
// When / Then
49-
assertThat(sut.accepts(BINARY)).isTrue();
44+
assertThat(sut.accepts(DTypes.BINARY)).isTrue();
5045
}
5146

5247
@Test
@@ -55,7 +50,7 @@ void accepts_primitive_false() {
5550
var sut = new FsstEncoding();
5651

5752
// When / Then
58-
assertThat(sut.accepts(I32)).isFalse();
53+
assertThat(sut.accepts(DTypes.I32)).isFalse();
5954
}
6055

6156
@ParameterizedTest(name = "{0}")
@@ -66,13 +61,13 @@ void encode_thenDecode_roundtripsAllStrings(String name, String[] values) {
6661
Arena arena = Arena.ofAuto();
6762

6863
// When
69-
EncodeResult result = sut.encode(UTF8, values, EncodeTestHelper.testCtx());
64+
EncodeResult result = sut.encode(DTypes.UTF8, values, EncodeTestHelper.testCtx());
7065
MemorySegment[] bufs = result.buffers().toArray(MemorySegment[]::new);
7166
ArrayNode node = toArrayNode(result.rootNode());
7267
EncodingRegistry registry = EncodingRegistry.empty();
7368
registry.register(new PrimitiveEncoding());
7469
registry.register(sut);
75-
DecodeContext ctx = new DecodeContext(node, UTF8, values.length, bufs, registry, arena);
70+
DecodeContext ctx = new DecodeContext(node, DTypes.UTF8, values.length, bufs, registry, arena);
7671
var decoded = (VarBinArray) sut.decode(ctx);
7772

7873
// Then
@@ -98,6 +93,7 @@ static Stream<Arguments> stringArrays() {
9893
Arguments.of("repeated-bigram", new String[]{"aaaa", "aaaa", "aaaa"}),
9994
Arguments.of("long-strings", new String[]{"the quick brown fox jumps over the lazy dog"}),
10095
Arguments.of("mixed-lengths", new String[]{"a", "hello", "this is a longer string than twelve"}),
96+
Arguments.of("repeated-short", repeat("a", 1)),
10197
Arguments.of("repeated-short", repeat("ab", 50)),
10298
Arguments.of("all-empty", new String[]{"", "", "", ""}),
10399
Arguments.of("unicode", new String[]{"héllo", "wörld", "こんにちは"})
@@ -214,7 +210,7 @@ void decode_missingMetadata_throwsVortexException() {
214210
// Given
215211
var sut = new FsstEncoding();
216212
ArrayNode node = ArrayNode.of(EncodingId.VORTEX_FSST, null, new ArrayNode[0], new int[0], null);
217-
DecodeContext ctx = new DecodeContext(node, UTF8, 0, new MemorySegment[0],
213+
DecodeContext ctx = new DecodeContext(node, DTypes.UTF8, 0, new MemorySegment[0],
218214
buildRegistry(), Arena.ofAuto());
219215

220216
// When / Then
@@ -273,7 +269,7 @@ private static DecodeContext buildCtx(
273269
EncodingId.VORTEX_FSST, ByteBuffer.wrap(metaBytes),
274270
new ArrayNode[]{uncompLensNode, codesOffNode}, new int[]{0, 1, 2}, null);
275271

276-
return new DecodeContext(root, UTF8, n, segs, buildRegistry(), arena);
272+
return new DecodeContext(root, DTypes.UTF8, n, segs, buildRegistry(), arena);
277273
}
278274

279275
private static EncodingRegistry buildRegistry() {

core/src/test/java/io/github/dfa1/vortex/encoding/NullEncodingTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.dfa1.vortex.encoding;
22

3-
import io.github.dfa1.vortex.core.DType;
43
import io.github.dfa1.vortex.core.array.NullArray;
54
import org.junit.jupiter.api.Nested;
65
import org.junit.jupiter.api.Test;
@@ -12,8 +11,6 @@
1211

1312
class NullEncodingTest {
1413

15-
private static final DType NULL_DTYPE = new DType.Null(true);
16-
1714
@Nested
1815
class Encode {
1916

@@ -23,7 +20,7 @@ void encode_producesEmptyNode() {
2320
var sut = new NullEncoding();
2421

2522
// When
26-
EncodeResult result = sut.encode(NULL_DTYPE, null, EncodeTestHelper.testCtx());
23+
EncodeResult result = sut.encode(DTypes.NULL, null, EncodeTestHelper.testCtx());
2724

2825
// Then
2926
assertThat(result.rootNode().encodingId()).isEqualTo(EncodingId.VORTEX_NULL);
@@ -38,9 +35,9 @@ void encode_thenDecode_roundTrips() {
3835
var sut = new NullEncoding();
3936

4037
// When
41-
EncodeResult encoded = sut.encode(NULL_DTYPE, null, EncodeTestHelper.testCtx());
38+
EncodeResult encoded = sut.encode(DTypes.NULL, null, EncodeTestHelper.testCtx());
4239
ArrayNode node = ArrayNode.of(encoded.rootNode().encodingId(), null, new ArrayNode[0], new int[0], null);
43-
DecodeContext ctx = new DecodeContext(node, NULL_DTYPE, rowCount, new MemorySegment[0],
40+
DecodeContext ctx = new DecodeContext(node, DTypes.NULL, rowCount, new MemorySegment[0],
4441
EncodingRegistry.empty(), Arena.ofAuto());
4542

4643
// Then
@@ -66,14 +63,14 @@ void decode_nullArray_returnsNullArrayWithCorrectLength() {
6663
// Then
6764
assertThat(result).isInstanceOf(NullArray.class);
6865
assertThat(result.length()).isEqualTo(rowCount);
69-
assertThat(result.dtype()).isEqualTo(NULL_DTYPE);
66+
assertThat(result.dtype()).isEqualTo(DTypes.NULL);
7067
}
7168

7269
private static DecodeContext buildNullCtx(long rowCount) {
7370
ArrayNode node = ArrayNode.of(EncodingId.VORTEX_NULL, null, new ArrayNode[0], new int[0], null);
7471
EncodingRegistry registry = EncodingRegistry.empty();
7572
registry.register(new NullEncoding());
76-
return new DecodeContext(node, NULL_DTYPE, rowCount, new MemorySegment[0], registry, Arena.ofAuto());
73+
return new DecodeContext(node, DTypes.NULL, rowCount, new MemorySegment[0], registry, Arena.ofAuto());
7774
}
7875
}
7976
}

core/src/test/java/io/github/dfa1/vortex/encoding/PcoEncodingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ void decode_nullable_allValid_returnsMaskedWithAllValues() {
403403
/// Build chunk meta for Classic mode + Conv1 delta by packing bits LSB-first.
404404
///
405405
/// Layout: mode(4b)=0, delta(4b)=3, quantization(5b), bias_latent(64b),
406-
/// order-1(5b), weights[order×32b], ansSizeLog(4b)=0, nBins(15b)=0, align.
406+
/// order-1(5b), weights[order*32b], ansSizeLog(4b)=0, nBins(15b)=0, align.
407407
/// bias_latent = bias ^ Long.MIN_VALUE; each weight_latent = weight ^ 0x80000000L.
408408
private static MemorySegment chunkMetaConv1(int quantization, long biasLatent,
409409
int order, long[] weightLatents) {

core/src/test/java/io/github/dfa1/vortex/encoding/SequenceEncodingTest.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626

2727
class SequenceEncodingTest {
2828

29-
private static final DType I64_DTYPE = new DType.Primitive(PType.I64, false);
30-
private static final DType I32_DTYPE = new DType.Primitive(PType.I32, false);
31-
private static final DType F64_DTYPE = new DType.Primitive(PType.F64, false);
32-
private static final DType F32_DTYPE = new DType.Primitive(PType.F32, false);
33-
3429
@Nested
3530
class Encode {
3631

@@ -47,8 +42,8 @@ void encode_i64_roundTrips() {
4742
long[] data = {10L, 12L, 14L, 16L};
4843

4944
// When
50-
EncodeResult result = sut.encode(I64_DTYPE, data, EncodeTestHelper.testCtx());
51-
DecodeContext ctx = encodeResultToCtx(result, I64_DTYPE, data.length);
45+
EncodeResult result = sut.encode(DTypes.I64, data, EncodeTestHelper.testCtx());
46+
DecodeContext ctx = encodeResultToCtx(result, DTypes.I64, data.length);
5247
LongArray decoded = (LongArray) sut.decode(ctx);
5348

5449
// Then
@@ -64,8 +59,8 @@ void encode_f64_roundTrips() {
6459
double[] data = {1.0, 1.5, 2.0, 2.5};
6560

6661
// When
67-
EncodeResult result = sut.encode(F64_DTYPE, data, EncodeTestHelper.testCtx());
68-
DecodeContext ctx = encodeResultToCtx(result, F64_DTYPE, data.length);
62+
EncodeResult result = sut.encode(DTypes.F64, data, EncodeTestHelper.testCtx());
63+
DecodeContext ctx = encodeResultToCtx(result, DTypes.F64, data.length);
6964
DoubleArray decoded = (DoubleArray) sut.decode(ctx);
7065

7166
// Then
@@ -81,7 +76,7 @@ void encode_nonArithmeticSequence_throwsVortexException() {
8176
long[] data = {1L, 2L, 4L};
8277

8378
// When / Then
84-
assertThatThrownBy(() -> sut.encode(I64_DTYPE, data, EncodeTestHelper.testCtx()))
79+
assertThatThrownBy(() -> sut.encode(DTypes.I64, data, EncodeTestHelper.testCtx()))
8580
.isInstanceOf(VortexException.class);
8681
}
8782

@@ -110,7 +105,7 @@ class Decode {
110105
void decode_i64_generatesCorrectSequence(long base, long mul, long[] expected) {
111106
// Given
112107
var sut = new SequenceEncoding();
113-
DecodeContext ctx = makeCtx(intMeta(base, mul), I64_DTYPE, expected.length);
108+
DecodeContext ctx = makeCtx(intMeta(base, mul), DTypes.I64, expected.length);
114109

115110
// When
116111
Array result = sut.decode(ctx);
@@ -128,7 +123,7 @@ void decode_i64_generatesCorrectSequence(long base, long mul, long[] expected) {
128123
void decode_i32_generatesCorrectSequence(long base, long mul, int[] expected) {
129124
// Given
130125
var sut = new SequenceEncoding();
131-
DecodeContext ctx = makeCtx(intMeta(base, mul), I32_DTYPE, expected.length);
126+
DecodeContext ctx = makeCtx(intMeta(base, mul), DTypes.I32, expected.length);
132127

133128
// When
134129
Array result = sut.decode(ctx);
@@ -145,7 +140,7 @@ void decode_i32_generatesCorrectSequence(long base, long mul, int[] expected) {
145140
void decode_f64_generatesCorrectSequence() {
146141
// Given
147142
var sut = new SequenceEncoding();
148-
DecodeContext ctx = makeCtx(f64Meta(1.0, 0.5), F64_DTYPE, 4);
143+
DecodeContext ctx = makeCtx(f64Meta(1.0, 0.5), DTypes.F64, 4);
149144

150145
// When
151146
Array result = sut.decode(ctx);
@@ -163,7 +158,7 @@ void decode_f64_generatesCorrectSequence() {
163158
void decode_f32_generatesCorrectSequence() {
164159
// Given
165160
var sut = new SequenceEncoding();
166-
DecodeContext ctx = makeCtx(f32Meta(0.0f, 1.0f), F32_DTYPE, 3);
161+
DecodeContext ctx = makeCtx(f32Meta(0.0f, 1.0f), DTypes.F32, 3);
167162

168163
// When
169164
Array result = sut.decode(ctx);
@@ -180,7 +175,7 @@ void decode_f32_generatesCorrectSequence() {
180175
void decode_emptySequence_returnsZeroLengthArray() {
181176
// Given
182177
var sut = new SequenceEncoding();
183-
DecodeContext ctx = makeCtx(intMeta(0, 1), I64_DTYPE, 0);
178+
DecodeContext ctx = makeCtx(intMeta(0, 1), DTypes.I64, 0);
184179

185180
// When
186181
Array result = sut.decode(ctx);
@@ -194,7 +189,7 @@ void decode_missingMetadata_throwsVortexException() {
194189
// Given
195190
var sut = new SequenceEncoding();
196191
ArrayNode node = ArrayNode.of(EncodingId.VORTEX_SEQUENCE, null, new ArrayNode[0], new int[0], null);
197-
DecodeContext ctx = new DecodeContext(node, I64_DTYPE, 3, new MemorySegment[0], EncodingRegistry.empty(), Arena.ofAuto());
192+
DecodeContext ctx = new DecodeContext(node, DTypes.I64, 3, new MemorySegment[0], EncodingRegistry.empty(), Arena.ofAuto());
198193

199194
// When / Then
200195
assertThatThrownBy(() -> sut.decode(ctx))

0 commit comments

Comments
 (0)