Search in sources :

Example 1 with RestrictedMapRDBSubScanSpec

use of org.apache.drill.exec.store.mapr.db.RestrictedMapRDBSubScanSpec in project drill by apache.

the class RestrictedJsonTableGroupScan method getSubScanSpec.

// TODO:  this method needs to be fully implemented
protected RestrictedMapRDBSubScanSpec getSubScanSpec(TabletFragmentInfo tfi) {
    JsonScanSpec spec = scanSpec;
    RestrictedMapRDBSubScanSpec subScanSpec = new RestrictedMapRDBSubScanSpec(spec.getTableName(), getRegionsToScan().get(tfi), spec.getSerializedFilter(), getUserName());
    return subScanSpec;
}
Also used : RestrictedMapRDBSubScanSpec(org.apache.drill.exec.store.mapr.db.RestrictedMapRDBSubScanSpec)

Example 2 with RestrictedMapRDBSubScanSpec

use of org.apache.drill.exec.store.mapr.db.RestrictedMapRDBSubScanSpec in project drill by apache.

the class RestrictedJsonTableGroupScan method getEndPointFragmentMapping.

private List<RestrictedMapRDBSubScanSpec> getEndPointFragmentMapping(int minorFragmentId) {
    List<RestrictedMapRDBSubScanSpec> restrictedSubScanSpecList = Lists.newArrayList();
    List<MapRDBSubScanSpec> subScanSpecList = endpointFragmentMapping.get(minorFragmentId);
    for (MapRDBSubScanSpec s : subScanSpecList) {
        restrictedSubScanSpecList.add((RestrictedMapRDBSubScanSpec) s);
    }
    return restrictedSubScanSpecList;
}
Also used : RestrictedMapRDBSubScanSpec(org.apache.drill.exec.store.mapr.db.RestrictedMapRDBSubScanSpec) MapRDBSubScanSpec(org.apache.drill.exec.store.mapr.db.MapRDBSubScanSpec) RestrictedMapRDBSubScanSpec(org.apache.drill.exec.store.mapr.db.RestrictedMapRDBSubScanSpec)

Example 3 with RestrictedMapRDBSubScanSpec

use of org.apache.drill.exec.store.mapr.db.RestrictedMapRDBSubScanSpec in project drill by apache.

the class RestrictedJsonRecordReader method next.

@Override
public int next() {
    Stopwatch watch = Stopwatch.createUnstarted();
    watch.start();
    RestrictedMapRDBSubScanSpec rss = ((RestrictedMapRDBSubScanSpec) this.subScanSpec);
    vectorWriter.allocate();
    vectorWriter.reset();
    if (!rss.readyToGetRowKey()) {
        // when we are in the build schema phase
        if (rss.isBuildSchemaPhase()) {
            readToInitSchema();
        }
        return 0;
    }
    Table table = super.formatPlugin.getJsonTableCache().getTable(subScanSpec.getTableName(), subScanSpec.getUserName());
    final MultiGet multiGet = new MultiGet((BaseJsonTable) table, condition, false, projections);
    int recordCount = 0;
    DBDocumentReaderBase reader = null;
    int maxRecordsForThisBatch = this.maxRecordsToRead > 0 ? Math.min(rss.getMaxRowKeysToBeRead(), this.maxRecordsToRead) : this.maxRecordsToRead == -1 ? rss.getMaxRowKeysToBeRead() : 0;
    Stopwatch timer = Stopwatch.createUnstarted();
    while (recordCount < maxRecordsForThisBatch) {
        ByteBuffer[] rowKeyIds = rss.getRowKeyIdsToRead(batchSize);
        if (rowKeyIds == null) {
            break;
        }
        try {
            timer.start();
            final List<Document> docList = multiGet.doGet(rowKeyIds);
            int index = 0;
            long docsToRead = docList.size();
            // If limit pushdown then stop once we have `limit` rows from multiget i.e. maxRecordsForThisBatch
            if (this.maxRecordsToRead != -1) {
                docsToRead = Math.min(docsToRead, maxRecordsForThisBatch);
            }
            while (index < docsToRead) {
                vectorWriter.setPosition(recordCount);
                reader = (DBDocumentReaderBase) docList.get(index).asReader();
                documentWriter.writeDBDocument(vectorWriter, reader);
                recordCount++;
                index++;
            }
            timer.stop();
        } catch (UserException e) {
            throw UserException.unsupportedError(e).addContext(String.format("Table: %s, document id: '%s'", getTable().getPath(), reader == null ? null : IdCodec.asString(reader.getId()))).build(logger);
        } catch (SchemaChangeException e) {
            if (getIgnoreSchemaChange()) {
                logger.warn("{}. Dropping the row from result.", e.getMessage());
                logger.debug("Stack trace:", e);
            } else {
                throw dataReadError(logger, e);
            }
        }
    }
    vectorWriter.setValueCount(recordCount);
    if (maxRecordsToRead > 0) {
        if (maxRecordsToRead - recordCount >= 0) {
            maxRecordsToRead -= recordCount;
        } else {
            maxRecordsToRead = 0;
        }
    }
    logger.debug("Took {} ms to get {} records, getrowkey {}", watch.elapsed(TimeUnit.MILLISECONDS), recordCount, timer.elapsed(TimeUnit.MILLISECONDS));
    return recordCount;
}
Also used : BaseJsonTable(com.mapr.db.impl.BaseJsonTable) Table(com.mapr.db.Table) RestrictedMapRDBSubScanSpec(org.apache.drill.exec.store.mapr.db.RestrictedMapRDBSubScanSpec) Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch) Document(org.ojai.Document) ByteBuffer(java.nio.ByteBuffer) MultiGet(com.mapr.db.impl.MultiGet) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) DBDocumentReaderBase(com.mapr.db.ojai.DBDocumentReaderBase) UserException(org.apache.drill.common.exceptions.UserException)

