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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations