Skip to content

Commit 4e8046d

Browse files
Wrapping TileDB 2.5.0 methods
1 parent 5859ee8 commit 4e8046d

File tree

12 files changed

+530
-36
lines changed

12 files changed

+530
-36
lines changed

cmake/Modules/FindTileDB_EP.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ if (NOT TILEDB_FOUND)
4848
# Try to download prebuilt artifacts unless the user specifies to build from source
4949
if(DOWNLOAD_TILEDB_PREBUILT)
5050
if (WIN32) # Windows
51-
SET(DOWNLOAD_URL "https://github.com/TileDB-Inc/TileDB/releases/download/2.5.0/tiledb-windows-x86_64-2.5.0-d11292d.zip")
52-
SET(DOWNLOAD_SHA1 "9db08d120fbaab2d635b086c1d2861a824994461")
53-
elseif(APPLE) # OSX
54-
SET(DOWNLOAD_URL "https://github.com/TileDB-Inc/TileDB/releases/download/2.5.0/tiledb-macos-x86_64-2.5.0-d11292d.tar.gz")
55-
SET(DOWNLOAD_SHA1 "daa6791eb08c876b127292cfe084f9de7a799766")
51+
SET(DOWNLOAD_URL "https://github.com/TileDB-Inc/TileDB/releases/download/2.5.1/tiledb-windows-x86_64-2.5.1-5b65a96.zip")
52+
SET(DOWNLOAD_SHA1 "d08658d08fab8da1c6d21c6c7af68b02d9d5d9e7")
53+
elseif(APPLE) # macOS
54+
SET(DOWNLOAD_URL "https://github.com/TileDB-Inc/TileDB/releases/download/2.5.1/tiledb-macos-x86_64-2.5.1-5b65a96.tar.gz")
55+
SET(DOWNLOAD_SHA1 "66521ccf7b5e6fe9be29c0107e8bb433bb50cfad")
5656
else() # Linux
57-
SET(DOWNLOAD_URL "https://github.com/TileDB-Inc/TileDB/releases/download/2.5.0/tiledb-linux-x86_64-2.5.0-d11292d.tar.gz")
58-
SET(DOWNLOAD_SHA1 "937b08fc58f0783d5738175dfebc23f69a512ca1")
57+
SET(DOWNLOAD_URL "https://github.com/TileDB-Inc/TileDB/releases/download/2.5.1/tiledb-linux-x86_64-2.5.1-5b65a96.tar.gz")
58+
SET(DOWNLOAD_SHA1 "d276396e0242c64d54479018517ad93206dc9e1b")
5959
endif()
6060

6161
ExternalProject_Add(ep_tiledb

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
TILEDB_GIT_REPOSITORY=https://github.com/TileDB-Inc/TileDB
2-
TILEDB_GIT_TAG=2.5.0
2+
TILEDB_GIT_TAG=2.5.1
33
TILEDB_VERBOSE=ON
44
TILEDB_S3=ON
55
TILEDB_AZURE=OFF

src/main/java/io/tiledb/java/api/Array.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,23 @@ public void evolve(Context ctx, ArraySchemaEvolution schemaEvolution) throws Til
411411
}
412412
}
413413

