Skip to content

Commit

Permalink
ARROW-5918: [Java] Add get to BaseIntVector interface
Browse files Browse the repository at this point in the history
Related to [ARROW-5918](https://issues.apache.org/jira/browse/ARROW-5918).

Author: tianchen <[email protected]>

Closes #4859 from tianchen92/ARROW-5918 and squashes the following commits:

3732a78 <tianchen> update javadoc and add unsafe method in BaseIntVector
1562ae1 <tianchen> fix 2
7ddce12 <tianchen> fix
26d30be <tianchen> fix
e65473c <tianchen> fix comments
fe9c2ec <tianchen> fix
9b8afa6 <tianchen> enable null checking
9f2fc09 <tianchen> fix
5739cc4 <tianchen> ARROW-5918:  Add get to BaseIntVector interface
  • Loading branch information
tianchen92 authored and kszucs committed Jul 22, 2019
1 parent b5b2522 commit 169abf8
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions java/vector/src/main/java/org/apache/arrow/vector/IntVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 169abf8

Please sign in to comment.