org.apache.kudu.client.Delete Java Examples
The following examples show how to use
org.apache.kudu.client.Delete.
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: KuduUpdatablePageSource.java From presto with Apache License 2.0 | 6 votes |
@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); } }
Example #2
Source File: NativeKuduClientSession.java From presto-kudu with Apache License 2.0 | 6 votes |
@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: KuduUpdatablePageSource.java From presto-kudu with Apache License 2.0 | 6 votes |
@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); } }
Example #4
Source File: AbstractKuduOutputOperator.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
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); }
Example #5
Source File: KuduOperations.java From geowave with Apache License 2.0 | 6 votes |
public List<Delete> getDeletions( final KuduTable table, final List<KuduPredicate> predicates, final Function<RowResult, PersistentKuduRow> adapter) throws KuduException { // TODO: Kudu Java API does not support deleting with predicates, so we first perform a scan and // then perform individual row deletions with the full primary key. This is inefficient, because // we need to read in entire rows in order to perform deletions. final KuduScannerBuilder scannerBuilder = getScannerBuilder(table); for (final KuduPredicate pred : predicates) { scannerBuilder.addPredicate(pred); } final KuduScanner scanner = scannerBuilder.build(); final List<RowResultIterator> allResults = new ArrayList<>(); while (scanner.hasMoreRows()) { allResults.add(scanner.nextRows()); } final Iterator<Delete> deletions = Streams.stream(Iterators.concat(allResults.iterator())).map(result -> { final PersistentKuduRow row = adapter.apply(result); final Delete delete = table.newDelete(); row.populatePartialRowPrimaryKey(delete.getRow()); return delete; }).iterator(); return Lists.newArrayList(deletions); }
Example #6
Source File: SchemaEmulationByTableNameConvention.java From presto with Apache License 2.0 | 5 votes |
@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 #7
Source File: KuduInputOperatorCommons.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
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 #8
Source File: AbstractKuduProcessor.java From nifi with Apache License 2.0 | 4 votes |
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; }
Example #9
Source File: MockPutKudu.java From nifi with Apache License 2.0 | 4 votes |
@Override protected Delete deleteRecordFromKudu(KuduTable kuduTable, Record record, List<String> fieldNames, Boolean ignoreNull, Boolean lowercaseFields) { return mock(Delete.class); }