use of org.apache.phoenix.expression.SingleCellConstructorExpression in project phoenix by apache.
the class ImmutableStorageSchemeTest method evaluate.
private ImmutableBytesPtr evaluate(List<Expression> children) {
SingleCellConstructorExpression singleCellConstructorExpression = new SingleCellConstructorExpression(immutableStorageScheme, children);
ImmutableBytesPtr ptr = new ImmutableBytesPtr();
singleCellConstructorExpression.evaluate(null, ptr);
return ptr;
}
use of org.apache.phoenix.expression.SingleCellConstructorExpression in project phoenix by apache.
the class ImmutableStorageSchemeTest method testWithMaxOffsetSmallerThanShortMin.
@Test
public void testWithMaxOffsetSmallerThanShortMin() throws Exception {
int numElements = Short.MAX_VALUE + 2;
List<Expression> children = Lists.newArrayListWithExpectedSize(numElements);
for (int i = 0; i <= numElements; i += 2) {
children.add(CONSTANT_EXPRESSION);
children.add(FALSE_EVAL_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);
assertFalse(decoder.decode(ptrCopy, 1));
assertArrayEquals(ByteUtil.EMPTY_BYTE_ARRAY, ptrCopy.copyBytesIfNecessary());
ptrCopy = new ImmutableBytesPtr(ptr);
assertTrue(decoder.decode(ptrCopy, numElements - 1));
assertArrayEquals(QueryConstants.EMPTY_COLUMN_VALUE_BYTES, ptrCopy.copyBytesIfNecessary());
ptrCopy = new ImmutableBytesPtr(ptr);
assertFalse(decoder.decode(ptrCopy, numElements));
assertArrayEquals(ByteUtil.EMPTY_BYTE_ARRAY, ptrCopy.copyBytesIfNecessary());
}
use of org.apache.phoenix.expression.SingleCellConstructorExpression in project phoenix by apache.
the class IndexMaintainer method buildUpdateMutation.
public Put buildUpdateMutation(KeyValueBuilder kvBuilder, ValueGetter valueGetter, ImmutableBytesWritable dataRowKeyPtr, long ts, byte[] regionStartKey, byte[] regionEndKey) throws IOException {
byte[] indexRowKey = this.buildRowKey(valueGetter, dataRowKeyPtr, regionStartKey, regionEndKey, ts);
Put put = null;
// New row being inserted: add the empty key value
ImmutableBytesWritable latestValue = null;
if (valueGetter == null || (latestValue = valueGetter.getLatestValue(dataEmptyKeyValueRef, ts)) == null || latestValue == ValueGetter.HIDDEN_BY_DELETE) {
// If it is, these Puts will be masked so should not be emitted.
if (latestValue == ValueGetter.HIDDEN_BY_DELETE) {
return null;
}
put = new Put(indexRowKey);
// add the keyvalue for the empty row
put.add(kvBuilder.buildPut(new ImmutableBytesPtr(indexRowKey), this.getEmptyKeyValueFamily(), dataEmptyKeyValueRef.getQualifierWritable(), ts, // set the value to the empty column name
dataEmptyKeyValueRef.getQualifierWritable()));
put.setDurability(!indexWALDisabled ? Durability.USE_DEFAULT : Durability.SKIP_WAL);
}
ImmutableBytesPtr rowKey = new ImmutableBytesPtr(indexRowKey);
if (immutableStorageScheme != ImmutableStorageScheme.ONE_CELL_PER_COLUMN) {
// map from index column family to list of pair of index column and data column (for covered columns)
Map<ImmutableBytesPtr, List<Pair<ColumnReference, ColumnReference>>> familyToColListMap = Maps.newHashMap();
for (ColumnReference ref : this.getCoveredColumns()) {
ColumnReference indexColRef = this.coveredColumnsMap.get(ref);
ImmutableBytesPtr cf = new ImmutableBytesPtr(indexColRef.getFamily());
if (!familyToColListMap.containsKey(cf)) {
familyToColListMap.put(cf, Lists.<Pair<ColumnReference, ColumnReference>>newArrayList());
}
familyToColListMap.get(cf).add(Pair.newPair(indexColRef, ref));
}
// iterate over each column family and create a byte[] containing all the columns
for (Entry<ImmutableBytesPtr, List<Pair<ColumnReference, ColumnReference>>> entry : familyToColListMap.entrySet()) {
byte[] columnFamily = entry.getKey().copyBytesIfNecessary();
List<Pair<ColumnReference, ColumnReference>> colRefPairs = entry.getValue();
int maxEncodedColumnQualifier = Integer.MIN_VALUE;
// find the max col qualifier
for (Pair<ColumnReference, ColumnReference> colRefPair : colRefPairs) {
maxEncodedColumnQualifier = Math.max(maxEncodedColumnQualifier, encodingScheme.decode(colRefPair.getFirst().getQualifier()));
}
Expression[] colValues = EncodedColumnsUtil.createColumnExpressionArray(maxEncodedColumnQualifier);
// set the values of the columns
for (Pair<ColumnReference, ColumnReference> colRefPair : colRefPairs) {
ColumnReference indexColRef = colRefPair.getFirst();
ColumnReference dataColRef = colRefPair.getSecond();
Expression expression = new SingleCellColumnExpression(new PDatum() {
@Override
public boolean isNullable() {
return false;
}
@Override
public SortOrder getSortOrder() {
return null;
}
@Override
public Integer getScale() {
return null;
}
@Override
public Integer getMaxLength() {
return null;
}
@Override
public PDataType getDataType() {
return null;
}
}, dataColRef.getFamily(), dataColRef.getQualifier(), encodingScheme, immutableStorageScheme);
ImmutableBytesPtr ptr = new ImmutableBytesPtr();
expression.evaluate(new ValueGetterTuple(valueGetter, ts), ptr);
byte[] value = ptr.copyBytesIfNecessary();
if (value != null) {
int indexArrayPos = encodingScheme.decode(indexColRef.getQualifier()) - QueryConstants.ENCODED_CQ_COUNTER_INITIAL_VALUE + 1;
colValues[indexArrayPos] = new LiteralExpression(value);
}
}
List<Expression> children = Arrays.asList(colValues);
// we use SingleCellConstructorExpression to serialize multiple columns into a single byte[]
SingleCellConstructorExpression singleCellConstructorExpression = new SingleCellConstructorExpression(immutableStorageScheme, children);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
singleCellConstructorExpression.evaluate(new BaseTuple() {
}, ptr);
if (put == null) {
put = new Put(indexRowKey);
put.setDurability(!indexWALDisabled ? Durability.USE_DEFAULT : Durability.SKIP_WAL);
}
ImmutableBytesPtr colFamilyPtr = new ImmutableBytesPtr(columnFamily);
// this is a little bit of extra work for installations that are running <0.94.14, but that should be rare and is a short-term set of wrappers - it shouldn't kill GC
put.add(kvBuilder.buildPut(rowKey, colFamilyPtr, QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES_PTR, ts, ptr));
}
} else {
for (ColumnReference ref : this.getCoveredColumns()) {
ColumnReference indexColRef = this.coveredColumnsMap.get(ref);
ImmutableBytesPtr cq = indexColRef.getQualifierWritable();
ImmutableBytesPtr cf = indexColRef.getFamilyWritable();
ImmutableBytesWritable value = valueGetter.getLatestValue(ref, ts);
if (value != null && value != ValueGetter.HIDDEN_BY_DELETE) {
if (put == null) {
put = new Put(indexRowKey);
put.setDurability(!indexWALDisabled ? Durability.USE_DEFAULT : Durability.SKIP_WAL);
}
put.add(kvBuilder.buildPut(rowKey, cf, cq, ts, value));
}
}
}
return put;
}
use of org.apache.phoenix.expression.SingleCellConstructorExpression 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());
}
Aggregations