Search in sources :

Example 36 with ColumnReference

use of org.apache.phoenix.hbase.index.covered.update.ColumnReference in project phoenix by apache.

the class NonAggregateRegionScannerFactory method getRegionScanner.

@Override
public RegionScanner getRegionScanner(final Scan scan, final RegionScanner s) throws Throwable {
    int offset = 0;
    if (ScanUtil.isLocalIndex(scan)) {
        /*
             * For local indexes, we need to set an offset on row key expressions to skip
             * the region start key.
             */
        Region region = getRegion();
        offset = region.getRegionInfo().getStartKey().length != 0 ? region.getRegionInfo().getStartKey().length : region.getRegionInfo().getEndKey().length;
        ScanUtil.setRowKeyOffset(scan, offset);
    }
    byte[] scanOffsetBytes = scan.getAttribute(BaseScannerRegionObserver.SCAN_OFFSET);
    Integer scanOffset = null;
    if (scanOffsetBytes != null) {
        scanOffset = (Integer) PInteger.INSTANCE.toObject(scanOffsetBytes);
    }
    RegionScanner innerScanner = s;
    Set<KeyValueColumnExpression> arrayKVRefs = Sets.newHashSet();
    Expression[] arrayFuncRefs = deserializeArrayPostionalExpressionInfoFromScan(scan, innerScanner, arrayKVRefs);
    TupleProjector tupleProjector = null;
    Region dataRegion = null;
    IndexMaintainer indexMaintainer = null;
    byte[][] viewConstants = null;
    Transaction tx = null;
    ColumnReference[] dataColumns = IndexUtil.deserializeDataTableColumnsToJoin(scan);
    if (dataColumns != null) {
        tupleProjector = IndexUtil.getTupleProjector(scan, dataColumns);
        dataRegion = env.getRegion();
        boolean useProto = false;
        byte[] localIndexBytes = scan.getAttribute(BaseScannerRegionObserver.LOCAL_INDEX_BUILD_PROTO);
        useProto = localIndexBytes != null;
        if (localIndexBytes == null) {
            localIndexBytes = scan.getAttribute(BaseScannerRegionObserver.LOCAL_INDEX_BUILD);
        }
        List<IndexMaintainer> indexMaintainers = localIndexBytes == null ? null : IndexMaintainer.deserialize(localIndexBytes, useProto);
        indexMaintainer = indexMaintainers.get(0);
        viewConstants = IndexUtil.deserializeViewConstantsFromScan(scan);
        byte[] txState = scan.getAttribute(BaseScannerRegionObserver.TX_STATE);
        tx = MutationState.decodeTransaction(txState);
    }
    final TupleProjector p = TupleProjector.deserializeProjectorFromScan(scan);
    final HashJoinInfo j = HashJoinInfo.deserializeHashJoinFromScan(scan);
    boolean useQualifierAsIndex = EncodedColumnsUtil.useQualifierAsIndex(getMinMaxQualifiersFromScan(scan)) && scan.getAttribute(BaseScannerRegionObserver.TOPN) != null;
    // setting dataRegion in case of a non-coprocessor environment
    if (dataRegion == null && env.getConfiguration().get(PhoenixConfigurationUtil.SNAPSHOT_NAME_KEY) != null) {
        dataRegion = env.getRegion();
    }
    innerScanner = getWrappedScanner(env, innerScanner, arrayKVRefs, arrayFuncRefs, offset, scan, dataColumns, tupleProjector, dataRegion, indexMaintainer, tx, viewConstants, kvSchema, kvSchemaBitSet, j == null ? p : null, ptr, useQualifierAsIndex);
    final ImmutableBytesPtr tenantId = ScanUtil.getTenantId(scan);
    if (j != null) {
        innerScanner = new HashJoinRegionScanner(innerScanner, p, j, tenantId, env, useQualifierAsIndex, useNewValueColumnQualifier);
    }
    if (scanOffset != null) {
        innerScanner = getOffsetScanner(innerScanner, new OffsetResultIterator(new RegionScannerResultIterator(innerScanner, getMinMaxQualifiersFromScan(scan), encodingScheme), scanOffset), scan.getAttribute(QueryConstants.LAST_SCAN) != null);
    }
    final OrderedResultIterator iterator = deserializeFromScan(scan, innerScanner);
    if (iterator == null) {
        return innerScanner;
    }
    // TODO:the above wrapped scanner should be used here also
    return getTopNScanner(env, innerScanner, iterator, tenantId);
}
Also used : TupleProjector(org.apache.phoenix.execute.TupleProjector) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) PInteger(org.apache.phoenix.schema.types.PInteger) BaseRegionScanner(org.apache.phoenix.coprocessor.BaseRegionScanner) RegionScanner(org.apache.hadoop.hbase.regionserver.RegionScanner) HashJoinRegionScanner(org.apache.phoenix.coprocessor.HashJoinRegionScanner) IndexMaintainer(org.apache.phoenix.index.IndexMaintainer) Transaction(org.apache.tephra.Transaction) KeyValueColumnExpression(org.apache.phoenix.expression.KeyValueColumnExpression) Expression(org.apache.phoenix.expression.Expression) SingleCellColumnExpression(org.apache.phoenix.expression.SingleCellColumnExpression) OrderByExpression(org.apache.phoenix.expression.OrderByExpression) HashJoinInfo(org.apache.phoenix.join.HashJoinInfo) Region(org.apache.hadoop.hbase.regionserver.Region) HashJoinRegionScanner(org.apache.phoenix.coprocessor.HashJoinRegionScanner) KeyValueColumnExpression(org.apache.phoenix.expression.KeyValueColumnExpression) ColumnReference(org.apache.phoenix.hbase.index.covered.update.ColumnReference)

