use of org.apache.kudu.client.Delete in project presto by prestodb.
the class KuduUpdatablePageSource method deleteRows.
@Override
public void deleteRows(Block rowIds) {
Schema schema = table.getSchema();
KuduSession session = clientSession.newSession();
session.setFlushMode(FlushMode.AUTO_FLUSH_BACKGROUND);
try {
try {
for (int i = 0; i < rowIds.getPositionCount(); i++) {
int len = rowIds.getSliceLength(i);
Slice slice = rowIds.getSlice(i, 0, len);
PartialRow row = KeyEncoderAccessor.decodePrimaryKey(schema, slice.getBytes());
Delete delete = table.newDelete();
RowHelper.copyPrimaryKey(schema, row, delete.getRow());
session.apply(delete);
}
} finally {
session.close();
}
} catch (KuduException e) {
throw new RuntimeException(e);
}
}
use of org.apache.kudu.client.Delete in project gora by apache.
the class KuduStore method delete.
@Override
public boolean delete(K key) throws GoraException {
try {
Column pkc = kuduMapping.getPrimaryKey().get(0);
Delete delete = table.newDelete();
PartialRow row = delete.getRow();
KuduClientUtils.addObjectRow(row, pkc, key);
OperationResponse apply = session.apply(delete);
return !apply.hasRowError();
} catch (KuduException ex) {
throw new GoraException(ex);
}
}
use of org.apache.kudu.client.Delete in project apex-malhar by apache.
the class KuduInputOperatorCommons method truncateTable.
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();
// Sleep to allow for scans to complete
Thread.sleep(2000);
}
use of org.apache.kudu.client.Delete in project apex-malhar by apache.
the class AbstractKuduOutputOperator method processForDelete.
protected void processForDelete(KuduExecutionContext kuduExecutionContext) {
Delete thisDelete = kuduTable.newDelete();
// Kudu does not allow column values to be set in case of a delete mutation
Set<String> doNotWriteCols = kuduExecutionContext.getDoNotWriteColumns();
if (doNotWriteCols == null) {
doNotWriteCols = new HashSet<>();
}
doNotWriteCols.clear();
for (String columnName : allColumnDefs.keySet()) {
if (!(primaryKeyColumnNames.contains(columnName))) {
doNotWriteCols.add(columnName);
}
}
kuduExecutionContext.setDoNotWriteColumns(doNotWriteCols);
performCommonProcessing(thisDelete, kuduExecutionContext);
}
use of org.apache.kudu.client.Delete in project presto by prestodb.
the class SchemaEmulationByTableNameConvention method dropSchema.
@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);
}
}
}
Aggregations