Skip to content

Commit

Permalink
use tiledb_group_get_member_by_{index|name}_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisStaratzis committed Jan 10, 2024
1 parent 9c9fb9d commit eb844f7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
50 changes: 39 additions & 11 deletions src/main/java/io/tiledb/java/api/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,28 +194,56 @@ public long getMemberCount() throws TileDBError {
* @return the corresponding member in the group.
* @throws TileDBError
*/
public String getMemberURIByIndex(BigInteger index) throws TileDBError {
public String getMemberByIndexV2(BigInteger index) throws TileDBError {
Util.checkBigIntegerRange(index);
SWIGTYPE_p_tiledb_object_t objtypep = tiledb.new_tiledb_object_tp();
SWIGTYPE_p_p_char uripp = tiledb.new_charpp();
SWIGTYPE_p_p_tiledb_string_handle_t uripp = tiledb.new_tiledb_string_handle_tpp();
TileDBString ts = null;

try {
ctx.handleError(
tiledb.tiledb_group_get_member_by_index(
tiledb.tiledb_group_get_member_by_index_v2(
ctx.getCtxp(), getGroupp(), index, uripp, objtypep, uripp));
return tiledb.charpp_value(uripp);
ts = new TileDBString(ctx, uripp);
return ts.getView().getFirst();
} finally {
tiledb.delete_charpp(uripp);
if (ts != null) ts.close();
tiledb.delete_tiledb_object_tp(objtypep);
}
}

/**
* Get the URI of a member of a group by name
*
* @param name the name of the member
* @return the URI of the member with the given name
* @throws TileDBError
*/
public String getMemberByNameV2(String name) throws TileDBError {
SWIGTYPE_p_tiledb_object_t objtypep = tiledb.new_tiledb_object_tp();
SWIGTYPE_p_p_tiledb_string_handle_t uripp = tiledb.new_tiledb_string_handle_tpp();
TileDBString ts = null;

try {
ctx.handleError(
tiledb.tiledb_group_get_member_by_name_v2(
ctx.getCtxp(), getGroupp(), name, uripp, objtypep));
ts = new TileDBString(ctx, uripp);
return ts.getView().getFirst();
} finally {
if (ts != null) ts.close();
tiledb.delete_tiledb_object_tp(objtypep);
}
}

@Deprecated
/**
* Get the URI of a member of a group by name
*
* @param name the name of the member
* @return the URI of the member with the given name
* @throws TileDBError
* @deprecated is replaced by getMemberByNameV2(String name);
*/
public String getMemberURIByName(String name) throws TileDBError {
SWIGTYPE_p_tiledb_object_t objtypep = tiledb.new_tiledb_object_tp();
Expand All @@ -232,27 +260,27 @@ public String getMemberURIByName(String name) throws TileDBError {
}
}

@Deprecated
/**
* Get the name of a member of a group by index and details of group
* Get the URI of a member of a group by index and details of group
*
* @param index the index of the member.
* @return the corresponding member in the group.
* @throws TileDBError
* @deprecated is replaced by getMemberByIndexV2(BigInteger index)
*/
public String getMemberNameByIndex(BigInteger index) throws TileDBError {
public String getMemberURIByIndex(BigInteger index) throws TileDBError {
Util.checkBigIntegerRange(index);
SWIGTYPE_p_tiledb_object_t objtypep = tiledb.new_tiledb_object_tp();
SWIGTYPE_p_p_char uripp = tiledb.new_charpp();
SWIGTYPE_p_p_char namepp = tiledb.new_charpp();

try {
ctx.handleError(
tiledb.tiledb_group_get_member_by_index(
ctx.getCtxp(), getGroupp(), index, uripp, objtypep, namepp));
return tiledb.charpp_value(namepp);
ctx.getCtxp(), getGroupp(), index, uripp, objtypep, uripp));
return tiledb.charpp_value(uripp);
} finally {
tiledb.delete_charpp(uripp);
tiledb.delete_charpp(namepp);
tiledb.delete_tiledb_object_tp(objtypep);
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/io/tiledb/java/api/GroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ public void membersTest() throws Exception {
group.reopen(ctx, QueryType.TILEDB_READ);
Assert.assertEquals(3, group.getMemberCount());

// test getters
String[] uri = group.getMemberByNameV2("array3Name").split("/");
Assert.assertEquals("TileDB-Java/array3", uri[uri.length - 2] + "/" + uri[uri.length - 1]);

Assert.assertEquals("array2Name", group.getMemberByIndexV2(new BigInteger("1")));

// remove a member
group.reopen(ctx, TILEDB_WRITE);
group.removeMember("array2");
Expand Down

0 comments on commit eb844f7

Please sign in to comment.