Search in sources :

Example 11 with RowKeySchema

use of org.apache.phoenix.schema.RowKeySchema in project phoenix by apache.

the class MutationState method getNewRowKeyWithRowTimestamp.

private static ImmutableBytesPtr getNewRowKeyWithRowTimestamp(ImmutableBytesPtr ptr, long rowTimestamp, PTable table) {
    RowKeySchema schema = table.getRowKeySchema();
    int rowTimestampColPos = table.getRowTimestampColPos();
    Field rowTimestampField = schema.getField(rowTimestampColPos);
    byte[] rowTimestampBytes = PLong.INSTANCE.toBytes(rowTimestamp, rowTimestampField.getSortOrder());
    int oldOffset = ptr.getOffset();
    int oldLength = ptr.getLength();
    // Move the pointer to the start byte of the row timestamp pk
    schema.position(ptr, 0, rowTimestampColPos);
    byte[] b = ptr.get();
    int newOffset = ptr.getOffset();
    int length = ptr.getLength();
    for (int i = newOffset; i < newOffset + length; i++) {
        // modify the underlying bytes array with the bytes of the row timestamp
        b[i] = rowTimestampBytes[i - newOffset];
    }
    // move the pointer back to where it was before.
    ptr.set(ptr.get(), oldOffset, oldLength);
    return ptr;
}
Also used : Field(org.apache.phoenix.schema.ValueSchema.Field) RowKeySchema(org.apache.phoenix.schema.RowKeySchema)

Example 12 with RowKeySchema

use of org.apache.phoenix.schema.RowKeySchema in project phoenix by apache.

the class ExplainTable method appendScanRow.

private void appendScanRow(StringBuilder buf, Bound bound) {
    ScanRanges scanRanges = context.getScanRanges();
    // TODO: review this and potentially intersect the scan ranges
    // with the minMaxRange in ScanRanges to prevent having to do all this.
    KeyRange minMaxRange = scanRanges.getMinMaxRange();
    Iterator<byte[]> minMaxIterator = Iterators.emptyIterator();
    if (minMaxRange != KeyRange.EVERYTHING_RANGE) {
        RowKeySchema schema = tableRef.getTable().getRowKeySchema();
        if (!minMaxRange.isUnbound(bound)) {
            minMaxIterator = new RowKeyValueIterator(schema, minMaxRange.getRange(bound));
        }
    }
    boolean isLocalIndex = ScanUtil.isLocalIndex(context.getScan());
    boolean forceSkipScan = this.hint.hasHint(Hint.SKIP_SCAN);
    int nRanges = forceSkipScan ? scanRanges.getRanges().size() : scanRanges.getBoundSlotCount();
    for (int i = 0, minPos = 0; minPos < nRanges || minMaxIterator.hasNext(); i++) {
        List<KeyRange> ranges = minPos >= nRanges ? EVERYTHING : scanRanges.getRanges().get(minPos++);
        KeyRange range = bound == Bound.LOWER ? ranges.get(0) : ranges.get(ranges.size() - 1);
        byte[] b = range.getRange(bound);
        Boolean isNull = KeyRange.IS_NULL_RANGE == range ? Boolean.TRUE : KeyRange.IS_NOT_NULL_RANGE == range ? Boolean.FALSE : null;
        if (minMaxIterator.hasNext()) {
            byte[] bMinMax = minMaxIterator.next();
            int cmp = Bytes.compareTo(bMinMax, b) * (bound == Bound.LOWER ? 1 : -1);
            if (cmp > 0) {
                minPos = nRanges;
                b = bMinMax;
                isNull = null;
            } else if (cmp < 0) {
                minMaxIterator = Iterators.emptyIterator();
            }
        }
        if (isLocalIndex && i == 0) {
            appendPKColumnValue(buf, b, isNull, i, true);
        } else {
            appendPKColumnValue(buf, b, isNull, i, false);
        }
        buf.append(',');
    }
}
Also used : KeyRange(org.apache.phoenix.query.KeyRange) RowKeySchema(org.apache.phoenix.schema.RowKeySchema) ScanRanges(org.apache.phoenix.compile.ScanRanges) Hint(org.apache.phoenix.parse.HintNode.Hint)

Aggregations

RowKeySchema (org.apache.phoenix.schema.RowKeySchema)12 List (java.util.List)5 Field (org.apache.phoenix.schema.ValueSchema.Field)5 IOException (java.io.IOException)3 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)3 Expression (org.apache.phoenix.expression.Expression)3 DataOutput (java.io.DataOutput)2 DataOutputStream (java.io.DataOutputStream)2 ArrayList (java.util.ArrayList)2 Cell (org.apache.hadoop.hbase.Cell)2 Delete (org.apache.hadoop.hbase.client.Delete)2 ScanRanges (org.apache.phoenix.compile.ScanRanges)2 CoerceExpression (org.apache.phoenix.expression.CoerceExpression)2 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)2 KeyRange (org.apache.phoenix.query.KeyRange)2 PColumn (org.apache.phoenix.schema.PColumn)2 PRow (org.apache.phoenix.schema.PRow)2 TrustedByteArrayOutputStream (org.apache.phoenix.util.TrustedByteArrayOutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInput (java.io.DataInput)1