Example 37 with ColumnReference

use of org.apache.phoenix.hbase.index.covered.update.ColumnReference in project phoenix by apache.

the class ValueGetterTuple method getValue.

@Override
public KeyValue getValue(byte[] family, byte[] qualifier) {
    ImmutableBytesWritable value = null;
    try {
        value = valueGetter.getLatestValue(new ColumnReference(family, qualifier));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    byte[] rowKey = valueGetter.getRowKey();
    int valueOffset = 0;
    int valueLength = 0;
    byte[] valueBytes = HConstants.EMPTY_BYTE_ARRAY;
    if (value != null) {
        valueBytes = value.get();
        valueOffset = value.getOffset();
        valueLength = value.getLength();
    }
    return new KeyValue(rowKey, 0, rowKey.length, family, 0, family.length, qualifier, 0, qualifier.length, HConstants.LATEST_TIMESTAMP, Type.Put, valueBytes, valueOffset, valueLength);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) KeyValue(org.apache.hadoop.hbase.KeyValue) IOException(java.io.IOException) ColumnReference(org.apache.phoenix.hbase.index.covered.update.ColumnReference)

Aggregations

ColumnReference (org.apache.phoenix.hbase.index.covered.update.ColumnReference)37 Put (org.apache.hadoop.hbase.client.Put)12 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)11 Test (org.junit.Test)11 Expression (org.apache.phoenix.expression.Expression)10 ArrayList (java.util.ArrayList)9 Cell (org.apache.hadoop.hbase.Cell)9 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)9 Scan (org.apache.hadoop.hbase.client.Scan)8 Region (org.apache.hadoop.hbase.regionserver.Region)8 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)8 SingleCellColumnExpression (org.apache.phoenix.expression.SingleCellColumnExpression)8 List (java.util.List)7 Mutation (org.apache.hadoop.hbase.client.Mutation)7 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)7 CoerceExpression (org.apache.phoenix.expression.CoerceExpression)7 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)7 SingleCellConstructorExpression (org.apache.phoenix.expression.SingleCellConstructorExpression)7 IndexMaintainer (org.apache.phoenix.index.IndexMaintainer)7 PDataType (org.apache.phoenix.schema.types.PDataType)7