Skip to content

Commit 1b44cbe

Browse files
committed
Review feedback
1 parent 3e3d521 commit 1b44cbe

6 files changed

Lines changed: 234 additions & 384 deletions

File tree

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

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

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

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,23 @@ public final class Variant {
4040
static final int BINARY_SEARCH_THRESHOLD = 32;
4141

4242
public Variant(byte[] value, byte[] metadata) {
43-
this(value, 0, metadata, 0);
43+
this(value, 0, value.length, metadata, 0, metadata.length);
4444
}
4545

46-
Variant(byte[] value, int valuePos, byte[] metadata, int metadataPos) {
47-
this(
48-
ByteBuffer.wrap(value, valuePos, value.length - valuePos),
49-
ByteBuffer.wrap(metadata, metadataPos, metadata.length - metadataPos));
46+
public Variant(byte[] value, int valuePos, int valueLength, byte[] metadata, int metadataPos, int metadataLength) {
47+
this(ByteBuffer.wrap(value, valuePos, valueLength), ByteBuffer.wrap(metadata, metadataPos, metadataLength));
5048
}
5149

52-
Variant(ByteBuffer value, ByteBuffer metadata) {
50+
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.
5353
this.value = value.asReadOnlyBuffer();
54-
this.value.mark();
55-
5654
this.metadata = metadata.asReadOnlyBuffer();
57-
this.metadata.mark();
5855

5956
// There is currently only one allowed version.
6057
if ((metadata.get(metadata.position()) & VariantUtil.VERSION_MASK) != VariantUtil.VERSION) {
6158
throw new UnsupportedOperationException(String.format(
62-
"Unsupported variant metadata version: %02X",
59+
"Unsupported variant metadata version: %d",
6360
metadata.get(metadata.position()) & VariantUtil.VERSION_MASK));
6461
}
6562
}
@@ -135,7 +132,7 @@ public float getFloat() {
135132
/**
136133
* @return the binary value
137134
*/
138-
public byte[] getBinary() {
135+
public ByteBuffer getBinary() {
139136
return VariantUtil.getBinary(value);
140137
}
141138

@@ -153,10 +150,38 @@ public String getString() {
153150
return VariantUtil.getString(value);
154151
}
155152

153+
/**
154+
* The value type of Variant value. It is determined by the header byte.
155+
*/
156+
public enum Type {
157+
OBJECT,
158+
ARRAY,
159+
NULL,
160+
BOOLEAN,
161+
BYTE,
162+
SHORT,
163+
INT,
164+
LONG,
165+
STRING,
166+
DOUBLE,
167+
DECIMAL4,
168+
DECIMAL8,
169+
DECIMAL16,
170+
DATE,
171+
TIMESTAMP_TZ,
172+
TIMESTAMP_NTZ,
173+
FLOAT,
174+
BINARY,
175+
TIME,
176+
TIMESTAMP_NANOS,
177+
TIMESTAMP_NANOS_NTZ,
178+
UUID
179+
}
180+
156181
/**
157182
* @return the type of the variant value
158183
*/
159-
public VariantUtil.Type getType() {
184+
public Type getType() {
160185
return VariantUtil.getType(value);
161186
}
162187

0 commit comments

Comments
 (0)