From 5739cc409dfb546ec82587c003dce232397f8e2e Mon Sep 17 00:00:00 2001 From: tianchen Date: Fri, 12 Jul 2019 17:07:31 +0800 Subject: [PATCH 1/9] ARROW-5918: [Java] Add get to BaseIntVector interface --- .../main/java/org/apache/arrow/vector/BaseIntVector.java | 5 +++++ .../main/java/org/apache/arrow/vector/BigIntVector.java | 5 +++++ .../src/main/java/org/apache/arrow/vector/IntVector.java | 5 +++++ .../main/java/org/apache/arrow/vector/SmallIntVector.java | 5 +++++ .../main/java/org/apache/arrow/vector/TinyIntVector.java | 5 +++++ .../src/main/java/org/apache/arrow/vector/UInt1Vector.java | 5 +++++ .../src/main/java/org/apache/arrow/vector/UInt2Vector.java | 5 +++++ .../src/main/java/org/apache/arrow/vector/UInt4Vector.java | 5 +++++ .../src/main/java/org/apache/arrow/vector/UInt8Vector.java | 5 +++++ .../apache/arrow/vector/dictionary/DictionaryEncoder.java | 7 ++++--- 10 files changed, 49 insertions(+), 3 deletions(-) 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..1bac5b564ed53 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 @@ -26,4 +26,9 @@ public interface BaseIntVector extends ValueVector { * set value at specific index, note this value may need to be need truncated. */ void setWithPossibleTruncate(int index, long value); + + /** + * get value at specific index, note this value may haven been extended to long. + */ + 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..4313fc150f3b6 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,11 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(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..6b7fbad4bb5be 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,11 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(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..a801ef52c1865 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,11 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(index, (int) value); } + @Override + public long getValueAsLong(int index) { + return 0; + } + 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..7a8febc37f6dc 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,11 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(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..105acf395c3d5 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,11 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(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..a9f045a9398c8 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,11 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(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..998a2555ae621 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,11 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(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..daf96e7f809e8 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,11 @@ public void setWithPossibleTruncate(int index, long value) { this.setSafe(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 a28ea5b954d05..5fd3db37ae3cf 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); } From 9f2fc0910e07385d5ccddeed4f3b409e269044a1 Mon Sep 17 00:00:00 2001 From: tianchen Date: Fri, 12 Jul 2019 17:09:17 +0800 Subject: [PATCH 2/9] fix --- .../src/main/java/org/apache/arrow/vector/SmallIntVector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a801ef52c1865..34a2426f5bcf9 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 @@ -360,7 +360,7 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { - return 0; + return this.get(index); } private class TransferImpl implements TransferPair { From 9b8afa6a045de2c1b3b57a4fc71344e9842b43dc Mon Sep 17 00:00:00 2001 From: tianchen Date: Sat, 13 Jul 2019 15:28:49 +0800 Subject: [PATCH 3/9] enable null checking --- .../src/main/java/org/apache/arrow/vector/BaseIntVector.java | 5 +++-- .../src/main/java/org/apache/arrow/vector/BigIntVector.java | 3 +++ .../src/main/java/org/apache/arrow/vector/IntVector.java | 3 +++ .../main/java/org/apache/arrow/vector/SmallIntVector.java | 3 +++ .../src/main/java/org/apache/arrow/vector/TinyIntVector.java | 3 +++ .../src/main/java/org/apache/arrow/vector/UInt1Vector.java | 3 +++ .../src/main/java/org/apache/arrow/vector/UInt2Vector.java | 3 +++ .../src/main/java/org/apache/arrow/vector/UInt4Vector.java | 3 +++ .../src/main/java/org/apache/arrow/vector/UInt8Vector.java | 3 +++ 9 files changed, 27 insertions(+), 2 deletions(-) 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 1bac5b564ed53..156cb835534b4 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,12 +23,13 @@ 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. */ void setWithPossibleTruncate(int index, long value); /** - * get value at specific index, note this value may haven been extended to long. + * Gets the value at index, note this value may haven been extended to long and will throw NPE if + * the value is null. */ 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 4313fc150f3b6..25cf0c75beb8e 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 @@ -329,6 +329,9 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { + if (NULL_CHECKING_ENABLED && isSet(index) == 0) { + throw new IllegalStateException("Value at index is null"); + } return this.get(index); } 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 6b7fbad4bb5be..e325e444bec37 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 @@ -333,6 +333,9 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { + if (NULL_CHECKING_ENABLED && isSet(index) == 0) { + throw new IllegalStateException("Value at index is null"); + } return this.get(index); } 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 34a2426f5bcf9..1f5487c93b792 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 @@ -360,6 +360,9 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { + if (NULL_CHECKING_ENABLED && isSet(index) == 0) { + throw new IllegalStateException("Value at index is null"); + } return this.get(index); } 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 7a8febc37f6dc..8c17711cfc1fc 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 @@ -361,6 +361,9 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { + if (NULL_CHECKING_ENABLED && isSet(index) == 0) { + throw new IllegalStateException("Value at index is null"); + } return this.get(index); } 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 105acf395c3d5..6450711988843 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 @@ -324,6 +324,9 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { + if (NULL_CHECKING_ENABLED && isSet(index) == 0) { + throw new IllegalStateException("Value at index is null"); + } return this.get(index); } 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 a9f045a9398c8..5a1351b2df258 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 @@ -304,6 +304,9 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { + if (NULL_CHECKING_ENABLED && isSet(index) == 0) { + throw new IllegalStateException("Value at index is null"); + } return this.get(index); } 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 998a2555ae621..e1175bd1fc6f1 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 @@ -294,6 +294,9 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { + if (NULL_CHECKING_ENABLED && isSet(index) == 0) { + throw new IllegalStateException("Value at index is null"); + } return this.get(index); } 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 daf96e7f809e8..898a2b11dd058 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 @@ -295,6 +295,9 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { + if (NULL_CHECKING_ENABLED && isSet(index) == 0) { + throw new IllegalStateException("Value at index is null"); + } return this.get(index); } From fe9c2ecda39af7d7730a28de9609c5a95e8791e7 Mon Sep 17 00:00:00 2001 From: tianchen Date: Sat, 13 Jul 2019 15:30:05 +0800 Subject: [PATCH 4/9] fix --- .../src/main/java/org/apache/arrow/vector/BaseIntVector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 156cb835534b4..027c74560bf08 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 @@ -28,7 +28,7 @@ public interface BaseIntVector extends ValueVector { void setWithPossibleTruncate(int index, long value); /** - * Gets the value at index, note this value may haven been extended to long and will throw NPE if + * Gets the value at index, note this value may haven been extended to long and will throw {@link IllegalStateException} if * the value is null. */ long getValueAsLong(int index); From e65473cf92439ff4ab019d6a263aa4c6c3cf8367 Mon Sep 17 00:00:00 2001 From: tianchen Date: Sat, 13 Jul 2019 15:31:33 +0800 Subject: [PATCH 5/9] fix comments --- .../src/main/java/org/apache/arrow/vector/BaseIntVector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 027c74560bf08..b4dde1e97059b 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 @@ -28,7 +28,7 @@ public interface BaseIntVector extends ValueVector { void setWithPossibleTruncate(int index, long value); /** - * Gets the value at index, note this value may haven been extended to long and will throw {@link IllegalStateException} if + * Gets the value at index, note this value may haven been extended to long and will throw Exception if * the value is null. */ long getValueAsLong(int index); From 26d30be8752be856e47e44126da6bad24de27e91 Mon Sep 17 00:00:00 2001 From: tianchen Date: Tue, 16 Jul 2019 12:32:06 +0800 Subject: [PATCH 6/9] fix --- .../src/main/java/org/apache/arrow/vector/BaseIntVector.java | 5 +++-- .../src/main/java/org/apache/arrow/vector/BigIntVector.java | 3 --- .../src/main/java/org/apache/arrow/vector/IntVector.java | 3 --- .../main/java/org/apache/arrow/vector/SmallIntVector.java | 3 --- .../src/main/java/org/apache/arrow/vector/TinyIntVector.java | 3 --- .../src/main/java/org/apache/arrow/vector/UInt1Vector.java | 3 --- .../src/main/java/org/apache/arrow/vector/UInt2Vector.java | 3 --- .../src/main/java/org/apache/arrow/vector/UInt4Vector.java | 3 --- .../src/main/java/org/apache/arrow/vector/UInt8Vector.java | 3 --- 9 files changed, 3 insertions(+), 26 deletions(-) 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 b4dde1e97059b..805fb879a8af3 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 @@ -28,8 +28,9 @@ public interface BaseIntVector extends ValueVector { void setWithPossibleTruncate(int index, long value); /** - * Gets the value at index, note this value may haven been extended to long and will throw Exception if - * the value is null. + * 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 25cf0c75beb8e..95621d1700e64 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 @@ -109,9 +109,6 @@ public MinorType getMinorType() { * @return element at given index */ public long get(int index) throws IllegalStateException { - if (NULL_CHECKING_ENABLED && isSet(index) == 0) { - throw new IllegalStateException("Value at index is null"); - } return valueBuffer.getLong(index * TYPE_WIDTH); } 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 e325e444bec37..6b7fbad4bb5be 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 @@ -333,9 +333,6 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { - if (NULL_CHECKING_ENABLED && isSet(index) == 0) { - throw new IllegalStateException("Value at index is null"); - } return this.get(index); } 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 1f5487c93b792..34a2426f5bcf9 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 @@ -360,9 +360,6 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { - if (NULL_CHECKING_ENABLED && isSet(index) == 0) { - throw new IllegalStateException("Value at index is null"); - } return this.get(index); } 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 8c17711cfc1fc..7a8febc37f6dc 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 @@ -361,9 +361,6 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { - if (NULL_CHECKING_ENABLED && isSet(index) == 0) { - throw new IllegalStateException("Value at index is null"); - } return this.get(index); } 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 6450711988843..105acf395c3d5 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 @@ -324,9 +324,6 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { - if (NULL_CHECKING_ENABLED && isSet(index) == 0) { - throw new IllegalStateException("Value at index is null"); - } return this.get(index); } 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 5a1351b2df258..a9f045a9398c8 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 @@ -304,9 +304,6 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { - if (NULL_CHECKING_ENABLED && isSet(index) == 0) { - throw new IllegalStateException("Value at index is null"); - } return this.get(index); } 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 e1175bd1fc6f1..998a2555ae621 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 @@ -294,9 +294,6 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { - if (NULL_CHECKING_ENABLED && isSet(index) == 0) { - throw new IllegalStateException("Value at index is null"); - } return this.get(index); } 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 898a2b11dd058..daf96e7f809e8 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 @@ -295,9 +295,6 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { - if (NULL_CHECKING_ENABLED && isSet(index) == 0) { - throw new IllegalStateException("Value at index is null"); - } return this.get(index); } From 7ddce12081e83bf57b4b56a835e47bdb41675e0b Mon Sep 17 00:00:00 2001 From: tianchen Date: Thu, 18 Jul 2019 14:50:58 +0800 Subject: [PATCH 7/9] fix --- .../src/main/java/org/apache/arrow/vector/BigIntVector.java | 3 --- 1 file changed, 3 deletions(-) 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 95621d1700e64..911bc66b7a195 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 @@ -326,9 +326,6 @@ public void setWithPossibleTruncate(int index, long value) { @Override public long getValueAsLong(int index) { - if (NULL_CHECKING_ENABLED && isSet(index) == 0) { - throw new IllegalStateException("Value at index is null"); - } return this.get(index); } From 1562ae183df9dd261c44575b55d625adaec852d4 Mon Sep 17 00:00:00 2001 From: tianchen Date: Thu, 18 Jul 2019 14:53:49 +0800 Subject: [PATCH 8/9] fix 2 --- .../src/main/java/org/apache/arrow/vector/BigIntVector.java | 3 +++ 1 file changed, 3 insertions(+) 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 911bc66b7a195..4313fc150f3b6 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 @@ -109,6 +109,9 @@ public MinorType getMinorType() { * @return element at given index */ public long get(int index) throws IllegalStateException { + if (NULL_CHECKING_ENABLED && isSet(index) == 0) { + throw new IllegalStateException("Value at index is null"); + } return valueBuffer.getLong(index * TYPE_WIDTH); } From 3732a78b3a74692458c7191ee8ae3361b3cceb68 Mon Sep 17 00:00:00 2001 From: tianchen Date: Fri, 19 Jul 2019 12:02:25 +0800 Subject: [PATCH 9/9] update javadoc and add unsafe method in BaseIntVector --- .../main/java/org/apache/arrow/vector/BaseIntVector.java | 7 +++++++ .../main/java/org/apache/arrow/vector/BigIntVector.java | 5 +++++ .../src/main/java/org/apache/arrow/vector/IntVector.java | 5 +++++ .../main/java/org/apache/arrow/vector/SmallIntVector.java | 5 +++++ .../main/java/org/apache/arrow/vector/TinyIntVector.java | 5 +++++ .../src/main/java/org/apache/arrow/vector/UInt1Vector.java | 5 +++++ .../src/main/java/org/apache/arrow/vector/UInt2Vector.java | 5 +++++ .../src/main/java/org/apache/arrow/vector/UInt4Vector.java | 5 +++++ .../src/main/java/org/apache/arrow/vector/UInt8Vector.java | 5 +++++ 9 files changed, 47 insertions(+) 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 805fb879a8af3..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 @@ -24,9 +24,16 @@ public interface BaseIntVector extends ValueVector { /** * 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} 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 4313fc150f3b6..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,11 @@ 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); 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 6b7fbad4bb5be..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,11 @@ 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); 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 34a2426f5bcf9..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,11 @@ 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); 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 7a8febc37f6dc..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,11 @@ 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); 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 105acf395c3d5..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,11 @@ 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); 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 a9f045a9398c8..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,11 @@ 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); 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 998a2555ae621..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,11 @@ 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); 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 daf96e7f809e8..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,11 @@ 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);