Example 4 with RestrictedMapRDBSubScanSpec

use of org.apache.drill.exec.store.mapr.db.RestrictedMapRDBSubScanSpec in project drill by apache.

the class RestrictedJsonRecordReader method setup.

@Override
public void setup(OperatorContext context, OutputMutator output) throws ExecutionSetupException {
    RestrictedMapRDBSubScanSpec rss = ((RestrictedMapRDBSubScanSpec) this.subScanSpec);
    RowKeyJoin rjBatch = rss.getJoinForSubScan();
    if (rjBatch == null) {
        throw new ExecutionSetupException("RowKeyJoin Batch is not setup for Restricted MapRDB Subscan");
    }
    AbstractRecordBatch.BatchState state = rjBatch.getBatchState();
    if (state == AbstractRecordBatch.BatchState.BUILD_SCHEMA || state == AbstractRecordBatch.BatchState.FIRST) {
        super.setup(context, output);
    }
    return;
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) RestrictedMapRDBSubScanSpec(org.apache.drill.exec.store.mapr.db.RestrictedMapRDBSubScanSpec) RowKeyJoin(org.apache.drill.exec.physical.impl.join.RowKeyJoin) AbstractRecordBatch(org.apache.drill.exec.record.AbstractRecordBatch)

Example 5 with RestrictedMapRDBSubScanSpec

use of org.apache.drill.exec.store.mapr.db.RestrictedMapRDBSubScanSpec in project drill by apache.

the class RestrictedJsonRecordReader method hasNext.

@Override
public boolean hasNext() {
    RestrictedMapRDBSubScanSpec rss = ((RestrictedMapRDBSubScanSpec) this.subScanSpec);
    RowKeyJoin rjBatch = rss.getJoinForSubScan();
    if (rjBatch == null) {
        return false;
    }
    boolean hasMore = false;
    AbstractRecordBatch.BatchState state = rss.getJoinForSubScan().getBatchState();
    RowKeyJoin.RowKeyJoinState rkState = rss.getJoinForSubScan().getRowKeyJoinState();
    if (state == AbstractRecordBatch.BatchState.BUILD_SCHEMA) {
        hasMore = true;
    } else if (state == AbstractRecordBatch.BatchState.FIRST) {
        if (this.maxRecordsToRead > 0) {
            rss.getJoinForSubScan().setBatchState(AbstractRecordBatch.BatchState.NOT_FIRST);
            rss.getJoinForSubScan().setRowKeyJoinState(RowKeyJoin.RowKeyJoinState.PROCESSING);
            hasMore = true;
        }
    } else if (rkState == RowKeyJoin.RowKeyJoinState.INITIAL) {
        if (this.maxRecordsToRead > 0) {
            rss.getJoinForSubScan().setRowKeyJoinState(RowKeyJoin.RowKeyJoinState.PROCESSING);
            hasMore = true;
        }
    }
    logger.debug("restricted reader hasMore = {}", hasMore);
    return hasMore;
}
Also used : RestrictedMapRDBSubScanSpec(org.apache.drill.exec.store.mapr.db.RestrictedMapRDBSubScanSpec) RowKeyJoin(org.apache.drill.exec.physical.impl.join.RowKeyJoin) AbstractRecordBatch(org.apache.drill.exec.record.AbstractRecordBatch)

Aggregations

RestrictedMapRDBSubScanSpec (org.apache.drill.exec.store.mapr.db.RestrictedMapRDBSubScanSpec)5 RowKeyJoin (org.apache.drill.exec.physical.impl.join.RowKeyJoin)2 AbstractRecordBatch (org.apache.drill.exec.record.AbstractRecordBatch)2 Table (com.mapr.db.Table)1 BaseJsonTable (com.mapr.db.impl.BaseJsonTable)1 MultiGet (com.mapr.db.impl.MultiGet)1 DBDocumentReaderBase (com.mapr.db.ojai.DBDocumentReaderBase)1 ByteBuffer (java.nio.ByteBuffer)1 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)1 UserException (org.apache.drill.common.exceptions.UserException)1 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)1 MapRDBSubScanSpec (org.apache.drill.exec.store.mapr.db.MapRDBSubScanSpec)1 Stopwatch (org.apache.drill.shaded.guava.com.google.common.base.Stopwatch)1 Document (org.ojai.Document)1