414+
/**
415+
* Upgrades an array to the latest format version.
416+
*
417+
* <p>**Example:** String uri = "test_array" array.upgradeVersion(ctx)
418+
*
419+
* @param ctx The TileDB context.
420+
* @param config Configuration parameters for the upgrade (`nullptr` means default, which will use
421+
* the config from `ctx`).
422+
*/
423+
public void upgradeVersion(Context ctx, Config config) throws TileDBError {
424+
try {
425+
ctx.handleError(tiledb.tiledb_array_upgrade_version(ctx.getCtxp(), uri, config.getConfigp()));
426+
} catch (TileDBError err) {
427+
throw err;
428+
}
429+
}
430+
414431
/**
415432
* Cleans up the array, such as consolidated fragments and array metadata. Note that this will
416433
* coarsen the granularity of time traveling (see docs for more information).

src/main/java/io/tiledb/java/api/FragmentInfo.java

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,191 @@ public String dump() throws TileDBError {
419419

420420
return tiledb.charpp_value(uri);
421421
}
422+
423+
/**
424+
* Retrieves the number of MBRs from the fragment.
425+
*
426+
* <p>In the case of sparse fragments, this is the number of physical tiles.
427+
*
428+
* <p>Dense fragments do not contain MBRs.
429+
*
430+
* @param fragmentID The index of the fragment of interest.
431+
* @return The number of MBRs.
432+
* @throws TileDBError
433+
*/
434+
public long getMBRNum(long fragmentID) throws TileDBError {
435+
SWIGTYPE_p_unsigned_long_long numFrags = tiledb.new_ullp();
436+
ctx.handleError(
437+
tiledb.tiledb_fragment_info_get_mbr_num(
438+
ctx.getCtxp(), this.fragmentInfop, fragmentID, numFrags));
439+
return tiledb.ullp_value(numFrags).longValue();
440+
}
441+
442+
/**
443+
* Retrieves the MBR from a given fragment for a given dimension index.
444+
*
445+
* @param fragmentID The index of the fragment of interest.
446+
* @param mid The mbr of the fragment of interest.
447+
* @param dimensionID The dimension index, following the order as it was defined in the domain of
448+
* the array schema.
449+
* @return The MBR.
450+
*/
451+
public long[] getMBRFromIndex(long fragmentID, long dimensionID, long mid) throws TileDBError {
452+
long[] mbr;
453+
try (NativeArray mbrArray = new NativeArray(ctx, 2, Long.class)) {
454+
ctx.handleError(
455+
tiledb.tiledb_fragment_info_get_mbr_from_index(
456+
ctx.getCtxp(),
457+
this.fragmentInfop,
458+
fragmentID,
459+
mid,
460+
dimensionID,
461+
mbrArray.toVoidPointer()));
462+
mbr = (long[]) mbrArray.toJavaArray();
463+
}
464+
return mbr;
465+
}
466+
467+
/**
468+
* Retrieves the MBR from a given fragment for a given dimension index.
469+
*
470+
* @param fragmentID The index of the fragment of interest.
471+
* @param mid The mbr of the fragment of interest.
472+
* @param dimName The dimension name.
473+
* @return The MBR.
474+
*/
475+
public long[] getMBRFromName(long fragmentID, String dimName, long mid) throws TileDBError {
476+
long[] mbr;
477+
try (NativeArray mbrArray = new NativeArray(ctx, 2, Long.class)) {
478+
ctx.handleError(
479+
tiledb.tiledb_fragment_info_get_mbr_from_name(
480+
ctx.getCtxp(),
481+
this.fragmentInfop,
482+
fragmentID,
483+
mid,
484+
dimName,
485+
mbrArray.toVoidPointer()));
486+
mbr = (long[]) mbrArray.toJavaArray();
487+
}
488+
return mbr;
489+
}
490+
491+
/**
492+
* Returns the MBR of the fragment with the given index on the given dimension index. Applicable
493+
* to string dimensions.
494+
*
495+
* @param fragmentID The index of the fragment of interest.
496+
* @param mid The mbr of the fragment of interest.
497+
* @param dimId The dimension index, following the order as it was defined in the domain of the
498+
* array schema.
499+
* @return The MBR.
500+
*/
501+
public Pair<Long, Long> getMBRVarSizeFromIndex(long fragmentID, long dimId, long mid)
502+
throws TileDBError {
503+
SWIGTYPE_p_unsigned_long_long startSize = tiledb.new_ullp();
504+
SWIGTYPE_p_unsigned_long_long endSize = tiledb.new_ullp();
505+
ctx.handleError(
506+
tiledb.tiledb_fragment_info_get_mbr_var_size_from_index(
507+
ctx.getCtxp(), this.fragmentInfop, fragmentID, mid, dimId, startSize, endSize));
508+
return new Pair<>(
509+
tiledb.ullp_value(startSize).longValue(), tiledb.ullp_value(endSize).longValue());
510+
}
511+
512+
/**
513+
* Returns the MBR of the fragment with the given index on the given dimension name. Applicable to
514+
* string dimensions.
515+
*
516+
* @param fragmentID The index of the fragment of interest.
517+
* @param mid The mbr of the fragment of interest.
518+
* @param dimName The dimension name.
519+
* @return The MBR.
520+
*/
521+
public Pair<Long, Long> getMBRVarSizeFromName(long fragmentID, String dimName, long mid)
522+
throws TileDBError {
523+
SWIGTYPE_p_unsigned_long_long startSize = tiledb.new_ullp();
524+
SWIGTYPE_p_unsigned_long_long endSize = tiledb.new_ullp();
525+
ctx.handleError(
526+
tiledb.tiledb_fragment_info_get_mbr_var_size_from_name(
527+
ctx.getCtxp(), this.fragmentInfop, fragmentID, mid, dimName, startSize, endSize));
528+
return new Pair<>(
529+
tiledb.ullp_value(startSize).longValue(), tiledb.ullp_value(endSize).longValue());
530+
}
531+
532+
/**
533+
* Returns the MBR of the fragment with the given index on the given dimension index. Applicable
534+
* to string dimensions.
535+
*
536+
* @param fragmentID The index of the fragment of interest.
537+
* @param mid The mbr of the fragment of interest.
538+
* @param dimId The dimension index, following the order as it was defined in the domain of the
539+
* array schema.
540+
* @return The MBR.
541+
*/
542+
public Pair<String, String> getMBRVarFromIndex(long fragmentID, long dimId, long mid)
543+
throws TileDBError {
544+
Pair<Long, Long> size = this.getMBRVarSizeFromIndex(fragmentID, dimId, mid);
545+
546+
try (NativeArray start = new NativeArray(ctx, size.getFirst().intValue(), String.class);
547+
NativeArray end = new NativeArray(ctx, size.getSecond().intValue(), String.class); ) {
548+
ctx.handleError(
549+
tiledb.tiledb_fragment_info_get_mbr_var_from_index(
550+
ctx.getCtxp(),
551+
this.fragmentInfop,
552+
fragmentID,
553+
mid,
554+
dimId,
555+
start.toVoidPointer(),
556+
end.toVoidPointer()));
557+
Object st = new String((byte[]) start.toJavaArray());
558+
Object e = new String((byte[]) end.toJavaArray());
559+
return new Pair(st, e);
560+
}
561+
}
562+
563+
/**
564+
* Returns the MBR of the fragment with the given index on the given dimension name. Applicable to
565+
* string dimensions.
566+
*
567+
* @param fragmentID The index of the fragment of interest.
568+
* @param mid The mbr of the fragment of interest.
569+
* @param dimName The dimension name.
570+
* @return The MBR.
571+
*/
572+
public Pair<String, String> getMBRVarFromName(long fragmentID, String dimName, long mid)
573+
throws TileDBError {
574+
Pair<Long, Long> size = this.getMBRVarSizeFromName(fragmentID, dimName, mid);
575+
576+
try (NativeArray start = new NativeArray(ctx, size.getFirst().intValue(), String.class);
577+
NativeArray end = new NativeArray(ctx, size.getSecond().intValue(), String.class); ) {
578+
ctx.handleError(
579+
tiledb.tiledb_fragment_info_get_mbr_var_from_name(
580+
ctx.getCtxp(),
581+
this.fragmentInfop,
582+
fragmentID,
583+
mid,
584+
dimName,
585+
start.toVoidPointer(),
586+
end.toVoidPointer()));
587+
Object st = new String((byte[]) start.toJavaArray());
588+
Object e = new String((byte[]) end.toJavaArray());
589+
return new Pair(st, e);
590+
}
591+
}
592+
593+
/**
594+
* Get the fragment info schema name.
595+
*
596+
* @param fragmentID The fragment info object.
597+
* @return The schema name.
598+
* @throws TileDBError
599+
*/
600+
public String getArraySchemaName(long fragmentID) throws TileDBError {
601+
SWIGTYPE_p_p_char name = tiledb.new_charpp();
602+
603+
ctx.handleError(
604+
tiledb.tiledb_fragment_info_get_array_schema_name(
605+
ctx.getCtxp(), fragmentInfop, fragmentID, name));
606+
607+
return tiledb.charpp_value(name);
608+
}
422609
}

