Skip to content

Commit

Permalink
DRILL-1205: group by causes access to DeadBuf
Browse files Browse the repository at this point in the history
* Fix an issue that causes calls to splitAndTransferTo malfunction on repeated vector types
  • Loading branch information
Hanifi Gunes authored and adityakishore committed Aug 18, 2014
1 parent db76274 commit 88c1b92
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public final class Repeated${minor.class}Vector extends BaseValueVector implemen

private int parentValueCount;
private int childValueCount;
protected int sliceOffset = 0;


private final UInt4Vector offsets; // offsets to start of each record
private final ${minor.class}Vector values;
private final Mutator mutator = new Mutator();
Expand Down Expand Up @@ -103,13 +102,16 @@ public void transferTo(Repeated${minor.class}Vector target){
}

public void splitAndTransferTo(int startIndex, int length, Repeated${minor.class}Vector target) {
int startValue = offsets.getAccessor().get(startIndex);
int endValue = offsets.getAccessor().get(startIndex + length);
values.splitAndTransferTo(startValue, endValue - startValue, target.values);
offsets.splitAndTransferTo(startIndex, length, target.offsets);
target.parentValueCount = parentValueCount;
target.childValueCount = childValueCount;
sliceOffset = startIndex;
int startPos = offsets.getAccessor().get(startIndex);
int endPos = offsets.getAccessor().get(startIndex+length);
values.splitAndTransferTo(startIndex, endPos-startPos, target.values);
target.offsets.clear();
target.offsets.allocateNew(length+1);
int normalizedPos = 0;
for (int i=0; i<length+1;i++) {
normalizedPos = offsets.getAccessor().get(startIndex+i) - startPos;
target.offsets.getMutator().set(i, normalizedPos);
}
}

private class TransferImpl implements TransferPair{
Expand Down Expand Up @@ -166,7 +168,6 @@ public boolean allocateNewSafe(){
if(!values.allocateNewSafe()) return false;
mutator.reset();
accessor.reset();
sliceOffset = 0;
return true;
}

Expand All @@ -176,7 +177,6 @@ public void allocateNew() {
values.allocateNew();
mutator.reset();
accessor.reset();
sliceOffset = 0;
}

<#if type.major == "VarLen">
Expand All @@ -196,7 +196,6 @@ public void allocateNew(int totalBytes, int parentValueCount, int childValueCoun
values.allocateNew(totalBytes, childValueCount);
mutator.reset();
accessor.reset();
sliceOffset = 0;
}

@Override
Expand Down Expand Up @@ -302,8 +301,8 @@ public int getCount(int index) {

public List<${friendlyType}> getObject(int index) {
List<${friendlyType}> vals = new JsonStringArrayList();
int start = offsets.getAccessor().get(index) - sliceOffset;
int end = offsets.getAccessor().get(index+1) - sliceOffset;
int start = offsets.getAccessor().get(index);
int end = offsets.getAccessor().get(index+1);
for(int i = start; i < end; i++){
vals.add(values.getAccessor().getObject(i));
}
Expand All @@ -326,7 +325,7 @@ public int getCount(int index) {
public <#if type.major == "VarLen">byte[]
<#else>${minor.javaType!type.javaType}
</#if> get(int index, int positionIndex) {
return values.getAccessor().get(offsets.getAccessor().get(index) - sliceOffset + positionIndex);
return values.getAccessor().get(offsets.getAccessor().get(index) + positionIndex);
}


Expand All @@ -335,8 +334,8 @@ public boolean isNull(int index){
}

public void get(int index, Repeated${minor.class}Holder holder){
holder.start = offsets.getAccessor().get(index) - sliceOffset;
holder.end = offsets.getAccessor().get(index+1) - sliceOffset;
holder.start = offsets.getAccessor().get(index);
holder.end = offsets.getAccessor().get(index+1);
holder.vector = values;
}

Expand Down

0 comments on commit 88c1b92

Please sign in to comment.