@Override public void apply() throws Exception { // delete the value kvTable.delete(KEY2); } });
@WriteOnly @Override public void delete(byte[] key) { kvTable.delete(key); }
@WriteOnly @Override public void delete(byte[] key) { kvTable.delete(key); }
/** * Delete a key. * * @param key the key to delete */ @WriteOnly public void delete(String key) { delete(Bytes.toBytes(key)); }
@Override public void apply() throws Exception { // add a write for table 1 to the transaction table1.write(KEY1, VAL2); // submit a delete for table 2 table2.delete(KEY2); throw new RuntimeException("Cancel transaction"); } });
Date processedDate = new Date(time); if (processedDate.before(expiryDate)) { table.delete(file.getKey()); } else { processedFiles.add(new String(file.getKey(), Charsets.UTF_8));
if (config.tableExpiryPeriod != null && config.tableExpiryPeriod > 0 && expiryDate != null && processedDate.before(expiryDate)) { processedFileTrackingTable.delete(keyValue.getKey()); } else { processedFiles.add(Bytes.toString(keyValue.getKey()));
@Override public void delete(final ProgramId serviceId) throws NotFoundException { Transactionals.execute(transactional, context -> { byte[] key = Bytes.toBytes(ServiceDiscoverable.getName(serviceId)); KeyValueTable kvTable = getRouteTable(context); if (kvTable.read(key) == null) { throw new NotFoundException(String.format("Route Config for Service %s was not found.", serviceId)); } kvTable.delete(key); }, NotFoundException.class); }
@Override public void delete(final ProgramId serviceId) throws NotFoundException { Transactionals.execute(transactional, context -> { byte[] key = Bytes.toBytes(ServiceDiscoverable.getName(serviceId)); KeyValueTable kvTable = getRouteTable(context); if (kvTable.read(key) == null) { throw new NotFoundException(String.format("Route Config for Service %s was not found.", serviceId)); } kvTable.delete(key); }, NotFoundException.class); }
@Override public void run(DatasetContext dsContext) throws Exception { KeyValueTable stateTable = dsContext.getDataset(ETLRealtimeApplication.STATE_TABLE); byte[] startKey = Bytes.toBytes(String.format("%s%s", appName, SEPARATOR)); // Scan the table for appname: prefixes and remove rows which doesn't match the unique id of this application. try (CloseableIterator<KeyValue<byte[], byte[]>> rows = stateTable.scan(startKey, Bytes.stopKeyForPrefix(startKey))) { while (rows.hasNext()) { KeyValue<byte[], byte[]> row = rows.next(); if (Bytes.compareTo(stateStoreKeyBytes, row.getKey()) != 0) { stateTable.delete(row.getKey()); } } } } }, Exception.class);
private void testSparkWithLocalFiles(Class<? extends Application> appClass, String sparkProgram, String prefix) throws Exception { ApplicationManager applicationManager = deploy(NamespaceId.DEFAULT, appClass); URI localFile = createLocalPropertiesFile(prefix); SparkManager sparkManager = applicationManager.getSparkManager(sparkProgram) .start(Collections.singletonMap(SparkAppUsingLocalFiles.LOCAL_FILE_RUNTIME_ARG, localFile.toString())); sparkManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS); sparkManager.waitForStopped(120, TimeUnit.SECONDS); DataSetManager<KeyValueTable> kvTableManager = getDataset(SparkAppUsingLocalFiles.OUTPUT_DATASET_NAME); KeyValueTable kvTable = kvTableManager.get(); Map<String, String> expected = ImmutableMap.of("a", "1", "b", "2", "c", "3"); List<byte[]> deleteKeys = new ArrayList<>(); try (CloseableIterator<KeyValue<byte[], byte[]>> scan = kvTable.scan(null, null)) { for (int i = 0; i < 3; i++) { KeyValue<byte[], byte[]> next = scan.next(); Assert.assertEquals(expected.get(Bytes.toString(next.getKey())), Bytes.toString(next.getValue())); deleteKeys.add(next.getKey()); } Assert.assertFalse(scan.hasNext()); } // Cleanup after run kvTableManager.flush(); for (byte[] key : deleteKeys) { kvTable.delete(key); } kvTableManager.flush(); }
private void testSparkWithGetDataset(Class<? extends Application> appClass, String sparkProgram) throws Exception { ApplicationManager applicationManager = deploy(appClass); DataSetManager<FileSet> filesetManager = getDataset("logs"); FileSet fileset = filesetManager.get(); Location location = fileset.getLocation("nn"); prepareInputFileSetWithLogData(location); Map<String, String> inputArgs = new HashMap<>(); FileSetArguments.setInputPath(inputArgs, "nn"); Map<String, String> args = new HashMap<>(); args.putAll(RuntimeArguments.addScope(Scope.DATASET, "logs", inputArgs)); args.put("input", "logs"); args.put("output", "logStats"); SparkManager sparkManager = applicationManager.getSparkManager(sparkProgram); sparkManager.startAndWaitForRun(args, ProgramRunStatus.COMPLETED, 2, TimeUnit.MINUTES); DataSetManager<KeyValueTable> logStatsManager = getDataset("logStats"); KeyValueTable logStatsTable = logStatsManager.get(); validateGetDatasetOutput(logStatsTable); // Cleanup after run location.delete(true); logStatsManager.flush(); try (CloseableIterator<KeyValue<byte[], byte[]>> scan = logStatsTable.scan(null, null)) { while (scan.hasNext()) { logStatsTable.delete(scan.next().getKey()); } } logStatsManager.flush(); }
@Override public void apply() throws Exception { // write a value and read it back kvTable.write(KEY1, VAL1); Assert.assertArrayEquals(VAL1, kvTable.read(KEY1)); // update the value and read it back kvTable.write(KEY1, VAL2); Assert.assertArrayEquals(VAL2, kvTable.read(KEY1)); // attempt to swap, expecting old value Assert.assertFalse(kvTable.compareAndSwap(KEY1, VAL1, VAL3)); Assert.assertArrayEquals(VAL2, kvTable.read(KEY1)); // swap the value and read it back Assert.assertTrue(kvTable.compareAndSwap(KEY1, VAL2, VAL3)); Assert.assertArrayEquals(VAL3, kvTable.read(KEY1)); // delete the value and verify its gone kvTable.delete(KEY1); Assert.assertNull(kvTable.read(KEY1)); } });