src/test/java/io/tiledb/java/api/ArrayTest.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
import static io.tiledb.java.api.QueryType.TILEDB_READ;
77
import static io.tiledb.java.api.QueryType.TILEDB_WRITE;
88

9+
import java.io.File;
10+
import java.io.IOException;
911
import java.math.BigInteger;
1012
import java.nio.charset.StandardCharsets;
13+
import java.nio.file.Path;
14+
import java.nio.file.Paths;
1115
import java.util.Map;
16+
import org.apache.commons.io.FileUtils;
1217
import org.junit.*;
1318
import org.junit.rules.TemporaryFolder;
1419

@@ -37,6 +42,11 @@ public void tearDown() throws Exception {
3742
ctx.close();
3843
}
3944

45+
private String testArrayURIString(String arrayName) {
46+
Path arraysPath = Paths.get("src", "test", "resources", "data", arrayName);
47+
return "file://".concat(arraysPath.toAbsolutePath().toString());
48+
}
49+
4050
private Object[] getArray(Object val) {
4151
if (val instanceof Object[]) return (Object[]) val;
4252
int arrlength = java.lang.reflect.Array.getLength(val);
@@ -761,4 +771,73 @@ public void testArrayReopen() throws Exception {
761771
array.reopen();
762772
}
763773
}
774+
775+
@Test
776+
public void testArrayUpgrade() throws TileDBError, IOException {
777+
778+
// move old array to new temp folder for the upgrade.
779+
String source = "src/test/resources/data/1.6/quickstart_sparse_array";
780+
File srcDir = new File(source);
781+
782+
String destination = "src/test/resources/data/quickstart_sparse_array_v2";
783+
File destDir = new File(destination);
784+
785+
try {
786+
FileUtils.copyDirectory(srcDir, destDir);
787+
} catch (IOException e) {
788+
e.printStackTrace();
789+
}
790+
791+
// READ BEFORE UPGRADE
792+
Array array = new Array(ctx, testArrayURIString("quickstart_sparse_array_v2"), TILEDB_READ);
793+
NativeArray subarray = new NativeArray(ctx, new int[] {1, 4, 1, 4}, Integer.class);
794+
795+
// Create query
796+
Query query = new Query(array, TILEDB_READ);
797+
query.setLayout(TILEDB_ROW_MAJOR);
798+
query.setSubarray(subarray);
799+
query.setBuffer("a", new NativeArray(ctx, 16, Integer.class));
800+
query.setBuffer("rows", new NativeArray(ctx, 16, Integer.class));
801+
query.setBuffer("cols", new NativeArray(ctx, 16, Integer.class));
802+
803+
// Submit query
804+
query.submit();
805+
806+
int[] rows = (int[]) query.getBuffer("rows");
807+
int[] cols = (int[]) query.getBuffer("cols");
808+
int[] data = (int[]) query.getBuffer("a");
809+
query.close();
810+
811+
// upgrade array
812+
array.upgradeVersion(ctx, array.getConfig());
813+
814+
// check schema
815+
array.getSchema().check();
816+
817+
// READ AFTER UPGRADE
818+
query = new Query(array, TILEDB_READ);
819+
query.setLayout(TILEDB_ROW_MAJOR);
820+
query.setSubarray(subarray);
821+
query.setBuffer("a", new NativeArray(ctx, 16, Integer.class));
822+
query.setBuffer("rows", new NativeArray(ctx, 16, Integer.class));
823+
query.setBuffer("cols", new NativeArray(ctx, 16, Integer.class));
824+
825+
// Submit query
826+
query.submit();
827+
828+
int[] rowsAfter = (int[]) query.getBuffer("rows");
829+
int[] colsAfter = (int[]) query.getBuffer("cols");
830+
int[] dataAfter = (int[]) query.getBuffer("a");
831+
832+
// clean up
833+
query.close();
834+
array.close();
835+
836+
// compare
837+
Assert.assertArrayEquals(cols, colsAfter);
838+
Assert.assertArrayEquals(rows, rowsAfter);
839+
Assert.assertArrayEquals(data, dataAfter);
840+
841+
FileUtils.deleteDirectory(destDir);
842+
}
764843
}

0 commit comments

Comments
 (0)