Skip to content

Commit 7588aa3

Browse files
dfa1claude
andcommitted
refactor(reader): UnknownArray carries the typed EncodingId
String encodingId predated the sealed EncodingId — a closed enum could not represent an unknown id, so the raw string was the only option. Now the component is typed: a Custom, or a WellKnown whose decoder is not registered. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent b08ace7 commit 7588aa3

6 files changed

Lines changed: 13 additions & 11 deletions

File tree

reader/src/main/java/io/github/dfa1/vortex/reader/ReadRegistry.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public MemorySegment decodeAsSegment(DecodeContext ctx) {
9999
}
100100

101101
private static UnknownArray decodeUnknown(DecodeContext ctx, ArrayNode node) {
102-
String rawId = node.encodingId().id();
103102
MemorySegment[] bufs = new MemorySegment[node.bufferIndices().length];
104103
for (int i = 0; i < bufs.length; i++) {
105104
bufs[i] = ctx.buffer(i);
@@ -113,7 +112,7 @@ private static UnknownArray decodeUnknown(DecodeContext ctx, ArrayNode node) {
113112
children[i] = decodeUnknown(childCtx, childNode);
114113
}
115114
return new UnknownArray(
116-
rawId, ctx.dtype(), ctx.rowCount(),
115+
node.encodingId(), ctx.dtype(), ctx.rowCount(),
117116
node.metadata(), bufs, children);
118117
}
119118

reader/src/main/java/io/github/dfa1/vortex/reader/array/UnknownArray.java

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

33
import io.github.dfa1.vortex.core.model.DType;
4+
import io.github.dfa1.vortex.core.model.EncodingId;
45
import io.github.dfa1.vortex.core.error.VortexException;
56

67
import java.lang.foreign.MemorySegment;
@@ -15,15 +16,15 @@
1516
/// Constructed by `Registry` when `allowUnknown()` is set and an encoding id is not
1617
/// in the registry. Data access beyond `buffer(i)` and `child(i)` is not supported.
1718
///
18-
/// @param encodingId the unrecognized encoding id string
19+
/// @param encodingId the unrecognized encoding id — a [EncodingId.Custom], or a [EncodingId.WellKnown] with no registered decoder
1920
/// @param dtype logical type of the array
2021
/// @param length number of logical rows
2122
/// @param metadata raw encoding metadata bytes, or `null`
2223
/// @param buffers raw data buffers owned by this node
2324
/// @param children decoded child arrays (also wrapped as unknown)
2425
@SuppressWarnings("java:S6218") // internal data carrier; record components are arrays of immutable primitives or refs that flow through pipelines without ever being compared.
2526
public record UnknownArray(
26-
String encodingId,
27+
EncodingId encodingId,
2728
DType dtype,
2829
long length,
2930
MemorySegment metadata,

reader/src/test/java/io/github/dfa1/vortex/reader/ReadRegistryTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void decodeKnownEncodingWithoutDecoderReturnsUnknownArrayWhenAllowed() {
6464

6565
// Then
6666
assertThat(result).isInstanceOf(UnknownArray.class);
67-
assertThat(((UnknownArray) result).encodingId()).isEqualTo("vortex.primitive");
67+
assertThat(((UnknownArray) result).encodingId()).isEqualTo(EncodingId.VORTEX_PRIMITIVE);
6868
}
6969

7070
@Test
@@ -85,7 +85,7 @@ void decodeUnknownEncodingReturnsUnknownArrayWhenAllowed() {
8585
// Then
8686
assertThat(result).isInstanceOf(UnknownArray.class);
8787
UnknownArray unknown = (UnknownArray) result;
88-
assertThat(unknown.encodingId()).isEqualTo("some.unknown");
88+
assertThat(unknown.encodingId()).isEqualTo(new EncodingId.Custom("some.unknown"));
8989
assertThat(unknown.dtype()).isEqualTo(DTypes.I32);
9090
assertThat(unknown.length()).isEqualTo(5L);
9191
assertThat(unknown.metadata()).isEqualTo(metadata);
@@ -114,7 +114,7 @@ void decodeUnknownEncodingWrapsChildrenAsUnknown() {
114114
UnknownArray unknown = (UnknownArray) result;
115115
assertThat(unknown.children()).hasSize(1);
116116
assertThat(unknown.children()[0]).isInstanceOf(UnknownArray.class);
117-
assertThat(((UnknownArray) unknown.children()[0]).encodingId()).isEqualTo("vortex.primitive");
117+
assertThat(((UnknownArray) unknown.children()[0]).encodingId()).isEqualTo(EncodingId.VORTEX_PRIMITIVE);
118118
assertThat(sut.isAllowUnknown()).isTrue();
119119
}
120120

reader/src/test/java/io/github/dfa1/vortex/reader/VortexReaderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public EncodingId encodingId() {
4040
public Array decode(DecodeContext ctx) {
4141
// Generic zero-length stand-in: scan chunk row count comes from the
4242
// layout, so the leaf array's contents are irrelevant to this test.
43-
return new UnknownArray("stub", ctx.dtype(), 0, null,
43+
return new UnknownArray(EncodingId.parse("stub"), ctx.dtype(), 0, null,
4444
new MemorySegment[0], new Array[0]);
4545
}
4646
});
@@ -198,7 +198,7 @@ void scan_withNoDecoders_allowUnknown_returnsUnknownArray(String name) throws UR
198198
for (Array column : chunk.columns().values()) {
199199
assertThat(column).isInstanceOf(UnknownArray.class);
200200
UnknownArray foreign = (UnknownArray) column;
201-
assertThat(foreign.encodingId()).describedAs(name).startsWith("vortex.");
201+
assertThat(foreign.encodingId().id()).describedAs(name).startsWith("vortex.");
202202
}
203203
}
204204
}

reader/src/test/java/io/github/dfa1/vortex/reader/array/ArrayLimitedTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.dfa1.vortex.reader.array;
22

33
import io.github.dfa1.vortex.core.model.DType;
4+
import io.github.dfa1.vortex.core.model.EncodingId;
45
import io.github.dfa1.vortex.core.error.VortexException;
56
import org.junit.jupiter.api.Nested;
67
import org.junit.jupiter.api.Test;
@@ -321,7 +322,7 @@ class Unsupported {
321322
@Test
322323
void unknownArrayThrows() {
323324
// Given
324-
UnknownArray sut = new UnknownArray("vortex.mystery", I64, 3, null,
325+
UnknownArray sut = new UnknownArray(EncodingId.parse("vortex.mystery"), I64, 3, null,
325326
new MemorySegment[0], new Array[0]);
326327

327328
// When / Then

reader/src/test/java/io/github/dfa1/vortex/reader/array/ArrayMaterializeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.dfa1.vortex.reader.array;
22

33
import io.github.dfa1.vortex.core.model.DType;
4+
import io.github.dfa1.vortex.core.model.EncodingId;
45
import io.github.dfa1.vortex.core.error.VortexException;
56
import io.github.dfa1.vortex.core.io.PTypeIO;
67
import org.junit.jupiter.api.Nested;
@@ -303,7 +304,7 @@ void bytePartsDecimalThrows() {
303304
@Test
304305
void unknownArrayThrows() {
305306
// Given an undecoded foreign encoding
306-
UnknownArray sut = new UnknownArray("vortex.mystery", I64, 3, null,
307+
UnknownArray sut = new UnknownArray(EncodingId.parse("vortex.mystery"), I64, 3, null,
307308
new MemorySegment[0], new Array[0]);
308309

309310
// When / Then

0 commit comments

Comments
 (0)