aboutsummaryrefslogtreecommitdiff
path: root/exec/vector
diff options
context:
space:
mode:
authorVlad Rozov <vrozov@apache.org>2018-03-01 09:36:05 -0800
committerVitalii Diravka <vitalii.diravka@gmail.com>2018-04-29 23:20:55 +0300
commit28a29033c0a966b4bd65ac691a7b86f41637cae2 (patch)
tree110b36c9ea054ccc2039888b53a1bb5e2945e818 /exec/vector
parent087b366f211f12e274fd2967767a7fb60e836774 (diff)
DRILL-6202: Deprecate usage of IndexOutOfBoundsException to re-alloc vectors
closes #1144
Diffstat (limited to 'exec/vector')
-rw-r--r--exec/vector/src/main/codegen/templates/VariableLengthVectors.java73
-rw-r--r--exec/vector/src/main/java/org/apache/drill/exec/vector/UntypedNullVector.java21
-rw-r--r--exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/reader/ArrayReaderImpl.java10
-rw-r--r--exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/writer/BaseScalarWriter.java2
-rw-r--r--exec/vector/src/main/java/org/apache/drill/exec/vector/complex/EmptyValuePopulator.java4
5 files changed, 38 insertions, 72 deletions
diff --git a/exec/vector/src/main/codegen/templates/VariableLengthVectors.java b/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
index 58f496868..876d6880d 100644
--- a/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
+++ b/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
@@ -581,15 +581,11 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
assert index >= 0;
final int currentOffset = offsetVector.getAccessor().get(index);
- offsetVector.getMutator().setSafe(index + 1, currentOffset + bytes.length);
- try {
- data.setBytes(currentOffset, bytes, 0, bytes.length);
- } catch (IndexOutOfBoundsException e) {
- while (data.capacity() < currentOffset + bytes.length) {
- reAlloc();
- }
- data.setBytes(currentOffset, bytes, 0, bytes.length);
+ while (data.capacity() < currentOffset + bytes.length) {
+ reAlloc();
}
+ offsetVector.getMutator().setSafe(index + 1, currentOffset + bytes.length);
+ data.setBytes(currentOffset, bytes, 0, bytes.length);
}
/**
@@ -611,15 +607,12 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
assert index >= 0;
final int currentOffset = offsetVector.getAccessor().get(index);
- offsetVector.getMutator().setSafe(index + 1, currentOffset + length);
- try {
- data.setBytes(currentOffset, bytes, start, length);
- } catch (IndexOutOfBoundsException e) {
- while (data.capacity() < currentOffset + length) {
- reAlloc();
- }
- data.setBytes(currentOffset, bytes, start, length);
+
+ while (data.capacity() < currentOffset + length) {
+ reAlloc();
}
+ offsetVector.getMutator().setSafe(index + 1, currentOffset + length);
+ data.setBytes(currentOffset, bytes, start, length);
}
public void setSafe(int index, byte[] bytes, int start, int length) {
@@ -627,15 +620,11 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
final int currentOffset = offsetVector.getAccessor().get(index);
- offsetVector.getMutator().setSafe(index + 1, currentOffset + length);
- try {
- data.setBytes(currentOffset, bytes, start, length);
- } catch (IndexOutOfBoundsException e) {
- while (data.capacity() < currentOffset + length) {
- reAlloc();
- }
- data.setBytes(currentOffset, bytes, start, length);
+ while (data.capacity() < currentOffset + length) {
+ reAlloc();
}
+ offsetVector.getMutator().setSafe(index + 1, currentOffset + length);
+ data.setBytes(currentOffset, bytes, start, length);
}
@Override
@@ -651,15 +640,11 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
final int len = end - start;
final int outputStart = offsetVector.data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width});
- offsetVector.getMutator().setSafe(index+1, outputStart + len);
- try{
- buffer.getBytes(start, data, outputStart, len);
- } catch (IndexOutOfBoundsException e) {
- while (data.capacity() < outputStart + len) {
- reAlloc();
- }
- buffer.getBytes(start, data, outputStart, len);
+ while (data.capacity() < outputStart + len) {
+ reAlloc();
}
+ offsetVector.getMutator().setSafe(index + 1, outputStart + len);
+ buffer.getBytes(start, data, outputStart, len);
}
public void setSafe(int index, Nullable${minor.class}Holder holder) {
@@ -671,15 +656,11 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
final int outputStart = offsetVector.data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width});
- try {
- holder.buffer.getBytes(start, data, outputStart, len);
- } catch (IndexOutOfBoundsException e) {
- while (data.capacity() < outputStart + len) {
- reAlloc();
- }
- holder.buffer.getBytes(start, data, outputStart, len);
+ while (data.capacity() < outputStart + len) {
+ reAlloc();
}
- offsetVector.getMutator().setSafe(index+1, outputStart + len);
+ holder.buffer.getBytes(start, data, outputStart, len);
+ offsetVector.getMutator().setSafe(index + 1, outputStart + len);
}
public void setSafe(int index, ${minor.class}Holder holder) {
@@ -688,15 +669,11 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
final int len = end - start;
final int outputStart = offsetVector.data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width});
- try {
- holder.buffer.getBytes(start, data, outputStart, len);
- } catch (IndexOutOfBoundsException e) {
- while(data.capacity() < outputStart + len) {
- reAlloc();
- }
- holder.buffer.getBytes(start, data, outputStart, len);
+ while(data.capacity() < outputStart + len) {
+ reAlloc();
}
- offsetVector.getMutator().setSafe( index+1, outputStart + len);
+ holder.buffer.getBytes(start, data, outputStart, len);
+ offsetVector.getMutator().setSafe(index + 1, outputStart + len);
}
/**
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/UntypedNullVector.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/UntypedNullVector.java
index 48cae7d14..e2f9f77ac 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/UntypedNullVector.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/UntypedNullVector.java
@@ -145,14 +145,13 @@ public final class UntypedNullVector extends BaseDataValueVector implements Fixe
@Override
public void splitAndTransfer(int startIndex, int length) {
- checkBounds(startIndex);
- checkBounds(startIndex + length - 1);
+ Preconditions.checkPositionIndexes(startIndex, startIndex + length, valueCount);
splitAndTransferTo(startIndex, length, to);
}
@Override
public void copyValueSafe(int fromIndex, int toIndex) {
- checkBounds(fromIndex);
+ Preconditions.checkElementIndex(fromIndex, valueCount);
to.copyFromSafe(fromIndex, toIndex, UntypedNullVector.this);
}
}
@@ -161,12 +160,6 @@ public final class UntypedNullVector extends BaseDataValueVector implements Fixe
public void copyFromSafe(int fromIndex, int thisIndex, UntypedNullVector from) { }
- private void checkBounds(int index) {
- if (index < 0 || index >= valueCount) {
- throw new IndexOutOfBoundsException(String.format(
- "index: %d, expected: range(0, %d-1))", index, valueCount));
- }
- }
@Override
public void copyEntry(int toIndex, ValueVector from, int fromIndex) {
((UntypedNullVector) from).data.getBytes(fromIndex * 4, data, toIndex * 4, 4);
@@ -180,23 +173,23 @@ public final class UntypedNullVector extends BaseDataValueVector implements Fixe
@Override
public boolean isNull(int index){
- checkBounds(index);
+ Preconditions.checkElementIndex(index, valueCount);
return true;
}
public int isSet(int index) {
- checkBounds(index);
+ Preconditions.checkElementIndex(index, valueCount);
return 0;
}
@Override
public Object getObject(int index) {
- checkBounds(index);
+ Preconditions.checkElementIndex(index, valueCount);
return null;
}
public void get(int index, UntypedNullHolder holder) {
- checkBounds(index);
+ Preconditions.checkElementIndex(index, valueCount);
}
}
@@ -247,4 +240,4 @@ public final class UntypedNullVector extends BaseDataValueVector implements Fixe
UntypedNullVector.this.valueCount = valueCount;
}
}
-} \ No newline at end of file
+}
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/reader/ArrayReaderImpl.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/reader/ArrayReaderImpl.java
index 7f2bf39ad..6aa454704 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/reader/ArrayReaderImpl.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/reader/ArrayReaderImpl.java
@@ -29,6 +29,8 @@ import org.apache.drill.exec.vector.accessor.ObjectType;
import org.apache.drill.exec.vector.accessor.ScalarReader;
import org.apache.drill.exec.vector.accessor.TupleReader;
+import com.google.common.base.Preconditions;
+
/**
* Reader for an array-valued column. This reader provides access to specific
* array members via an array index. This class implements all arrays. The
@@ -132,9 +134,7 @@ public class ArrayReaderImpl implements ArrayReader, ReaderEvents {
@Override
public int offset() {
- if (position < 0 || length <= position) {
- throw new IndexOutOfBoundsException("Index = " + position + ", length = " + length);
- }
+ Preconditions.checkElementIndex(position, length);
return startOffset + position;
}
@@ -154,9 +154,7 @@ public class ArrayReaderImpl implements ArrayReader, ReaderEvents {
*/
public void set(int index) {
- if (index < 0 || length < index) {
- throw new IndexOutOfBoundsException("Index = " + index + ", length = " + length);
- }
+ Preconditions.checkPositionIndex(index, length);
position = index;
}
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/writer/BaseScalarWriter.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/writer/BaseScalarWriter.java
index 10a2cf3b5..7e121495f 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/writer/BaseScalarWriter.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/accessor/writer/BaseScalarWriter.java
@@ -194,7 +194,7 @@ public abstract class BaseScalarWriter extends AbstractScalarWriter {
protected void overflowed() {
if (listener == null) {
- throw new IndexOutOfBoundsException("Overflow not supported");
+ throw new UnsupportedOperationException("Overflow not supported");
} else {
listener.overflowed(this);
}
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/EmptyValuePopulator.java b/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/EmptyValuePopulator.java
index 41098596d..2c51422ee 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/EmptyValuePopulator.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/complex/EmptyValuePopulator.java
@@ -37,9 +37,7 @@ public class EmptyValuePopulator {
* @throws java.lang.IndexOutOfBoundsException if lastIndex is negative or greater than offsets capacity.
*/
public void populate(int lastIndex) {
- if (lastIndex < 0) {
- throw new IndexOutOfBoundsException("index cannot be negative");
- }
+ Preconditions.checkElementIndex(lastIndex, Integer.MAX_VALUE);
final UInt4Vector.Accessor accessor = offsets.getAccessor();
final UInt4Vector.Mutator mutator = offsets.getMutator();
final int lastSet = Math.max(accessor.getValueCount() - 1, 0);