Skip to content
Merged
Changes from 2 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
58 changes: 58 additions & 0 deletions src/main/java/io/tiledb/java/api/Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import static io.tiledb.java.api.QueryType.*;

import io.tiledb.libtiledb.*;

import java.math.BigInteger;
import java.util.HashMap;

/**
Expand Down Expand Up @@ -73,6 +75,24 @@ public Array(Context ctx, String uri) throws TileDBError {
openArray(ctx, uri, TILEDB_READ, EncryptionType.TILEDB_NO_ENCRYPTION, new byte[] {});
}

/**
* Constructs an Array object opening the array for reading at a user-given timestamp (time-travelling).
*
* <pre><b>Example:</b>
* {@code
* Context ctx = new Context();
* Array array new Array(ctx, "s3://bucket-name/array-name");
* }</pre>
*
* @param ctx TileDB context
* @param uri The array URI
* @param timestamp The timestamp
* @exception TileDBError A TileDB exception
*/
public Array(Context ctx, String uri, BigInteger timestamp) throws TileDBError {
openArray(ctx, uri, TILEDB_READ, EncryptionType.TILEDB_NO_ENCRYPTION, new byte[] {}, timestamp);
}

/**
* Constructs an Array object, opening the array for the given query type.
*
Expand Down Expand Up @@ -155,6 +175,44 @@ private synchronized void openArray(
this.arrayp = _arrayp;
}

private synchronized void openArray(
Context ctx, String uri, QueryType query_type, EncryptionType encryption_type, byte[] key,
BigInteger timestamp)
throws TileDBError {
SWIGTYPE_p_p_tiledb_array_t _arraypp = tiledb.new_tiledb_array_tpp();
try {
ctx.handleError(tiledb.tiledb_array_alloc(ctx.getCtxp(), uri, _arraypp));
} catch (TileDBError err) {
tiledb.delete_tiledb_array_tpp(_arraypp);
throw err;
}
SWIGTYPE_p_tiledb_array_t _arrayp = tiledb.tiledb_array_tpp_value(_arraypp);
ArraySchema _schema;
try (NativeArray keyArray = new NativeArray(ctx, key, Byte.class)) {
try {
ctx.handleError(
tiledb.tiledb_array_open_at_with_key(
ctx.getCtxp(),
_arrayp,
query_type.toSwigEnum(),
encryption_type.toSwigEnum(),
keyArray.toVoidPointer(),
keyArray.getSize(),
timestamp));
} catch (TileDBError err) {
tiledb.delete_tiledb_array_tpp(_arraypp);
throw err;
}
_schema = new ArraySchema(ctx, uri, encryption_type, key);
}
this.ctx = ctx;
this.uri = uri;
this.query_type = query_type;
this.schema = _schema;
this.arraypp = _arraypp;
this.arrayp = _arrayp;
}

private void checkIsOpen() throws TileDBError {
if (arrayp == null) {
throw new TileDBError("TileDB Array " + uri + " is closed");
Expand Down