Search in sources :

Example 1 with Update

use of org.apache.kudu.client.Update in project gora by apache.

the class KuduStore method deleteByQuery.

@Override
public long deleteByQuery(Query<K, T> query) throws GoraException {
    try {
        long count = 0;
        Column pkc = kuduMapping.getPrimaryKey().get(0);
        ColumnSchema column = table.getSchema().getColumn(pkc.getName());
        List<String> dbFields = new ArrayList<>();
        dbFields.add(pkc.getName());
        List<KuduPredicate> rangePredicates = KuduClientUtils.createRangePredicate(column, query.getStartKey(), query.getEndKey());
        rangePredicates.add(KuduPredicate.newIsNotNullPredicate(column));
        KuduScanner build = createScanner(rangePredicates, dbFields, query.getLimit());
        while (build.hasMoreRows()) {
            RowResultIterator nextRows = build.nextRows();
            for (RowResult it : nextRows) {
                count++;
                K key = (K) KuduClientUtils.getObjectRow(it, pkc);
                if (query.getFields() != null && query.getFields().length < kuduMapping.getFields().size()) {
                    Update updateOp = table.newUpdate();
                    PartialRow row = updateOp.getRow();
                    String[] avFields = getFieldsToQuery(query.getFields());
                    KuduClientUtils.addObjectRow(row, pkc, key);
                    for (String af : avFields) {
                        row.setNull(kuduMapping.getFields().get(af).getName());
                    }
                    session.apply(updateOp);
                } else {
                    delete(key);
                }
            }
        }
        build.close();
        return count;
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) PartialRow(org.apache.kudu.client.PartialRow) ColumnSchema(org.apache.kudu.ColumnSchema) Update(org.apache.kudu.client.Update) KuduPredicate(org.apache.kudu.client.KuduPredicate) KuduException(org.apache.kudu.client.KuduException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException) RowResultIterator(org.apache.kudu.client.RowResultIterator) RowResult(org.apache.kudu.client.RowResult) GoraException(org.apache.gora.util.GoraException) Column(org.apache.gora.kudu.mapping.Column) KuduScanner(org.apache.kudu.client.KuduScanner)

Example 2 with Update

use of org.apache.kudu.client.Update in project apex-malhar by apache.

the class AbstractKuduOutputOperator method processForUpdate.

protected void processForUpdate(KuduExecutionContext kuduExecutionContext) {
    Update thisUpdate = kuduTable.newUpdate();
    performCommonProcessing(thisUpdate, kuduExecutionContext);
}
Also used : Update(org.apache.kudu.client.Update)

Aggregations

Update (org.apache.kudu.client.Update)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Column (org.apache.gora.kudu.mapping.Column)1 GoraException (org.apache.gora.util.GoraException)1 ColumnSchema (org.apache.kudu.ColumnSchema)1 KuduException (org.apache.kudu.client.KuduException)1 KuduPredicate (org.apache.kudu.client.KuduPredicate)1 KuduScanner (org.apache.kudu.client.KuduScanner)1 PartialRow (org.apache.kudu.client.PartialRow)1 RowResult (org.apache.kudu.client.RowResult)1 RowResultIterator (org.apache.kudu.client.RowResultIterator)1