Search in sources :

Example 11 with RowResult

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;
}
Also used : RowResult(org.apache.kudu.client.RowResult) KuduScanner(org.apache.kudu.client.KuduScanner) ArrayList(java.util.ArrayList) RowResultIterator(org.apache.kudu.client.RowResultIterator)

Example 12 with RowResult

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;
}
Also used : RowResult(org.apache.kudu.client.RowResult) KuduScanner(org.apache.kudu.client.KuduScanner) RowResultIterator(org.apache.kudu.client.RowResultIterator)

Example 13 with RowResult

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);
    }
}
Also used : RowResult(org.apache.kudu.client.RowResult) KuduScanner(org.apache.kudu.client.KuduScanner) ArrayList(java.util.ArrayList) PrestoException(com.facebook.presto.spi.PrestoException) RowResultIterator(org.apache.kudu.client.RowResultIterator) KuduException(org.apache.kudu.client.KuduException)

Example 14 with RowResult

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;
}
Also used : RowResult(org.apache.kudu.client.RowResult) RowResultIterator(org.apache.kudu.client.RowResultIterator)

Aggregations

RowResult (org.apache.kudu.client.RowResult)14 KuduScanner (org.apache.kudu.client.KuduScanner)10 RowResultIterator (org.apache.kudu.client.RowResultIterator)8 ArrayList (java.util.ArrayList)7 ColumnSchema (org.apache.kudu.ColumnSchema)5 JobConf (org.apache.hadoop.mapred.JobConf)4 KuduException (org.apache.kudu.client.KuduException)4 KuduTable (org.apache.kudu.client.KuduTable)4 PartialRow (org.apache.kudu.client.PartialRow)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 GoraException (org.apache.gora.util.GoraException)3 KuduInputSplit (org.apache.hadoop.hive.kudu.KuduInputFormat.KuduInputSplit)3 KuduRecordReader (org.apache.hadoop.hive.kudu.KuduInputFormat.KuduRecordReader)3 InputSplit (org.apache.hadoop.mapred.InputSplit)3 KuduPredicate (org.apache.kudu.client.KuduPredicate)3 KuduSession (org.apache.kudu.client.KuduSession)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 BigDecimal (java.math.BigDecimal)2 Timestamp (java.sql.Timestamp)2