Java Code Examples for org.apache.kudu.client.RowResultIterator#next()

The following examples show how to use org.apache.kudu.client.RowResultIterator#next() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KuduConsumerTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Ignore
public void insertRow() throws KuduException, InterruptedException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);

    assertMockEndpointsSatisfied();

    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertEquals(1, exchanges.size());

    KuduScanner scanner = exchanges.get(0).getIn().getBody(KuduScanner.class);

    RowResultIterator results = scanner.nextRows();
    RowResult result = results.next();

    ColumnSchema columnByIndex = result.getSchema().getColumnByIndex(0);
    String name = columnByIndex.getName();

    assertEquals("id", name);
    assertEquals(46, result.getInt(0));
    assertEquals(10, result.getInt(1));
}
 
Example 2
Source File: KuduInputOperatorCommons.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: KuduClientTestCommons.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
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;
  }
}
 
Example 4
Source File: KuduInputOperatorCommons.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
public void truncateTable() throws Exception
{
  AbstractKuduPartitionScanner<UnitTestTablePojo,InputOperatorControlTuple> scannerForDeletingRows =
      unitTestStepwiseScanInputOperator.getScanner();
  List<KuduScanToken> scansForAllTablets = unitTestStepwiseScanInputOperator
      .getPartitioner().getKuduScanTokensForSelectAllColumns();
  ApexKuduConnection aCurrentConnection = scannerForDeletingRows.getConnectionPoolForThreads().get(0);
  KuduSession aSessionForDeletes = aCurrentConnection.getKuduClient().newSession();
  KuduTable currentTable = aCurrentConnection.getKuduTable();
  for ( KuduScanToken aTabletScanToken : scansForAllTablets) {
    KuduScanner aScanner = aTabletScanToken.intoScanner(aCurrentConnection.getKuduClient());
    while ( aScanner.hasMoreRows()) {
      RowResultIterator itrForRows = aScanner.nextRows();
      while ( itrForRows.hasNext()) {
        RowResult aRow = itrForRows.next();
        int intRowKey = aRow.getInt("introwkey");
        String stringRowKey = aRow.getString("stringrowkey");
        long timestampRowKey = aRow.getLong("timestamprowkey");
        Delete aDeleteOp = currentTable.newDelete();
        aDeleteOp.getRow().addInt("introwkey",intRowKey);
        aDeleteOp.getRow().addString("stringrowkey", stringRowKey);
        aDeleteOp.getRow().addLong("timestamprowkey",timestampRowKey);
        aSessionForDeletes.apply(aDeleteOp);
      }
    }
  }
  aSessionForDeletes.close();
  Thread.sleep(2000); // Sleep to allow for scans to complete
}
 
Example 5
Source File: KuduScanCustomizer.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private static void processBody(Exchange exchange) throws KuduException, JsonProcessingException {
    final Message in = exchange.getIn();
    final KuduScanner scanner = in.getBody(KuduScanner.class);

    final List<String> answer = new ArrayList<>();
    while(scanner.hasMoreRows()) {
        RowResultIterator results = scanner.nextRows();

        while (results.hasNext()) {
            Map<String, Object> row = new HashMap<String, Object>();
            RowResult result = results.next();

            for (int i = 0; i < result.getSchema().getColumnCount(); i++) {
                String key = result.getSchema().getColumnByIndex(i).getName();
                Type type = result.getColumnType(i);

                switch (type.getName()) {
                    case "string":
                        row.put(key, result.getString(i));
                        break;
                    case "bool":
                        row.put(key, result.getBoolean(i));
                        break;
                    case "int8":
                    case "int16":
                    case "int32":
                        row.put(key, result.getInt(i));
                        break;
                    case "int64":
                        row.put(key, result.getLong(i));
                        break;
                    case "double":
                        row.put(key, result.getDouble(i));
                        break;
                    case "float":
                        row.put(key, result.getFloat(i));
                        break;
                    default:
                        throw new SyndesisServerException("The column schema type " + type.getName()
                                + " for column " + key
                                + " is not supported at the moment");
                }
            }
            answer.add(KuduSupport.toJSONBean(row));
        }
    }

    in.setBody(answer);
}
 
Example 6
Source File: KuduPartitionScannerCallable.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@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);
  bufferForTransmittingRecords.add(beginScanRecord); // Add a record entry that denotes the end of this scan.
  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);
  bufferForTransmittingRecords.add(endScanRecord); // Add a record entry that denotes the end of this scan.
  LOG.info(" Scanned a total of " + numRowsScanned + " for this scanner thread @tablet " +
      KuduScanToken.stringifySerializedToken(kuduPartitionScanAssignmentMeta.getSerializedKuduScanToken(),
      kuduClientHandle));
  return numRowsScanned;
}