use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class InListExpression method write.
@Override
public void write(DataOutput output) throws IOException {
super.write(output);
// Unused, but left for b/w compat. TODO: remove in next major release
output.writeBoolean(false);
WritableUtils.writeVInt(output, fixedWidth);
WritableUtils.writeVInt(output, valuesByteLength);
for (ImmutableBytesPtr ptr : values) {
output.write(ptr.get(), ptr.getOffset(), ptr.getLength());
}
if (fixedWidth == -1) {
WritableUtils.writeVInt(output, values.size());
for (ImmutableBytesPtr ptr : values) {
WritableUtils.writeVInt(output, ptr.getLength());
}
}
}
use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class CachingHTableFactory method getTable.
@Override
@SuppressWarnings("unchecked")
public HTableInterface getTable(ImmutableBytesPtr tablename, ExecutorService pool) throws IOException {
ImmutableBytesPtr tableBytes = new ImmutableBytesPtr(tablename);
synchronized (openTables) {
CachedHTableWrapper table = (CachedHTableWrapper) openTables.get(tableBytes);
if (table == null) {
table = new CachedHTableWrapper(delegate.getTable(tablename, pool));
openTables.put(tableBytes, table);
}
table.incrementReferenceCount();
return table;
}
}
use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class IndexUpdateManager method addIndexUpdate.
/**
* Add an index update. Keeps the latest {@link Put} for a given timestamp
* @param tableName
* @param m
*/
public void addIndexUpdate(byte[] tableName, Mutation m) {
// we only keep the most recent update
ImmutableBytesPtr key = new ImmutableBytesPtr(tableName);
Collection<Mutation> updates = map.get(key);
if (updates == null) {
updates = new TreeSet<Mutation>(COMPARATOR);
map.put(key, updates);
}
if (indexMetaData.ignoreNewerMutations()) {
// if we're replaying mutations, we don't need to worry about out-of-order updates
updates.add(m);
} else {
fixUpCurrentUpdates(updates, m);
}
}
use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class ImmutableStorageSchemeTest method testWithMaxOffsetLargerThanShortMax.
@Test
public void testWithMaxOffsetLargerThanShortMax() throws Exception {
int numElements = Short.MAX_VALUE + 2;
List<Expression> children = Lists.newArrayListWithExpectedSize(numElements);
for (int i = 0; i < numElements; ++i) {
children.add(CONSTANT_EXPRESSION);
}
SingleCellConstructorExpression singleCellConstructorExpression = new SingleCellConstructorExpression(immutableStorageScheme, children);
ImmutableBytesPtr ptr = new ImmutableBytesPtr();
singleCellConstructorExpression.evaluate(null, ptr);
ImmutableBytesPtr ptrCopy = new ImmutableBytesPtr(ptr);
ColumnValueDecoder decoder = immutableStorageScheme.getDecoder();
assertTrue(decoder.decode(ptrCopy, 0));
assertArrayEquals(QueryConstants.EMPTY_COLUMN_VALUE_BYTES, ptrCopy.copyBytesIfNecessary());
ptrCopy = new ImmutableBytesPtr(ptr);
assertTrue(decoder.decode(ptrCopy, 14999));
assertArrayEquals(QueryConstants.EMPTY_COLUMN_VALUE_BYTES, ptrCopy.copyBytesIfNecessary());
ptrCopy = new ImmutableBytesPtr(ptr);
assertTrue(decoder.decode(ptrCopy, numElements - 1));
assertArrayEquals(QueryConstants.EMPTY_COLUMN_VALUE_BYTES, ptrCopy.copyBytesIfNecessary());
}
use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class ImmutableStorageSchemeTest method testLeadingNulls.
@Test
public void testLeadingNulls() throws Exception {
List<Expression> children = Lists.newArrayListWithExpectedSize(4);
LiteralExpression nullExpression = LiteralExpression.newConstant(null);
children.add(nullExpression);
children.add(nullExpression);
children.add(LiteralExpression.newConstant(BYTE_ARRAY1, PVarbinary.INSTANCE));
children.add(LiteralExpression.newConstant(BYTE_ARRAY2, PVarbinary.INSTANCE));
SingleCellConstructorExpression singleCellConstructorExpression = new SingleCellConstructorExpression(immutableStorageScheme, children);
ImmutableBytesPtr ptr = new ImmutableBytesPtr();
singleCellConstructorExpression.evaluate(null, ptr);
ImmutableBytesPtr ptrCopy = new ImmutableBytesPtr(ptr);
ColumnValueDecoder decoder = immutableStorageScheme.getDecoder();
assertTrue(decoder.decode(ptrCopy, 0));
assertArrayEquals(ByteUtil.EMPTY_BYTE_ARRAY, ptrCopy.copyBytesIfNecessary());
ptrCopy = new ImmutableBytesPtr(ptr);
assertTrue(decoder.decode(ptrCopy, 1));
assertArrayEquals(ByteUtil.EMPTY_BYTE_ARRAY, ptrCopy.copyBytesIfNecessary());
ptrCopy = new ImmutableBytesPtr(ptr);
assertTrue(decoder.decode(ptrCopy, 2));
assertArrayEquals(BYTE_ARRAY1, ptrCopy.copyBytesIfNecessary());
ptrCopy = new ImmutableBytesPtr(ptr);
assertTrue(decoder.decode(ptrCopy, 3));
assertArrayEquals(BYTE_ARRAY2, ptrCopy.copyBytesIfNecessary());
}
Aggregations