Skip to content

Commit 95e985c

Browse files
committed
PR feedback and add tests
1 parent 1b44cbe commit 95e985c

6 files changed

Lines changed: 319 additions & 80 deletions

File tree

parquet-variant/src/main/java/org/apache/parquet/variant/MalformedVariantException.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

parquet-variant/src/main/java/org/apache/parquet/variant/Variant.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public Variant(byte[] value, int valuePos, int valueLength, byte[] metadata, int
4848
}
4949

5050
public Variant(ByteBuffer value, ByteBuffer metadata) {
51-
// THe buffers are read single-byte at a time, so the endianness of the input buffers
52-
// are not important.
51+
// The buffers are read a single-byte at a time, so the endianness of the input buffers
52+
// is not important.
5353
this.value = value.asReadOnlyBuffer();
5454
this.metadata = metadata.asReadOnlyBuffer();
5555

@@ -72,33 +72,21 @@ public boolean getBoolean() {
7272
* @return the byte value
7373
*/
7474
public byte getByte() {
75-
long longValue = VariantUtil.getLong(value);
76-
if (longValue < Byte.MIN_VALUE || longValue > Byte.MAX_VALUE) {
77-
throw new IllegalStateException("Value out of range for byte: " + longValue);
78-
}
79-
return (byte) longValue;
75+
return VariantUtil.getByte(value);
8076
}
8177

8278
/**
8379
* @return the short value
8480
*/
8581
public short getShort() {
86-
long longValue = VariantUtil.getLong(value);
87-
if (longValue < Short.MIN_VALUE || longValue > Short.MAX_VALUE) {
88-
throw new IllegalStateException("Value out of range for short: " + longValue);
89-
}
90-
return (short) longValue;
82+
return VariantUtil.getShort(value);
9183
}
9284

9385
/**
9486
* @return the int value
9587
*/
9688
public int getInt() {
97-
long longValue = VariantUtil.getLong(value);
98-
if (longValue < Integer.MIN_VALUE || longValue > Integer.MAX_VALUE) {
99-
throw new IllegalStateException("Value out of range for int: " + longValue);
100-
}
101-
return (int) longValue;
89+
return VariantUtil.getInt(value);
10290
}
10391

10492
/**
@@ -173,7 +161,7 @@ public enum Type {
173161
FLOAT,
174162
BINARY,
175163
TIME,
176-
TIMESTAMP_NANOS,
164+
TIMESTAMP_NANOS_TZ,
177165
TIMESTAMP_NANOS_NTZ,
178166
UUID
179167
}
@@ -186,17 +174,19 @@ public Type getType() {
186174
}
187175

188176
/**
189-
* @return the number of object fields in the variant. `getType()` must be `Type.OBJECT`.
177+
* @return the number of object fields in the variant
178+
* @throws IllegalArgumentException if `getType()` does not return `Type.OBJECT`
190179
*/
191180
public int numObjectElements() {
192181
return VariantUtil.getObjectInfo(value).numElements;
193182
}
194183

195184
/**
196185
* Returns the object field Variant value whose key is equal to `key`.
197-
* Return null if the key is not found. `getType()` must be `Type.OBJECT`.
186+
* Returns null if the key is not found.
198187
* @param key the key to look up
199188
* @return the field value whose key is equal to `key`, or null if key is not found
189+
* @throws IllegalArgumentException if `getType()` does not return `Type.OBJECT`
200190
*/
201191
public Variant getFieldByKey(String key) {
202192
VariantUtil.ObjectInfo info = VariantUtil.getObjectInfo(value);
@@ -250,7 +240,7 @@ public Variant getFieldByKey(String key) {
250240
/**
251241
* A field in a Variant object.
252242
*/
253-
public static final class ObjectField {
243+
static final class ObjectField {
254244
public final String key;
255245
public final Variant value;
256246

@@ -278,17 +268,19 @@ private static ObjectField getFieldAtIndex(
278268
}
279269

280270
/**
281-
* @return the number of array elements. `getType()` must be `Type.ARRAY`.
271+
* @return the number of array elements
272+
* @throws IllegalArgumentException if `getType()` does not return `Type.ARRAY`
282273
*/
283274
public int numArrayElements() {
284275
return VariantUtil.getArrayInfo(value).numElements;
285276
}
286277

287278
/**
288279
* Returns the array element Variant value at the `index` slot. Returns null if `index` is
289-
* out of the bound of `[0, arraySize())`. `getType()` must be `Type.ARRAY`.
280+
* out of the bound of `[0, arraySize())`.
290281
* @param index the index of the array element to get
291282
* @return the array element Variant at the `index` slot, or null if `index` is out of bounds
283+
* @throws IllegalArgumentException if `getType()` does not return `Type.ARRAY`
292284
*/
293285
public Variant getElementAtIndex(int index) {
294286
VariantUtil.ArrayInfo info = VariantUtil.getArrayInfo(value);

0 commit comments

Comments
 (0)