org.apache.kudu.client.Upsert Java Examples

The following examples show how to use org.apache.kudu.client.Upsert. 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: KuduPageSink.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<?> appendPage(Page page)
{
    for (int position = 0; position < page.getPositionCount(); position++) {
        Upsert upsert = table.newUpsert();
        PartialRow row = upsert.getRow();
        int start = 0;
        if (generateUUID) {
            String id = format("%s-%08x", uuid, nextSubId++);
            row.addString(0, id);
            start = 1;
        }

        for (int channel = 0; channel < page.getChannelCount(); channel++) {
            appendColumn(row, page, position, channel, channel + start);
        }

        try {
            session.apply(upsert);
        }
        catch (KuduException e) {
            throw new RuntimeException(e);
        }
    }
    return NOT_BLOCKED;
}
 
Example #2
Source File: SchemaEmulationByTableNameConvention.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public void createSchema(KuduClient client, String schemaName)
{
    if (DEFAULT_SCHEMA.equals(schemaName)) {
        throw new SchemaAlreadyExistsException(schemaName);
    }
    else {
        try {
            KuduTable schemasTable = getSchemasTable(client);
            KuduSession session = client.newSession();
            try {
                Upsert upsert = schemasTable.newUpsert();
                upsert.getRow().addString(0, schemaName);
                session.apply(upsert);
            }
            finally {
                session.close();
            }
        }
        catch (KuduException e) {
            throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
        }
    }
}
 
Example #3
Source File: NativeKuduClientSession.java    From presto-kudu with Apache License 2.0 6 votes vote down vote up
@Override
public void createSchema(String schemaName) {
    if (DEFAULT_SCHEMA.equals(schemaName)) {
        throw new SchemaAlreadyExistsException(schemaName);
    }
    else {
        try {
            KuduTable schemasTable = getSchemasTable();
            KuduSession session = client.newSession();
            try {
                Upsert upsert = schemasTable.newUpsert();
                fillSchemaRow(upsert.getRow(), schemaName);
                session.apply(upsert);
            }
            finally {
                session.close();
            }
        }
        catch (KuduException e) {
            throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
        }
    }
}
 
Example #4
Source File: KuduPageSink.java    From presto-kudu with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<?> appendPage(Page page) {
    for (int position = 0; position < page.getPositionCount(); position++) {
        Upsert upsert = table.newUpsert();
        PartialRow row = upsert.getRow();
        int start = 0;
        if (generateUUID) {
            String id = String.format("%s-%08x", uuid, nextSubId++);
            row.addString(0, id);
            start = 1;
        }

        for (int channel = 0; channel < page.getChannelCount(); channel++) {
            appendColumn(row, page, position, channel, channel + start);
        }

        try {
            session.apply(upsert);
        } catch (KuduException e) {
            throw new RuntimeException(e);
        }
    }
    return NOT_BLOCKED;
}
 
Example #5
Source File: KuduTestUtils.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public Operation apply(TableAndRecord<Long> input) {
  Upsert upsert = input.getTable().newUpsert();
  PartialRow row = upsert.getRow();
  row.addLong(COL_ID, input.getRecord());
  row.addString(COL_NAME, input.getRecord() + ": name");
  return upsert;
}
 
Example #6
Source File: Metrics.java    From kudu-ts with Apache License 2.0 5 votes vote down vote up
public Upsert insertDatapoint(final String metric,
                              final int tagsetID,
                              final long time,
                              final double value) {
  Upsert insert = table.newUpsert();
  insert.getRow().addString(Tables.METRICS_METRIC_INDEX, metric);
  insert.getRow().addInt(Tables.METRICS_TAGSET_ID_INDEX, tagsetID);
  insert.getRow().addLong(Tables.METRICS_TIME_INDEX, time);
  insert.getRow().addDouble(Tables.METRICS_VALUE_INDEX, value);
  return insert;
}
 
