Search in sources :

Example 1 with Delete

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);
    }
}
Also used : Delete(org.apache.kudu.client.Delete) KuduSession(org.apache.kudu.client.KuduSession) Slice(io.airlift.slice.Slice) Schema(org.apache.kudu.Schema) PartialRow(org.apache.kudu.client.PartialRow) KuduException(org.apache.kudu.client.KuduException)

Example 2 with Delete

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);
    }
}
Also used : Delete(org.apache.kudu.client.Delete) GoraException(org.apache.gora.util.GoraException) Column(org.apache.gora.kudu.mapping.Column) PartialRow(org.apache.kudu.client.PartialRow) OperationResponse(org.apache.kudu.client.OperationResponse) KuduException(org.apache.kudu.client.KuduException)

Example 3 with Delete

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);
}
Also used : Delete(org.apache.kudu.client.Delete) KuduScanToken(org.apache.kudu.client.KuduScanToken) KuduSession(org.apache.kudu.client.KuduSession) KuduTable(org.apache.kudu.client.KuduTable) RowResultIterator(org.apache.kudu.client.RowResultIterator) RowResult(org.apache.kudu.client.RowResult) KuduScanner(org.apache.kudu.client.KuduScanner)

Example 4 with Delete

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);
}
Also used : Delete(org.apache.kudu.client.Delete)

Example 5 with Delete

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);
        }
    }
}
Also used : Delete(org.apache.kudu.client.Delete) KuduSession(org.apache.kudu.client.KuduSession) PrestoException(com.facebook.presto.spi.PrestoException) KuduTable(org.apache.kudu.client.KuduTable) KuduException(org.apache.kudu.client.KuduException)

Aggregations

Delete (org.apache.kudu.client.Delete)6 KuduException (org.apache.kudu.client.KuduException)4 KuduSession (org.apache.kudu.client.KuduSession)4 KuduTable (org.apache.kudu.client.KuduTable)3 PartialRow (org.apache.kudu.client.PartialRow)3 Schema (org.apache.kudu.Schema)2 OperationResponse (org.apache.kudu.client.OperationResponse)2 PrestoException (com.facebook.presto.spi.PrestoException)1 Slice (io.airlift.slice.Slice)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Column (org.apache.gora.kudu.mapping.Column)1 GoraException (org.apache.gora.util.GoraException)1 ColumnSchema (org.apache.kudu.ColumnSchema)1 Type (org.apache.kudu.Type)1 KuduScanToken (org.apache.kudu.client.KuduScanToken)1 KuduScanner (org.apache.kudu.client.KuduScanner)1 RowResult (org.apache.kudu.client.RowResult)1 RowResultIterator (org.apache.kudu.client.RowResultIterator)1