Java Code Examples for org.apache.kudu.client.KuduTable#newDelete()

The following examples show how to use org.apache.kudu.client.KuduTable#newDelete() . 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: KuduSink.java    From sylph with Apache License 2.0 6 votes vote down vote up
private static Supplier<Operation> getOperationCreater(String mode, KuduTable kuduTable)
{
    //INSERT OR UPSET OR UPDATE OR DELETE
    switch (mode.toUpperCase()) {
        case "INSERT":
            return () -> kuduTable.newInsert();
        case "UPSET":
            return () -> kuduTable.newUpsert();
        case "UPDATE":
            return () -> kuduTable.newUpdate();
        case "DELETE":
            return () -> kuduTable.newDelete();
        default:
            throw new IllegalArgumentException();
    }
}
 
Example 2
Source File: NativeKuduClientSession.java    From presto-kudu with Apache License 2.0 6 votes vote down vote up
@Override
public void dropSchema(String schemaName) {
    if (DEFAULT_SCHEMA.equals(schemaName)) {
        throw new PrestoException(GENERIC_USER_ERROR, "Deleting default schema not allowed.");
    }
    else {
        try {
            for (SchemaTableName table : listTables(schemaName)) {
                dropTable(table);
            }
            KuduTable schemasTable = getSchemasTable();
            KuduSession session = client.newSession();
            try {
                Delete delete = schemasTable.newDelete();
                fillSchemaRow(delete.getRow(), schemaName);
                session.apply(delete);
            }
            finally {
                session.close();
            }
        }
        catch (KuduException e) {
            throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
        }
    }
}
 
Example 3
Source File: KuduTarget.java    From datacollector with Apache License 2.0 6 votes vote down vote up
/**
 * Return Operation based on the operation code. If the code has a number
 * that Kudu destination doesn't support, it throws UnsupportedOperationException.
 * @param table
 * @param op
 * @return
 * @throws UnsupportedOperationException
 */
protected Operation getOperation(KuduTable table, int op) throws UnsupportedOperationException {
  Operation operation = null;
  switch (op) {
    case OperationType.INSERT_CODE:
      operation = table.newInsert();
      break;
    case OperationType.UPSERT_CODE:
      operation = table.newUpsert();
      break;
    case OperationType.UPDATE_CODE:
      operation = table.newUpdate();
      break;
    case OperationType.DELETE_CODE:
      operation = table.newDelete();
      break;
    default:
      LOG.error("Operation {} not supported", op);
      throw new UnsupportedOperationException(String.format("Unsupported Operation: %s", op));
  }
  return operation;
}
 
Example 4
Source File: SchemaEmulationByTableNameConvention.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void dropSchema(KuduClient client, String schemaName)
{
    if (DEFAULT_SCHEMA.equals(schemaName)) {
        throw new PrestoException(GENERIC_USER_ERROR, "Deleting default schema not allowed.");
    }
    else {
        try {
            String prefix = getPrefixForTablesOfSchema(schemaName);
            for (String name : client.getTablesList(prefix).getTablesList()) {
                client.deleteTable(name);
            }

            KuduTable schemasTable = getSchemasTable(client);
            KuduSession session = client.newSession();
            try {
                Delete delete = schemasTable.newDelete();
                delete.getRow().addString(0, schemaName);
                session.apply(delete);
            }
            finally {
                session.close();
            }
        }
        catch (KuduException e) {
            throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
        }
    }
}
 
Example 5
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 6
Source File: AbstractKuduProcessor.java    From nifi with Apache License 2.0 4 votes vote down vote up
protected Delete deleteRecordFromKudu(KuduTable kuduTable, Record record, List<String> fieldNames, Boolean ignoreNull, Boolean lowercaseFields) {
    Delete delete = kuduTable.newDelete();
    buildPartialRow(kuduTable.getSchema(), delete.getRow(), record, fieldNames, ignoreNull, lowercaseFields);
    return delete;
}