use of org.apache.kudu.client.RowResult in project apex-malhar by apache.
the class KuduInputOperatorCommons method countNumRowsInTable.
public long countNumRowsInTable() throws Exception {
List<String> allProjectedCols = new ArrayList<>(unitTestStepwiseScanInputOperator.getKuduColNameToSchemaMapping().keySet());
KuduScanner scanner = kuduClient.newScannerBuilder(kuduTable).setProjectedColumnNames(allProjectedCols).build();
long counter = 0;
while (scanner.hasMoreRows()) {
RowResultIterator rowResultItr = scanner.nextRows();
while (rowResultItr.hasNext()) {
RowResult thisRow = rowResultItr.next();
counter += 1;
}
}
return counter;
}
use of org.apache.kudu.client.RowResult in project apex-malhar by apache.
the class KuduPartitionScannerCallable method call.
@Override
public Long call() throws Exception {
long numRowsScanned = 0;
KuduScanner aPartitionSpecificScanner = KuduScanToken.deserializeIntoScanner(kuduPartitionScanAssignmentMeta.getSerializedKuduScanToken(), kuduClientHandle);
LOG.info("Scanning the following tablet " + KuduScanToken.stringifySerializedToken(kuduPartitionScanAssignmentMeta.getSerializedKuduScanToken(), kuduClientHandle));
KuduRecordWithMeta<T> beginScanRecord = new KuduRecordWithMeta<>();
beginScanRecord.setBeginScanMarker(true);
beginScanRecord.setTabletMetadata(kuduPartitionScanAssignmentMeta);
// Add a record entry that denotes the end of this scan.
bufferForTransmittingRecords.add(beginScanRecord);
while (aPartitionSpecificScanner.hasMoreRows()) {
LOG.debug("Number of columns being returned for this read " + aPartitionSpecificScanner.getProjectionSchema().getColumnCount());
RowResultIterator resultIterator = aPartitionSpecificScanner.nextRows();
if (resultIterator == null) {
break;
} else {
while (resultIterator.hasNext()) {
KuduRecordWithMeta<T> recordWithMeta = new KuduRecordWithMeta<>();
RowResult aRow = resultIterator.next();
recordWithMeta.setPositionInScan(numRowsScanned);
T payload = clazzForResultObject.newInstance();
recordWithMeta.setThePayload(payload);
recordWithMeta.setEndOfScanMarker(false);
recordWithMeta.setTabletMetadata(kuduPartitionScanAssignmentMeta);
setValuesInPOJO(aRow, payload);
bufferForTransmittingRecords.add(recordWithMeta);
numRowsScanned += 1;
}
}
}
aPartitionSpecificScanner.close();
KuduRecordWithMeta<T> endScanRecord = new KuduRecordWithMeta<>();
endScanRecord.setEndOfScanMarker(true);
endScanRecord.setTabletMetadata(kuduPartitionScanAssignmentMeta);
// Add a record entry that denotes the end of this scan.
bufferForTransmittingRecords.add(endScanRecord);
LOG.info(" Scanned a total of " + numRowsScanned + " for this scanner thread @tablet " + KuduScanToken.stringifySerializedToken(kuduPartitionScanAssignmentMeta.getSerializedKuduScanToken(), kuduClientHandle));
return numRowsScanned;
}
use of org.apache.kudu.client.RowResult in project presto by prestodb.
the class SchemaEmulationByTableNameConvention method listSchemaNames.
@Override
public List<String> listSchemaNames(KuduClient client) {
try {
if (rawSchemasTable == null) {
if (!client.tableExists(rawSchemasTableName)) {
createAndFillSchemasTable(client);
}
rawSchemasTable = getSchemasTable(client);
}
KuduScanner scanner = client.newScannerBuilder(rawSchemasTable).build();
RowResultIterator iterator = scanner.nextRows();
ArrayList<String> result = new ArrayList<>();
while (iterator != null) {
for (RowResult row : iterator) {
result.add(row.getString(0));
}
iterator = scanner.nextRows();
}
return result;
} catch (KuduException e) {
throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
}
}
use of org.apache.kudu.client.RowResult in project gora by apache.
the class KuduResult method nextInner.
/**
* {@inheritDoc}
*/
@Override
protected boolean nextInner() throws IOException {
boolean hasMoreRecords = false;
if (this.resultIt == null || !this.resultIt.hasNext()) {
while (this.result.hasMoreRows()) {
RowResultIterator nextRows = this.result.nextRows();
if (nextRows.hasNext()) {
resultIt = nextRows;
hasMoreRecords = true;
}
}
} else {
hasMoreRecords = true;
}
if (hasMoreRecords) {
RowResult next = resultIt.next();
key = ((KuduStore<K, T>) getDataStore()).extractKey(next);
persistent = ((KuduStore<K, T>) getDataStore()).newInstance(next, getQuery().getFields());
}
return hasMoreRecords;
}
Aggregations