diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseIntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseIntVector.java index 6b5b53aa726bc..57ad645c87394 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseIntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseIntVector.java @@ -23,7 +23,21 @@ public interface BaseIntVector extends ValueVector { /** - * set value at specific index, note this value may need to be need truncated. + * Sets the value at index, note this value may need to be need truncated. + * Note this is safe version (i.e. call setSafe method in vector) */ void setWithPossibleTruncate(int index, long value); + + /** + * Sets the value at index, note this value may need to be need truncated. + * Note this is unsafe version (i.e. call set method in vector) + */ + void setUnsafeWithPossibleTruncate(int index, long value); + + /** + * Gets the value at index. + * This value may have been extended to long and will throw {@link NullPointerException} + * if the value is null. Note null check could be turned off via {@link NullCheckingForGet}. + */ + long getValueAsLong(int index); } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BigIntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BigIntVector.java index 2c75a8d7557b5..8b9404b7a281c 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BigIntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BigIntVector.java @@ -327,6 +327,16 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(index, value); } + @Override + public void setUnsafeWithPossibleTruncate(int index, long value) { + this.set(index, value); + } + + @Override + public long getValueAsLong(int index) { + return this.get(index); + } + private class TransferImpl implements TransferPair { BigIntVector to; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/IntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/IntVector.java index e4deabaf01546..61235e0de5224 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/IntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/IntVector.java @@ -331,6 +331,16 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(index, (int) value); } + @Override + public void setUnsafeWithPossibleTruncate(int index, long value) { + this.set(index, (int) value); + } + + @Override + public long getValueAsLong(int index) { + return this.get(index); + } + private class TransferImpl implements TransferPair { IntVector to; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/SmallIntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/SmallIntVector.java index f1f064bdb0379..52ecd59b09846 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/SmallIntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/SmallIntVector.java @@ -358,6 +358,16 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(index, (int) value); } + @Override + public void setUnsafeWithPossibleTruncate(int index, long value) { + this.set(index, (int) value); + } + + @Override + public long getValueAsLong(int index) { + return this.get(index); + } + private class TransferImpl implements TransferPair { SmallIntVector to; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TinyIntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TinyIntVector.java index d74adf24aad49..ebac2fcec3d87 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TinyIntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TinyIntVector.java @@ -359,6 +359,16 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(index, (int) value); } + @Override + public void setUnsafeWithPossibleTruncate(int index, long value) { + this.set(index, (int) value); + } + + @Override + public long getValueAsLong(int index) { + return this.get(index); + } + private class TransferImpl implements TransferPair { TinyIntVector to; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java index 8e6d4fe581130..df3759e7c2d49 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java @@ -322,6 +322,16 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(index, (int) value); } + @Override + public void setUnsafeWithPossibleTruncate(int index, long value) { + this.set(index, (int) value); + } + + @Override + public long getValueAsLong(int index) { + return this.get(index); + } + private class TransferImpl implements TransferPair { diff --git a/java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java index 53bb16753ec5d..e39e5e2646e34 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java @@ -302,6 +302,16 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(index, (int) value); } + @Override + public void setUnsafeWithPossibleTruncate(int index, long value) { + this.set(index, (int) value); + } + + @Override + public long getValueAsLong(int index) { + return this.get(index); + } + private class TransferImpl implements TransferPair { UInt2Vector to; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java index b54b3f78bbd25..8657f067bd657 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java @@ -292,6 +292,16 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(index, (int) value); } + @Override + public void setUnsafeWithPossibleTruncate(int index, long value) { + this.set(index, (int) value); + } + + @Override + public long getValueAsLong(int index) { + return this.get(index); + } + private class TransferImpl implements TransferPair { UInt4Vector to; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java index 2451ab5b2e25d..62a5ba5e4ab03 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java @@ -293,6 +293,16 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(index, value); } + @Override + public void setUnsafeWithPossibleTruncate(int index, long value) { + this.set(index, value); + } + + @Override + public long getValueAsLong(int index) { + return this.get(index); + } + private class TransferImpl implements TransferPair { UInt8Vector to; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/dictionary/DictionaryEncoder.java b/java/vector/src/main/java/org/apache/arrow/vector/dictionary/DictionaryEncoder.java index ed69df3cf4090..9b16bb160ea8a 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/dictionary/DictionaryEncoder.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/dictionary/DictionaryEncoder.java @@ -98,10 +98,11 @@ public static ValueVector decode(ValueVector indices, Dictionary dictionary) { // copy the dictionary values into the decoded vector TransferPair transfer = dictionaryVector.getTransferPair(indices.getAllocator()); transfer.getTo().allocateNewSafe(); + + BaseIntVector baseIntVector = (BaseIntVector) indices; for (int i = 0; i < count; i++) { - Object index = indices.getObject(i); - if (index != null) { - int indexAsInt = ((Number) index).intValue(); + if (!baseIntVector.isNull(i)) { + int indexAsInt = (int) baseIntVector.getValueAsLong(i); if (indexAsInt > dictionaryCount) { throw new IllegalArgumentException("Provided dictionary does not contain value for index " + indexAsInt); }