Skip to content

Commit 5e58788

Browse files
dfa1claude
andcommitted
refactor: use record patterns for full-component access (S6878)
Convert type-pattern bindings whose variable was used only to call every component accessor into record deconstruction patterns, e.g. case DType.Bool b -> ... b.nullable() case DType.Bool(var nullable) -> ... nullable Matches the existing idiom in SchemaCommand.formatDType and clears Sonar java:S6878. 26 sites across PredicateEvaluator, VortexWriter.serializeDType, VariantEncodingEncoder, MaskedEncodingEncoder, CascadingCompressor, VortexGridTui, JdbcImporter. Cases accessing only a subset (DType.Primitive->nullable in isMaskable, DType.Extension, Predicate.Between) are left as plain bindings so no unused component binding is introduced. Behavior-preserving; the Rust interop oracle confirms serializeDType stays byte-identical. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 9909bbf commit 5e58788

7 files changed

Lines changed: 52 additions & 52 deletions

File tree

cli/src/main/java/io/github/dfa1/vortex/cli/tui/VortexGridTui.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ private boolean handle(Key key) {
127127
jumpCol(totalCols - 1);
128128
yield true;
129129
}
130-
case Key.Char c when c.value() == 'g' -> {
130+
case Key.Char(var value) when value == 'g' -> {
131131
jumpRow(0);
132132
yield true;
133133
}
134-
case Key.Char c when c.value() == 'G' -> {
134+
case Key.Char(var value) when value == 'G' -> {
135135
jumpRow(totalRows - 1);
136136
yield true;
137137
}
138-
case Key.Char c when c.value() == 'q' -> false;
138+
case Key.Char(var value) when value == 'q' -> false;
139139
case Key.Escape _ -> false;
140140
case Key.Eof _ -> false;
141141
default -> true;

jdbc/src/main/java/io/github/dfa1/vortex/jdbc/JdbcImporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private static boolean isMaskable(DType dt) {
151151
// Bool nullable not yet wired (no Bool inner encoding on MaskedEncoding fallback).
152152
return switch (dt) {
153153
case DType.Primitive p -> p.nullable();
154-
case DType.Utf8 u -> u.nullable();
154+
case DType.Utf8(var nullable) -> nullable;
155155
default -> false;
156156
};
157157
}

reader/src/main/java/io/github/dfa1/vortex/reader/compute/PredicateEvaluator.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ private PredicateEvaluator() {
2525
/// @return `true` if the value at `i` satisfies `predicate`
2626
static boolean evaluate(Array array, long i, Predicate predicate) {
2727
return switch (predicate) {
28-
case Predicate.Eq eq -> !Values.isNullAt(array, i)
29-
&& Compare.values(Values.valueAt(array, i), eq.value(), array.dtype()) == 0;
30-
case Predicate.Neq neq -> !Values.isNullAt(array, i)
31-
&& Compare.values(Values.valueAt(array, i), neq.value(), array.dtype()) != 0;
32-
case Predicate.Lt lt -> !Values.isNullAt(array, i)
33-
&& Compare.values(Values.valueAt(array, i), lt.value(), array.dtype()) < 0;
34-
case Predicate.Gt gt -> !Values.isNullAt(array, i)
35-
&& Compare.values(Values.valueAt(array, i), gt.value(), array.dtype()) > 0;
36-
case Predicate.Lte lte -> !Values.isNullAt(array, i)
37-
&& Compare.values(Values.valueAt(array, i), lte.value(), array.dtype()) <= 0;
38-
case Predicate.Gte gte -> !Values.isNullAt(array, i)
39-
&& Compare.values(Values.valueAt(array, i), gte.value(), array.dtype()) >= 0;
28+
case Predicate.Eq(var value) -> !Values.isNullAt(array, i)
29+
&& Compare.values(Values.valueAt(array, i), value, array.dtype()) == 0;
30+
case Predicate.Neq(var value) -> !Values.isNullAt(array, i)
31+
&& Compare.values(Values.valueAt(array, i), value, array.dtype()) != 0;
32+
case Predicate.Lt(var value) -> !Values.isNullAt(array, i)
33+
&& Compare.values(Values.valueAt(array, i), value, array.dtype()) < 0;
34+
case Predicate.Gt(var value) -> !Values.isNullAt(array, i)
35+
&& Compare.values(Values.valueAt(array, i), value, array.dtype()) > 0;
36+
case Predicate.Lte(var value) -> !Values.isNullAt(array, i)
37+
&& Compare.values(Values.valueAt(array, i), value, array.dtype()) <= 0;
38+
case Predicate.Gte(var value) -> !Values.isNullAt(array, i)
39+
&& Compare.values(Values.valueAt(array, i), value, array.dtype()) >= 0;
4040
case Predicate.Between between -> evaluateBetween(array, i, between);
4141
case Predicate.IsNull _ -> Values.isNullAt(array, i);
4242
case Predicate.IsNotNull _ -> !Values.isNullAt(array, i);
43-
case Predicate.And and -> evaluate(array, i, and.left()) && evaluate(array, i, and.right());
44-
case Predicate.Or or -> evaluate(array, i, or.left()) || evaluate(array, i, or.right());
43+
case Predicate.And(var left, var right) -> evaluate(array, i, left) && evaluate(array, i, right);
44+
case Predicate.Or(var left, var right) -> evaluate(array, i, left) || evaluate(array, i, right);
4545
};
4646
}
4747

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -300,44 +300,44 @@ private static int serializeDType(FbsBuilder fbb, DType dtype) {
300300
int inner = io.github.dfa1.vortex.core.fbs.FbsNull.endFbsNull(fbb);
301301
yield io.github.dfa1.vortex.core.fbs.FbsDType.createFbsDType(fbb, FbsType.FbsNull, inner);
302302
}
303-
case DType.Bool b -> {
304-
int inner = io.github.dfa1.vortex.core.fbs.FbsBool.createFbsBool(fbb, b.nullable());
303+
case DType.Bool(var nullable) -> {
304+
int inner = io.github.dfa1.vortex.core.fbs.FbsBool.createFbsBool(fbb, nullable);
305305
yield io.github.dfa1.vortex.core.fbs.FbsDType.createFbsDType(fbb, FbsType.FbsBool, inner);
306306
}
307-
case DType.Primitive p -> {
307+
case DType.Primitive(var ptype, var nullable) -> {
308308
int inner = io.github.dfa1.vortex.core.fbs.FbsPrimitive.createFbsPrimitive(
309-
fbb, p.ptype().ordinal(), p.nullable());
309+
fbb, ptype.ordinal(), nullable);
310310
yield io.github.dfa1.vortex.core.fbs.FbsDType.createFbsDType(fbb, FbsType.FbsPrimitive, inner);
311311
}
312-
case DType.Struct s -> {
312+
case DType.Struct(var fieldNames, var fieldTypes, var nullable) -> {
313313
// Build child DType tables first (FlatBuffers bottom-up requirement)
314-
int[] fieldOffsets = new int[s.fieldTypes().size()];
314+
int[] fieldOffsets = new int[fieldTypes.size()];
315315
for (int i = 0; i < fieldOffsets.length; i++) {
316-
fieldOffsets[i] = serializeDType(fbb, s.fieldTypes().get(i));
316+
fieldOffsets[i] = serializeDType(fbb, fieldTypes.get(i));
317317
}
318-
int[] nameOffsets = new int[s.fieldNames().size()];
318+
int[] nameOffsets = new int[fieldNames.size()];
319319
for (int i = 0; i < nameOffsets.length; i++) {
320-
nameOffsets[i] = fbb.createString(s.fieldNames().get(i).value());
320+
nameOffsets[i] = fbb.createString(fieldNames.get(i).value());
321321
}
322322
int namesVec = io.github.dfa1.vortex.core.fbs.FbsStruct_.createNamesVector(fbb, nameOffsets);
323323
int dtypesVec = io.github.dfa1.vortex.core.fbs.FbsStruct_.createDtypesVector(fbb, fieldOffsets);
324324
int inner = io.github.dfa1.vortex.core.fbs.FbsStruct_.createFbsStruct_(
325-
fbb, namesVec, dtypesVec, s.nullable());
325+
fbb, namesVec, dtypesVec, nullable);
326326
yield io.github.dfa1.vortex.core.fbs.FbsDType.createFbsDType(fbb, FbsType.FbsStruct_, inner);
327327
}
328-
case DType.Utf8 u -> {
329-
int inner = io.github.dfa1.vortex.core.fbs.FbsUtf8.createFbsUtf8(fbb, u.nullable());
328+
case DType.Utf8(var nullable) -> {
329+
int inner = io.github.dfa1.vortex.core.fbs.FbsUtf8.createFbsUtf8(fbb, nullable);
330330
yield io.github.dfa1.vortex.core.fbs.FbsDType.createFbsDType(fbb, FbsType.FbsUtf8, inner);
331331
}
332-
case DType.List l -> {
333-
int elemTypeOff = serializeDType(fbb, l.elementType());
334-
int inner = io.github.dfa1.vortex.core.fbs.FbsList.createFbsList(fbb, elemTypeOff, l.nullable());
332+
case DType.List(var elementType, var nullable) -> {
333+
int elemTypeOff = serializeDType(fbb, elementType);
334+
int inner = io.github.dfa1.vortex.core.fbs.FbsList.createFbsList(fbb, elemTypeOff, nullable);
335335
yield io.github.dfa1.vortex.core.fbs.FbsDType.createFbsDType(fbb, FbsType.FbsList, inner);
336336
}
337-
case DType.FixedSizeList fsl -> {
338-
int elemTypeOff = serializeDType(fbb, fsl.elementType());
337+
case DType.FixedSizeList(var elementType, var fixedSize, var nullable) -> {
338+
int elemTypeOff = serializeDType(fbb, elementType);
339339
int inner = io.github.dfa1.vortex.core.fbs.FbsFixedSizeList.createFbsFixedSizeList(
340-
fbb, elemTypeOff, fsl.fixedSize(), fsl.nullable());
340+
fbb, elemTypeOff, fixedSize, nullable);
341341
yield io.github.dfa1.vortex.core.fbs.FbsDType.createFbsDType(fbb, FbsType.FbsFixedSizeList, inner);
342342
}
343343
case DType.Extension e -> {
@@ -351,8 +351,8 @@ private static int serializeDType(FbsBuilder fbb, DType dtype) {
351351
int inner = FbsExtension.createFbsExtension(fbb, idOff, storageDtypeOff, metaOff);
352352
yield io.github.dfa1.vortex.core.fbs.FbsDType.createFbsDType(fbb, FbsType.FbsExtension, inner);
353353
}
354-
case DType.Variant v -> {
355-
int inner = io.github.dfa1.vortex.core.fbs.FbsVariant.createFbsVariant(fbb, v.nullable());
354+
case DType.Variant(var nullable) -> {
355+
int inner = io.github.dfa1.vortex.core.fbs.FbsVariant.createFbsVariant(fbb, nullable);
356356
yield io.github.dfa1.vortex.core.fbs.FbsDType.createFbsDType(fbb, FbsType.FbsVariant, inner);
357357
}
358358
default -> throw new UnsupportedOperationException("unsupported DType: " + dtype);

writer/src/main/java/io/github/dfa1/vortex/writer/encode/CascadingCompressor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public CascadingCompressor(List<EncodingEncoder> encodings) {
2929

3030
private static int dataLength(Object data) {
3131
return switch (data) {
32-
case StructData sd -> sd.fieldArrays().isEmpty() ? 0 : dataLength(sd.fieldArrays().getFirst());
32+
case StructData(var fieldArrays) -> fieldArrays.isEmpty() ? 0 : dataLength(fieldArrays.getFirst());
3333
case byte[] a -> a.length;
3434
case short[] a -> a.length;
3535
case int[] a -> a.length;
@@ -48,8 +48,8 @@ private static int dataLength(Object data) {
4848
/// Falls back to first-N when the data is short enough for one stride to span it.
4949
private static Object stratifiedSample(Object data, int sampleSize, long seed) {
5050
return switch (data) {
51-
case StructData sd -> {
52-
List<Object> sliced = sd.fieldArrays().stream()
51+
case StructData(var fieldArrays) -> {
52+
List<Object> sliced = fieldArrays.stream()
5353
.map(f -> stratifiedSample(f, sampleSize, seed)).toList();
5454
yield new StructData(sliced);
5555
}

writer/src/main/java/io/github/dfa1/vortex/writer/encode/MaskedEncodingEncoder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public boolean accepts(DType dtype) {
3030

3131
@Override
3232
public EncodeResult encode(DType dtype, Object data, EncodeContext ctx) {
33-
if (!(data instanceof NullableData nd)) {
33+
if (!(data instanceof NullableData(var values, var validity))) {
3434
throw new VortexException(EncodingId.VORTEX_MASKED,
3535
"expected NullableData, got " + (data == null ? "null" : data.getClass().getName()));
3636
}
3737
DType nonNullable = dtype.withNullable(false);
3838
EncodingEncoder inner = pickInner(nonNullable);
39-
EncodeResult valuesResult = inner.encode(nonNullable, nd.values(), ctx);
40-
EncodeResult validityResult = new BoolEncodingEncoder().encode(DType.BOOL, nd.validity(), ctx);
39+
EncodeResult valuesResult = inner.encode(nonNullable, values, ctx);
40+
EncodeResult validityResult = new BoolEncodingEncoder().encode(DType.BOOL, validity, ctx);
4141

4242
int valuesBufCount = valuesResult.buffers().size();
4343
EncodeNode validityNode = EncodeNode.remapBufferIndices(validityResult.rootNode(), valuesBufCount);

writer/src/main/java/io/github/dfa1/vortex/writer/encode/VariantEncodingEncoder.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ private static EncodeNode encodeShredded(VariantData data, EncodeContext ctx, Li
9999
/// Converts a shreddable scalar dtype to its protobuf form for `ProtoVariantMetadata`.
100100
private static io.github.dfa1.vortex.core.proto.ProtoDType toProtoDtype(DType dtype) {
101101
return switch (dtype) {
102-
case DType.Primitive p -> io.github.dfa1.vortex.core.proto.ProtoDType.ofPrimitive(
102+
case DType.Primitive(var ptype, var nullable) -> io.github.dfa1.vortex.core.proto.ProtoDType.ofPrimitive(
103103
new io.github.dfa1.vortex.core.proto.ProtoPrimitive(
104-
io.github.dfa1.vortex.core.proto.ProtoPType.fromValue(p.ptype().ordinal()), p.nullable()));
105-
case DType.Bool b -> io.github.dfa1.vortex.core.proto.ProtoDType.ofBool(
106-
new io.github.dfa1.vortex.core.proto.ProtoBool(b.nullable()));
107-
case DType.Utf8 u -> io.github.dfa1.vortex.core.proto.ProtoDType.ofUtf8(
108-
new io.github.dfa1.vortex.core.proto.ProtoUtf8(u.nullable()));
109-
case DType.Binary bin -> io.github.dfa1.vortex.core.proto.ProtoDType.ofBinary(
110-
new io.github.dfa1.vortex.core.proto.ProtoBinary(bin.nullable()));
104+
io.github.dfa1.vortex.core.proto.ProtoPType.fromValue(ptype.ordinal()), nullable));
105+
case DType.Bool(var nullable) -> io.github.dfa1.vortex.core.proto.ProtoDType.ofBool(
106+
new io.github.dfa1.vortex.core.proto.ProtoBool(nullable));
107+
case DType.Utf8(var nullable) -> io.github.dfa1.vortex.core.proto.ProtoDType.ofUtf8(
108+
new io.github.dfa1.vortex.core.proto.ProtoUtf8(nullable));
109+
case DType.Binary(var nullable) -> io.github.dfa1.vortex.core.proto.ProtoDType.ofBinary(
110+
new io.github.dfa1.vortex.core.proto.ProtoBinary(nullable));
111111
default -> throw new VortexException(EncodingId.VORTEX_VARIANT,
112112
"shredded dtype not supported: " + dtype);
113113
};

0 commit comments

Comments
 (0)