Example #7
Source File: KuduInputOperatorCommons.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
public void addTestDataRows(int numRowsInEachPartition) throws Exception
{
  int intRowKeyStepsize = Integer.MAX_VALUE / SPLIT_COUNT_FOR_INT_ROW_KEY;
  int splitBoundaryForIntRowKey = intRowKeyStepsize;
  int[] inputrowkeyPartitionEntries = new int[SPLIT_COUNT_FOR_INT_ROW_KEY + 1];
  // setting the int keys that will fall in the range of all partitions
  for ( int i = 0; i < SPLIT_COUNT_FOR_INT_ROW_KEY; i++) {
    inputrowkeyPartitionEntries[i] = splitBoundaryForIntRowKey + 3; // 3 to fall into the partition next to boundary
    splitBoundaryForIntRowKey += intRowKeyStepsize;
  }
  inputrowkeyPartitionEntries[SPLIT_COUNT_FOR_INT_ROW_KEY] = splitBoundaryForIntRowKey + 3;
  AbstractKuduPartitionScanner<UnitTestTablePojo,InputOperatorControlTuple> scannerForAddingRows =
      unitTestStepwiseScanInputOperator.getScanner();
  ApexKuduConnection aCurrentConnection = scannerForAddingRows.getConnectionPoolForThreads().get(0);
  KuduSession aSessionForInserts = aCurrentConnection.getKuduClient().newSession();
  KuduTable currentTable = aCurrentConnection.getKuduTable();
  long seedValueForTimestampRowKey = 0L; // constant to allow for data landing on first partition for unit tests
  for ( int i = 0; i <= SPLIT_COUNT_FOR_INT_ROW_KEY; i++) { // range key iterator
    int intRowKeyBaseValue = inputrowkeyPartitionEntries[i] + i;
    for ( int k = 0; k < 2; k++) { // hash key iterator . The table defines two hash partitions
      long timestampRowKeyValue = seedValueForTimestampRowKey + k; // to avoid spilling to another tablet
      String stringRowKeyValue = "" + timestampRowKeyValue + k; // to avoid spilling to another tablet randomly
      for ( int y = 0; y < numRowsInEachPartition; y++) {
        Upsert aNewRow = currentTable.newUpsert();
        PartialRow rowValue  = aNewRow.getRow();
        // Start assigning row keys below the current split boundary.
        rowValue.addInt("introwkey",intRowKeyBaseValue - y - 1);
        rowValue.addString("stringrowkey",stringRowKeyValue);
        rowValue.addLong("timestamprowkey",timestampRowKeyValue);
        rowValue.addLong("longdata",(seedValueForTimestampRowKey + y));
        rowValue.addString("stringdata", ("" + seedValueForTimestampRowKey + y));
        OperationResponse response = aSessionForInserts.apply(aNewRow);
      }
    }
  }
  List<OperationResponse> insertResponse = aSessionForInserts.flush();
  aSessionForInserts.close();
  Thread.sleep(2000); // Sleep to allow for scans to complete
}
 
Example #8
Source File: DafPutKudu.java    From daf-kylo with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected Upsert upsertRecordToKudu(KuduTable kuduTable, Record record, List<String> fieldNames) throws IllegalStateException, Exception {
    Upsert upsert = kuduTable.newUpsert();
    this.insert(kuduTable, upsert, record, fieldNames);
    return upsert;
}
 
Example #9
Source File: AbstractKuduOutputOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
protected void processForUpsert(KuduExecutionContext kuduExecutionContext)
{
  Upsert thisUpsert = kuduTable.newUpsert();
  performCommonProcessing(thisUpsert,kuduExecutionContext);
}
 
Example #10
Source File: AbstractKuduProcessor.java    From nifi with Apache License 2.0 4 votes vote down vote up
protected Upsert upsertRecordToKudu(KuduTable kuduTable, Record record, List<String> fieldNames, Boolean ignoreNull, Boolean lowercaseFields) {
    Upsert upsert = kuduTable.newUpsert();
    buildPartialRow(kuduTable.getSchema(), upsert.getRow(), record, fieldNames, ignoreNull, lowercaseFields);
    return upsert;
}
 
Example #11
Source File: MockPutKudu.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
protected Upsert upsertRecordToKudu(KuduTable kuduTable, Record record, List<String> fieldNames, Boolean ignoreNull, Boolean lowercaseFields) {
    return mock(Upsert.class);
}
 
Example #12
Source File: DafAbstractKudu.java    From daf-kylo with GNU Affero General Public License v3.0 votes vote down vote up
protected abstract Upsert upsertRecordToKudu(final KuduTable table, final Record record, final List<String> fields) throws Exception;