Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ public class ArrayConsolidateExample {
public static void main(String[] args) throws Exception {
// Create TileDB context
Context ctx = new Context();
String arrayURI = "my_dense_array";

// Consolidate array
Array.consolidate(ctx, "my_dense_array");
Array.consolidate(ctx, arrayURI);

// Vacuum array
Array.vacuum(ctx, arrayURI);
}
}
29 changes: 29 additions & 0 deletions src/main/java/io/tiledb/java/api/Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,35 @@ public static void consolidate(
}
}

/**
* Cleans up the array, such as consolidated fragments and array metadata. Note that this will
* coarsen the granularity of time traveling (see docs for more information).
*
* <p>This method uses as the vacuum configuration the configuration instance that is encapsulated
* in the context (ctx) instance (ctx.getConfig()).
*
* @param arrayURI The array URI
* @param ctx The TileDB context
* @throws TileDBError A TileDB exception
*/
public static void vacuum(Context ctx, String arrayURI) throws TileDBError {
ctx.handleError(
tiledb.tiledb_array_vacuum(ctx.getCtxp(), arrayURI, ctx.getConfig().getConfigp()));
}

/**
* Cleans up the array, such as consolidated fragments and array metadata. Note that this will
* coarsen the granularity of time traveling (see docs for more information).
*
* @param arrayURI The array URI
* @param ctx The TileDB context
* @param config The TileDB config that will be used for the vacuum process
* @throws TileDBError A TileDB exception
*/
public static void vacuum(Context ctx, String arrayURI, Config config) throws TileDBError {
ctx.handleError(tiledb.tiledb_array_vacuum(ctx.getCtxp(), arrayURI, config.getConfigp()));
}

/**
* Checks if a given URI is an existing TileDB array object
*
Expand Down
29 changes: 28 additions & 1 deletion src/test/java/io/tiledb/java/api/FragmentsConsolidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static io.tiledb.java.api.QueryType.TILEDB_READ;
import static io.tiledb.java.api.QueryType.TILEDB_WRITE;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
Expand Down Expand Up @@ -35,7 +36,7 @@ public void teardown() throws Exception {
}

@Test
public void test() throws Exception {
public void testConsolidate() throws Exception {
// create array
arrayCreate();
// updates
Expand All @@ -48,6 +49,32 @@ public void test() throws Exception {
arrayRead();
}

@Test
public void testVacuum() throws Exception {
// create array
arrayCreate();
// updates
arrayWrite1();
arrayWrite2();
arrayWrite3();
// consolidate
Array.consolidate(ctx, arrayURI);
Array.vacuum(ctx, arrayURI);
// verify consolidation
arrayRead();

// verify vacuum
File f = new File(arrayURI);
int nFiles = 0;
for (File file : f.listFiles())
if (file.isDirectory() && !file.getName().equals("__meta")) {
System.out.println(file.getAbsolutePath());
nFiles++;
}

Assert.assertEquals(1, nFiles);
}

public void arrayCreate() throws Exception {

// Create getDimensions
Expand Down