Skip to content

Commit 4c6ab14

Browse files
dfa1claude
andcommitted
refactor(writer): drop dead ptype arms in readPrimitiveElement
Like primitiveArrayLen, all callers (the global-dict counts/codes loops and the post-exclusion isDictCandidate check) pass only dict-admitted ptypes: I32/U32, I64/U64, F64. Collapse the unreachable I8/U8, I16/U16/F16, F32 arms to default -> throw and add an F64 case to readPrimitiveElementCases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 94d2fa4 commit 4c6ab14

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

writer/src/main/java/io/github/dfa1/vortex/writer/VortexWriter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,14 +1332,15 @@ static int primitiveArrayLen(Object data, PType ptype) {
13321332
};
13331333
}
13341334

1335+
/// Boxed element `i` of a global-dict column's chunk array. Only the dict-admitted carriers
1336+
/// ([#isDictCandidate]) — I32/U32, I64/U64, F64 — reach here; narrow-int and F16/F32 ptypes are
1337+
/// rejected upstream.
13351338
static Object readPrimitiveElement(Object data, PType ptype, int i) {
13361339
return switch (ptype) {
1337-
case I8, U8 -> ((byte[]) data)[i];
1338-
case I16, U16, F16 -> ((short[]) data)[i];
13391340
case I32, U32 -> ((int[]) data)[i];
13401341
case I64, U64 -> ((long[]) data)[i];
1341-
case F32 -> ((float[]) data)[i];
13421342
case F64 -> ((double[]) data)[i];
1343+
default -> throw new IllegalStateException("ptype not admitted to the global dict: " + ptype);
13431344
};
13441345
}
13451346

writer/src/test/java/io/github/dfa1/vortex/writer/VortexWriterDictDecisionTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ void primitiveArrayLen_returnsActualLength(Object data, PType ptype, int expecte
120120
}
121121

122122
static Stream<Arguments> readPrimitiveElementCases() {
123+
// Only dict-admitted ptypes reach readPrimitiveElement: I32/U32, I64/U64, F64.
123124
return Stream.of(
124125
arguments(new long[]{7, 8, 9}, PType.I64, 1, 8L),
125-
arguments(new int[]{7, 8, 9}, PType.I32, 2, 9));
126+
arguments(new int[]{7, 8, 9}, PType.I32, 2, 9),
127+
arguments(new double[]{7.0, 8.0, 9.0}, PType.F64, 0, 7.0));
126128
}
127129

128130
@ParameterizedTest

0 commit comments

Comments
 (0)