Search in sources :

Example 1 with HashJoinRegionScanner

use of org.apache.phoenix.coprocessor.HashJoinRegionScanner 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)

Aggregations

Region (org.apache.hadoop.hbase.regionserver.Region)1 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)1 BaseRegionScanner (org.apache.phoenix.coprocessor.BaseRegionScanner)1 HashJoinRegionScanner (org.apache.phoenix.coprocessor.HashJoinRegionScanner)1 TupleProjector (org.apache.phoenix.execute.TupleProjector)1 Expression (org.apache.phoenix.expression.Expression)1 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)1 OrderByExpression (org.apache.phoenix.expression.OrderByExpression)1 SingleCellColumnExpression (org.apache.phoenix.expression.SingleCellColumnExpression)1 ColumnReference (org.apache.phoenix.hbase.index.covered.update.ColumnReference)1 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)1 IndexMaintainer (org.apache.phoenix.index.IndexMaintainer)1 HashJoinInfo (org.apache.phoenix.join.HashJoinInfo)1 PInteger (org.apache.phoenix.schema.types.PInteger)1 Transaction (org.apache.tephra.Transaction)1