Skip to content

Commit

Permalink
Bug fix for forcedotcom#275
Browse files Browse the repository at this point in the history
  • Loading branch information
jtaylor-sfdc committed Jun 20, 2013
1 parent 2f30e7b commit b93a8e7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ protected int positionVarLength(ImmutableBytesWritable ptr, int position, int nF
return length;
}

@Override
protected int getVarLengthBytes(int length) {
return length + WritableUtils.getVIntSize(length);
}

@Override
protected int writeVarLengthField(ImmutableBytesWritable ptr, byte[] b, int offset) {
int length = ptr.getLength();
int vintLen = WritableUtils.getVIntSize(length);
b = ensureSize(b, offset, offset + vintLen);
offset += ByteUtil.vintToBytes(b, offset, length);
b = ensureSize(b, offset, offset + length);
System.arraycopy(ptr.get(), ptr.getOffset(), b, offset, length);
offset += length;
return offset;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/salesforce/phoenix/schema/RowKeySchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ protected int positionVarLength(ImmutableBytesWritable ptr, int position, int nF
}
return len;
}

@Override
protected int getVarLengthBytes(int length) {
return length + 1; // Size in bytes plus one for the separator byte
}

@Override
protected int writeVarLengthField(ImmutableBytesWritable ptr, byte[] b, int offset) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/salesforce/phoenix/schema/ValueSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public Field getField(int position) {
return fields.get(fieldIndexByPosition[position]);
}

protected static byte[] ensureSize(byte[] b, int offset, int size) {
private static byte[] ensureSize(byte[] b, int offset, int size) {
if (size > b.length) {
byte[] bBigger = new byte[Math.max(b.length * 2, size)];
System.arraycopy(b, 0, bBigger, 0, b.length);
Expand Down Expand Up @@ -383,6 +383,7 @@ protected int positionFixedLength(ImmutableBytesWritable ptr, int position, int

abstract protected int positionVarLength(ImmutableBytesWritable ptr, int position, int nFields, int maxLength);
abstract protected int writeVarLengthField(ImmutableBytesWritable ptr, byte[] b, int offset);
abstract protected int getVarLengthBytes(int length);

/**
* @return byte representation of the ValueSchema
Expand All @@ -405,7 +406,7 @@ public byte[] toBytes(Aggregator[] aggregators, ValueBitSet valueSet, ImmutableB
valueSet.set(index - minNullableIndex);
}
if (!type.isFixedWidth()) {
b = ensureSize(b, offset, offset + ptr.getLength() + 1);
b = ensureSize(b, offset, offset + getVarLengthBytes(ptr.getLength()));
offset = writeVarLengthField(ptr, b, offset);
} else {
int nBytes = ptr.getLength();
Expand Down

0 comments on commit b93a8e7

Please sign in to comment.