Search in sources :

Example 11 with KuduScanner

use of org.apache.kudu.client.KuduScanner in project apex-malhar by apache.

the class KuduClientTestCommons method lookUpAndPopulateRecord.

protected void lookUpAndPopulateRecord(UnitTestTablePojo keyInfo) throws Exception {
    KuduScanner scanner = kuduClient.newScannerBuilder(kuduTable).addPredicate(KuduPredicate.newComparisonPredicate(columnDefs.get("introwkey"), KuduPredicate.ComparisonOp.EQUAL, keyInfo.getIntrowkey())).addPredicate(KuduPredicate.newComparisonPredicate(columnDefs.get("stringrowkey"), KuduPredicate.ComparisonOp.EQUAL, keyInfo.getStringrowkey())).addPredicate(KuduPredicate.newComparisonPredicate(columnDefs.get("timestamprowkey"), KuduPredicate.ComparisonOp.EQUAL, keyInfo.getTimestamprowkey())).build();
    RowResultIterator rowResultItr = scanner.nextRows();
    while (rowResultItr.hasNext()) {
        RowResult thisRow = rowResultItr.next();
        keyInfo.setFloatdata(thisRow.getFloat("floatdata"));
        keyInfo.setBooldata(thisRow.getBoolean("booldata"));
        keyInfo.setBinarydata(thisRow.getBinary("binarydata"));
        keyInfo.setLongdata(thisRow.getLong("longdata"));
        keyInfo.setTimestampdata(thisRow.getLong("timestampdata"));
        keyInfo.setStringdata("stringdata");
        break;
    }
}
Also used : RowResult(org.apache.kudu.client.RowResult) KuduScanner(org.apache.kudu.client.KuduScanner) RowResultIterator(org.apache.kudu.client.RowResultIterator)

Example 12 with KuduScanner

use of org.apache.kudu.client.KuduScanner 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 13 with KuduScanner

use of org.apache.kudu.client.KuduScanner 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 14 with KuduScanner

use of org.apache.kudu.client.KuduScanner 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 15 with KuduScanner

use of org.apache.kudu.client.KuduScanner in project canal by alibaba.

the class KuduTemplate method countRow.

/**
 * 统计kudu表数据
 *
 * @param tableName
 * @return
 */
public long countRow(String tableName) {
    this.checkClient();
    long rowCount = 0L;
    try {
        KuduTable kuduTable = kuduClient.openTable(tableName);
        // 创建scanner扫描
        KuduScanner scanner = kuduClient.newScannerBuilder(kuduTable).build();
        // 遍历数据
        while (scanner.hasMoreRows()) {
            while (scanner.nextRows().hasNext()) {
                rowCount++;
            }
        }
    } catch (KuduException e) {
        e.printStackTrace();
    }
    return rowCount;
}
Also used : KuduScanner(org.apache.kudu.client.KuduScanner) KuduTable(org.apache.kudu.client.KuduTable) KuduException(org.apache.kudu.client.KuduException)

Aggregations

KuduScanner (org.apache.kudu.client.KuduScanner)16 RowResult (org.apache.kudu.client.RowResult)10 ArrayList (java.util.ArrayList)9 RowResultIterator (org.apache.kudu.client.RowResultIterator)8 KuduTable (org.apache.kudu.client.KuduTable)7 ColumnSchema (org.apache.kudu.ColumnSchema)6 KuduException (org.apache.kudu.client.KuduException)6 KuduPredicate (org.apache.kudu.client.KuduPredicate)6 IOException (java.io.IOException)4 GoraException (org.apache.gora.util.GoraException)4 KuduClient (org.apache.kudu.client.KuduClient)4 PartialRow (org.apache.kudu.client.PartialRow)4 KuduSession (org.apache.kudu.client.KuduSession)3 Schema (org.apache.kudu.Schema)2 CreateTableOptions (org.apache.kudu.client.CreateTableOptions)2 Insert (org.apache.kudu.client.Insert)2 ListTablesResponse (org.apache.kudu.client.ListTablesResponse)2 PrestoException (com.facebook.presto.spi.PrestoException)1 BigDecimal (java.math.BigDecimal)1 Timestamp (java.sql.Timestamp)1