@Override public int run(String[] args) throws Exception { // Delete the users dataset boolean success = Datasets.delete("dataset:hdfs:/tmp/data/users"); return success ? 0 : 1; }
@Override public int run(String[] args) throws Exception { // Delete the products dataset boolean success = Datasets.delete("dataset:hdfs:/tmp/data/products"); return success ? 0 : 1; }
@Override public int run(String[] args) throws Exception { // Drop the events dataset boolean success = Datasets.delete("dataset:hive:/tmp/data/default/events"); return success ? 0 : 1; }
@Override public int run(String[] args) throws Exception { // Delete the users dataset boolean success = Datasets.delete("dataset:hive?dataset=users"); return success ? 0 : 1; }
/** * Delete a {@link Dataset} identified by the given dataset URI string. * <p> * When you call this method using a dataset URI, both data and metadata are * deleted. After you call this method, the dataset no longer exists, unless * an exception is thrown. * <p> * When you call this method using a view URI, data in that view is deleted. * The dataset's metadata is not changed. This can throw an * {@code UnsupportedOperationException} if the delete requires additional * work. For example, if some, but not all, of the data in an underlying data * file must be removed, then the implementation is allowed to reject the * deletion rather than copy the remaining records to a new file. * An implementation must document under what conditions it accepts deletes, * and under what conditions it rejects them. * <p> * URIs must begin with {@code dataset:}. The remainder of * the URI is implementation specific, depending on the dataset scheme. * * @param uri a {@code Dataset} URI string * @return {@code true} if any data or metadata is removed, {@code false} * otherwise * @throws NullPointerException if {@code uri} is null * @throws IllegalArgumentException if {@code uri} is not a dataset URI */ public static boolean delete(String uri) { return delete(URI.create(uri)); }
@Override public void run() { Datasets.delete(datasetUri); } });
@Override public void execute() throws MojoExecutionException, MojoFailureException { getConf(); // ensure properties are added to DefaultConfig if (uri != null) { Datasets.delete(uri); } else { LOG.warn( "kite.datasetName is deprecated, instead use kite.uri=<dataset-uri>"); Preconditions.checkArgument(datasetName != null, "kite.datasetName is required if kite.uri is not used"); DatasetRepository repo = getDatasetRepository(); repo.delete(datasetNamespace, datasetName); } } }
@Override public int run() throws IOException { if (targets == null || targets.isEmpty()) { throw new IllegalArgumentException("No views or datasets were specified."); } for (String uriOrName : targets) { if (isViewUri(uriOrName)) { View view = Datasets.load(uriOrName); Preconditions.checkArgument(viewMatches(view.getUri(), uriOrName), "Resolved view does not match requested view: " + view.getUri()); view.deleteAll(); } else if (isDatasetUri(uriOrName)) { Datasets.delete(uriOrName); } else { getDatasetRepository().delete(namespace, uriOrName); } console.debug("Deleted {}", uriOrName); } return 0; }
@Test public void testDeleteStringUri() { URI datasetUri = new URIBuilder(repoUri, "ns", "test").build(); Datasets.delete(datasetUri.toString()); verify(repo).delete("ns", "test"); verifyNoMoreInteractions(repo); }
@Test public void testDelete() { URI datasetUri = new URIBuilder(repoUri, "ns", "test").build(); Datasets.delete(datasetUri); verify(repo).delete("ns", "test"); verifyNoMoreInteractions(repo); }
@Before public void createFileSystemDataset() { String uri = "dataset:file:/tmp/datasets/ns/test"; DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .schema(schema) .partitionStrategy(ymd) .build(); Datasets.delete(uri); this.dataset = Datasets.create(uri, descriptor); }
@BeforeClass public static void createTestDataset() { Datasets.delete("dataset:file:/tmp/test_name"); test = Datasets.create("dataset:file:/tmp/test_name", new DatasetDescriptor.Builder() .schema(SCHEMA) .partitionStrategy(STRATEGY) .build()); }
@Test public void testUnpartitionedReplace() { // recreate temporary without a partition strategy Datasets.delete("dataset:file:/tmp/datasets/temporary"); DatasetDescriptor descriptor = new DatasetDescriptor .Builder(unpartitioned.getDescriptor()) .location((URI) null) // clear the location .build(); temporary = Datasets.create("dataset:file:/tmp/datasets/temporary", descriptor, TestRecord.class); Assert.assertTrue("Should allow replacing an unpartitioned dataset", unpartitioned.canReplace(unpartitioned)); // make sure there are multiple files writeTestRecords(unpartitioned); writeTestRecords(unpartitioned); writeTestRecords(temporary); writeTestRecords(temporary); Set<String> originalFiles = Sets.newHashSet( Iterators.transform(unpartitioned.pathIterator(), new GetFilename())); Set<String> replacementFiles = Sets.newHashSet( Iterators.transform(temporary.pathIterator(), new GetFilename())); Iterators.transform(temporary.pathIterator(), new GetFilename()); Assert.assertFalse("Sanity check", originalFiles.equals(replacementFiles)); unpartitioned.replace(unpartitioned, temporary); Set<String> replacedFiles = Sets.newHashSet( Iterators.transform(unpartitioned.pathIterator(), new GetFilename())); Assert.assertEquals("Should contain the replacement files", replacementFiles, replacedFiles); }
@Before public void createTestDatasets() { Datasets.delete("dataset:file:/tmp/datasets/unpartitioned"); Datasets.delete("dataset:file:/tmp/datasets/partitioned"); Datasets.delete("dataset:file:/tmp/datasets/temporary"); DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .schema(TestRecord.class) .build(); unpartitioned = Datasets.create("dataset:file:/tmp/datasets/unpartitioned", descriptor, TestRecord.class); descriptor = new DatasetDescriptor.Builder(descriptor) .property("kite.writer.cache-size", "20") .partitionStrategy(new PartitionStrategy.Builder() .hash("id", 4) .build()) .build(); partitioned = Datasets.create("dataset:file:/tmp/datasets/partitioned", descriptor, TestRecord.class); // create a second dataset with the same partitioning for replacement parts temporary = Datasets.create("dataset:file:/tmp/datasets/temporary", descriptor, TestRecord.class); writeTestRecords(unpartitioned); writeTestRecords(partitioned); writeTestRecords(temporary); }
@Before public void createTestDatasets() { Datasets.delete("dataset:file:/tmp/datasets/unpartitioned"); Datasets.delete("dataset:file:/tmp/datasets/partitioned"); DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .schema(TestRecord.class) .build(); unpartitioned = Datasets.create("dataset:file:/tmp/datasets/unpartitioned", descriptor, TestRecord.class); descriptor = new DatasetDescriptor.Builder(descriptor) .partitionStrategy(new PartitionStrategy.Builder() .hash("id", 4) .build()) .build(); partitioned = Datasets.create("dataset:file:/tmp/datasets/partitioned", descriptor, TestRecord.class); writeTestRecords(unpartitioned); writeTestRecords(partitioned); }
Datasets.delete(datasetUri);
@Test public void testDatasetNotPartitioned() { Datasets.delete("dataset:file:/tmp/datasets/ns/test"); final Dataset<GenericRecord> ds = Datasets.create( "dataset:file:/tmp/datasets/ns/test", new DatasetDescriptor.Builder() .schema(schema) .build()); Assert.assertEquals("Should work for empty relative directory", ds, FileSystemDatasets.viewForUri(ds, "file:/tmp/datasets/ns/test")); TestHelpers.assertThrows("Should reject paths in a non-partitioned dataset", IllegalArgumentException.class, new Runnable() { @Override public void run() { FileSystemDatasets.viewForUri(ds, "y=2014/m=03/d=14"); } }); }