Search in sources :

Example 1 with SingleCellConstructorExpression

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;
}
Also used : SingleCellConstructorExpression(org.apache.phoenix.expression.SingleCellConstructorExpression) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)

Example 2 with SingleCellConstructorExpression

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());
}
Also used : SingleCellConstructorExpression(org.apache.phoenix.expression.SingleCellConstructorExpression) SingleCellConstructorExpression(org.apache.phoenix.expression.SingleCellConstructorExpression) Expression(org.apache.phoenix.expression.Expression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) DelegateExpression(org.apache.phoenix.expression.DelegateExpression) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) PUnsignedTinyint(org.apache.phoenix.schema.types.PUnsignedTinyint) PTinyint(org.apache.phoenix.schema.types.PTinyint) PSmallint(org.apache.phoenix.schema.types.PSmallint) Test(org.junit.Test)

Example 3 with SingleCellConstructorExpression

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;
}
Also used : BaseTuple(org.apache.phoenix.schema.tuple.BaseTuple) PDatum(org.apache.phoenix.schema.PDatum) SingleCellConstructorExpression(org.apache.phoenix.expression.SingleCellConstructorExpression) PDataType(org.apache.phoenix.schema.types.PDataType) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.apache.hadoop.hbase.util.Pair) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) SortOrder(org.apache.phoenix.schema.SortOrder) Put(org.apache.hadoop.hbase.client.Put) SingleCellColumnExpression(org.apache.phoenix.expression.SingleCellColumnExpression) Expression(org.apache.phoenix.expression.Expression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) KeyValueColumnExpression(org.apache.phoenix.expression.KeyValueColumnExpression) SingleCellConstructorExpression(org.apache.phoenix.expression.SingleCellConstructorExpression) SingleCellColumnExpression(org.apache.phoenix.expression.SingleCellColumnExpression) CoerceExpression(org.apache.phoenix.expression.CoerceExpression) ColumnReference(org.apache.phoenix.hbase.index.covered.update.ColumnReference) ValueGetterTuple(org.apache.phoenix.schema.tuple.ValueGetterTuple)

Example 4 with SingleCellConstructorExpression

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());
}
Also used : SingleCellConstructorExpression(org.apache.phoenix.expression.SingleCellConstructorExpression) SingleCellConstructorExpression(org.apache.phoenix.expression.SingleCellConstructorExpression) Expression(org.apache.phoenix.expression.Expression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) DelegateExpression(org.apache.phoenix.expression.DelegateExpression) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) PUnsignedTinyint(org.apache.phoenix.schema.types.PUnsignedTinyint) PTinyint(org.apache.phoenix.schema.types.PTinyint) PSmallint(org.apache.phoenix.schema.types.PSmallint) Test(org.junit.Test)

Aggregations

SingleCellConstructorExpression (org.apache.phoenix.expression.SingleCellConstructorExpression)4 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)4 Expression (org.apache.phoenix.expression.Expression)3 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)3 DelegateExpression (org.apache.phoenix.expression.DelegateExpression)2 PSmallint (org.apache.phoenix.schema.types.PSmallint)2 PTinyint (org.apache.phoenix.schema.types.PTinyint)2 PUnsignedTinyint (org.apache.phoenix.schema.types.PUnsignedTinyint)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Put (org.apache.hadoop.hbase.client.Put)1 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)1 Pair (org.apache.hadoop.hbase.util.Pair)1 CoerceExpression (org.apache.phoenix.expression.CoerceExpression)1 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)1 SingleCellColumnExpression (org.apache.phoenix.expression.SingleCellColumnExpression)1 ColumnReference (org.apache.phoenix.hbase.index.covered.update.ColumnReference)1 PDatum (org.apache.phoenix.schema.PDatum)1 SortOrder (org.apache.phoenix.schema.SortOrder)1