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
6 changes: 2 additions & 4 deletions src/main/java/io/tiledb/java/api/Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,7 @@ public HashMap<String, Pair> nonEmptyDomain() throws TileDBError {
public Pair getNonEmptyDomainFromIndex(long index) throws TileDBError {
checkIsOpen();
try (Domain domain = schema.getDomain();
NativeArray domainArray =
new NativeArray(ctx, 2 * (int) domain.getRank(), domain.getType())) {
NativeArray domainArray = new NativeArray(ctx, 2, domain.getDimension(index).getType())) {

if (domain.getDimension(index).isVar()) return getNonEmptyDomainVarFromIndex(index);

Expand Down Expand Up @@ -515,8 +514,7 @@ public Pair getNonEmptyDomainFromIndex(long index) throws TileDBError {
public Pair getNonEmptyDomainFromName(String name) throws TileDBError {
checkIsOpen();
try (Domain domain = schema.getDomain();
NativeArray domainArray =
new NativeArray(ctx, 2 * (int) domain.getRank(), domain.getType())) {
NativeArray domainArray = new NativeArray(ctx, 2, domain.getDimension(name).getType())) {

if (domain.getDimension(name).isVar()) return this.getNonEmptyDomainVarFromName(name);

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/io/tiledb/java/api/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public synchronized Query addRange(int dimIdx, Object start, Object end) throws
Datatype dimType;
try (ArraySchema schema = array.getSchema();
Domain domain = schema.getDomain()) {
dimType = domain.getType();
dimType = domain.getDimension(dimIdx).getType();
}

// We use java type check here because we can not tell the difference between unsigned and
Expand Down Expand Up @@ -215,7 +215,7 @@ public synchronized Query addRangeVar(int dimIdx, String start, String end) thro
Datatype dimType;
try (ArraySchema schema = array.getSchema();
Domain domain = schema.getDomain()) {
dimType = domain.getType();
dimType = domain.getDimension(dimIdx).getType();
}

Types.javaTypeCheck(start.getClass(), dimType.javaClass());
Expand Down Expand Up @@ -276,7 +276,7 @@ public synchronized Pair<String, String> getRangeVar(int dimIdx, BigInteger rang
Datatype dimType;
try (ArraySchema schema = array.getSchema();
Domain domain = schema.getDomain()) {
dimType = domain.getType();
dimType = domain.getDimension(dimIdx).getType();
}

Pair<Long, Long> size = this.getRangeVarSize(dimIdx, rangeIdx);
Expand Down Expand Up @@ -325,7 +325,7 @@ public Pair<Object, Object> getRange(int dimIdx, long rangeIdx) throws TileDBErr
Datatype dimType;
try (ArraySchema schema = array.getSchema();
Domain domain = schema.getDomain()) {
dimType = domain.getType();
dimType = domain.getDimension(dimIdx).getType();
}

SWIGTYPE_p_p_void startArrpp = tiledb.new_voidpArray(1);
Expand Down Expand Up @@ -368,7 +368,7 @@ public synchronized Query setBuffer(String attr, NativeArray buffer) throws Tile
try (ArraySchema schema = array.getSchema()) {
try (Domain domain = schema.getDomain()) {
if (attr.equals(tiledb.tiledb_coords())) {
Types.typeCheck(domain.getType(), buffer.getNativeType());
Types.typeCheck(domain.getDimension(attr).getType(), buffer.getNativeType());
} else if (domain.hasDimension(attr)) {
Types.typeCheck(domain.getDimension(attr).getType(), buffer.getNativeType());
} else {
Expand Down Expand Up @@ -429,7 +429,7 @@ public synchronized Query setBuffer(String attr, NativeArray buffer, long buffer
try (ArraySchema schema = array.getSchema()) {
try (Domain domain = schema.getDomain()) {
if (attr.equals(tiledb.tiledb_coords())) {
Types.typeCheck(domain.getType(), buffer.getNativeType());
Types.typeCheck(domain.getDimension(attr).getType(), buffer.getNativeType());
} else if (domain.hasDimension(attr)) {
Types.typeCheck(domain.getDimension(attr).getType(), buffer.getNativeType());
} else {
Expand Down Expand Up @@ -492,7 +492,7 @@ public synchronized Query setBuffer(String attr, NativeArray offsets, NativeArra
try (ArraySchema schema = array.getSchema()) {
try (Domain domain = schema.getDomain()) {
if (attr.equals(tiledb.tiledb_coords())) {
Types.typeCheck(domain.getType(), buffer.getNativeType());
Types.typeCheck(domain.getDimension(attr).getType(), buffer.getNativeType());
} else if (domain.hasDimension(attr)) {
Types.typeCheck(domain.getDimension(attr).getType(), buffer.getNativeType());
} else {
Expand Down Expand Up @@ -748,6 +748,7 @@ public Query setCoordinates(NativeArray buffer) throws TileDBError {
* @return The query result coordinate buffer.
* @exception TileDBError A TileDB exception
*/
@Deprecated
public Object getCoordinates() throws TileDBError {
return getBuffer(tiledb.tiledb_coords());
}
Expand Down
30 changes: 18 additions & 12 deletions src/test/java/io/tiledb/java/api/AsyncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ public void test() throws Exception {

public void arrayCreate() throws Exception {
// Create getDimensions
Dimension<Integer> rows =
new Dimension<Integer>(ctx, "rows", Integer.class, new Pair<Integer, Integer>(1, 4), 2);
Dimension<Integer> cols =
new Dimension<Integer>(ctx, "cols", Integer.class, new Pair<Integer, Integer>(1, 4), 2);
Dimension<Integer> rows = new Dimension(ctx, "rows", Integer.class, new Pair(1, 4), 2);
Dimension<Integer> cols = new Dimension(ctx, "cols", Integer.class, new Pair(1, 4), 2);

// Create and set getDomain
Domain domain = new Domain(ctx);
Expand All @@ -65,18 +63,20 @@ public void arrayCreate() throws Exception {
}

public void arrayWrite() throws Exception {
NativeArray d1_data = new NativeArray(ctx, new int[] {1, 2, 2, 4}, Integer.class);
NativeArray d2_data = new NativeArray(ctx, new int[] {1, 1, 2, 3}, Integer.class);

// Prepare cell buffers
NativeArray data = new NativeArray(ctx, new int[] {1, 2, 3, 4}, Integer.class);

NativeArray coords_buff =
new NativeArray(ctx, new int[] {1, 1, 2, 1, 2, 2, 4, 3}, Integer.class);

// Create query
Array array = new Array(ctx, arrayURI, TILEDB_WRITE);
Query query = new Query(array);
query.setLayout(TILEDB_GLOBAL_ORDER);
query.setBuffer("rows", d1_data);
query.setBuffer("cols", d2_data);
query.setBuffer("a", data);
query.setCoordinates(coords_buff);

// Submit query
query.submitAsync();

Expand All @@ -102,9 +102,13 @@ private void arrayRead() throws Exception {
Query query = new Query(array, TILEDB_READ);
query.setLayout(TILEDB_ROW_MAJOR);
query.setBuffer(
"a", new NativeArray(ctx, max_sizes.get("a").getSecond().intValue(), Integer.class));
query.setCoordinates(
"rows",
new NativeArray(ctx, max_sizes.get(TILEDB_COORDS).getSecond().intValue(), Integer.class));
query.setBuffer(
"cols",
new NativeArray(ctx, max_sizes.get(TILEDB_COORDS).getSecond().intValue(), Integer.class));
query.setBuffer(
"a", new NativeArray(ctx, max_sizes.get("a").getSecond().intValue(), Integer.class));

// Submit query with callback
query.submitAsync(new ReadCallback());
Expand All @@ -119,14 +123,16 @@ private void arrayRead() throws Exception {
// Print cell values (assumes all getAttributes are read)
HashMap<String, Pair<Long, Long>> result_el = query.resultBufferElements();

int[] rows = (int[]) query.getBuffer("rows");
int[] cols = (int[]) query.getBuffer("cols");
int[] data = (int[]) query.getBuffer("a");
int[] coords = (int[]) query.getCoordinates();

query.close();
array.close();

Assert.assertTrue(callbackCalled);
Assert.assertArrayEquals(coords, new int[] {1, 1, 2, 1, 2, 2, 4, 3});
Assert.assertArrayEquals(rows, new int[] {1, 2, 2, 4});
Assert.assertArrayEquals(cols, new int[] {1, 1, 2, 3});
Assert.assertArrayEquals(data, new int[] {1, 2, 3, 4});
}

Expand Down
20 changes: 11 additions & 9 deletions src/test/java/io/tiledb/java/api/FragmentsConsolidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public void arrayWrite2() throws Exception {

public void arrayWrite3() throws Exception {
// Prepare cell buffers
NativeArray rows = new NativeArray(ctx, new int[] {1, 3}, Integer.class);
NativeArray cols = new NativeArray(ctx, new int[] {1, 4}, Integer.class);
NativeArray data = new NativeArray(ctx, new int[] {201, 202}, Integer.class);

NativeArray coords = new NativeArray(ctx, new int[] {1, 1, 3, 4}, Integer.class);
Expand All @@ -120,8 +122,9 @@ public void arrayWrite3() throws Exception {
Array array = new Array(ctx, arrayURI, TILEDB_WRITE);
Query query = new Query(array);
query.setLayout(TILEDB_UNORDERED);
query.setBuffer("rows", rows);
query.setBuffer("cols", cols);
query.setBuffer("a", data);
query.setCoordinates(coords);
// Submit query
query.submit();
query.close();
Expand All @@ -140,24 +143,23 @@ private void arrayRead() throws Exception {
query.setLayout(TILEDB_ROW_MAJOR);
query.setSubarray(subarray);
query.setBuffer("a", new NativeArray(ctx, 16, Integer.class));
query.setCoordinates(new NativeArray(ctx, 32, Integer.class));
query.setBuffer("rows", new NativeArray(ctx, 16, Integer.class));
query.setBuffer("cols", new NativeArray(ctx, 16, Integer.class));

// Submit query
query.submit();
// Print cell values (assumes all getAttributes are read)
HashMap<String, Pair<Long, Long>> result_el = query.resultBufferElements();

int[] rows = (int[]) query.getBuffer("rows");
int[] cols = (int[]) query.getBuffer("cols");
int[] data = (int[]) query.getBuffer("a");
int[] coords = (int[]) query.getCoordinates();
query.close();
array.close();

Assert.assertArrayEquals(
coords,
new int[] {
1, 1, 1, 2, 1, 3, 1, 4, 2, 1, 2, 2, 2, 3, 2, 4, 3, 1, 3, 2, 3, 3, 3, 4, 4, 1, 4, 2, 4, 3,
4, 4
});
Assert.assertArrayEquals(rows, new int[] {1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4});
Assert.assertArrayEquals(cols, new int[] {1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4});

Assert.assertArrayEquals(
data,
new int[] {
Expand Down
141 changes: 141 additions & 0 deletions src/test/java/io/tiledb/java/api/HeterogeneousSparseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020 TileDB, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.tiledb.java.api;

import static io.tiledb.java.api.ArrayType.TILEDB_SPARSE;
import static io.tiledb.java.api.Layout.TILEDB_GLOBAL_ORDER;
import static io.tiledb.java.api.Layout.TILEDB_ROW_MAJOR;
import static io.tiledb.java.api.QueryType.TILEDB_READ;
import static io.tiledb.java.api.QueryType.TILEDB_WRITE;

import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

@SuppressWarnings("ALL")
public class HeterogeneousSparseTest {

private Context ctx;
private String arrayURI = "my_sparse_array";

@Before
public void setup() throws Exception {
ctx = new Context();
if (Files.exists(Paths.get(arrayURI))) {
TileDBObject.remove(ctx, arrayURI);
}
}

@After
public void teardown() throws Exception {
if (Files.exists(Paths.get(arrayURI))) {
TileDBObject.remove(ctx, arrayURI);
}
}

@Test
public void testQuickstartSparse() throws Exception {
arrayCreate();
arrayWrite();
arrayRead();
}

public void arrayCreate() throws Exception {
Dimension d1 = new Dimension(ctx, "d1", Datatype.TILEDB_STRING_ASCII, null, null);
Dimension d2 = new Dimension(ctx, "d2", Datatype.TILEDB_INT32, new Pair(0, 100), 2);

// Create and set getDomain
Domain domain = new Domain(ctx);
domain.addDimension(d1).addDimension(d2);

// Add two attributes "a1" and "a2", so each (i,j) cell can store
// a character on "a1" and a vector of two floats on "a2".
Attribute a1 = new Attribute(ctx, "a1", Integer.class);

ArraySchema schema = new ArraySchema(ctx, TILEDB_SPARSE);
schema.setTileOrder(TILEDB_ROW_MAJOR);
schema.setCellOrder(TILEDB_ROW_MAJOR);
schema.setDomain(domain);
schema.addAttribute(a1);

Array.create(arrayURI, schema);
}

public void arrayWrite() throws Exception {
NativeArray d1_data = new NativeArray(ctx, "aabbccddee", Datatype.TILEDB_STRING_ASCII);
NativeArray d1_off = new NativeArray(ctx, new long[] {0, 2, 4, 6, 8}, Datatype.TILEDB_UINT64);
NativeArray d2_data = new NativeArray(ctx, new int[] {1, 4, 9, 10, 12}, Datatype.TILEDB_INT32);

// Prepare cell buffers
NativeArray a1 = new NativeArray(ctx, new int[] {1, 2, 3, 4, 5}, Integer.class);

// Create query
Array array = new Array(ctx, arrayURI, TILEDB_WRITE);
Query query = new Query(array);
query.setLayout(TILEDB_GLOBAL_ORDER);

query.setBuffer("d1", d1_off, d1_data);
query.setBuffer("d2", d2_data);
query.setBuffer("a1", a1);

// Submit query
query.submit();

query.finalizeQuery();
query.close();
array.close();
}

private void arrayRead() throws Exception {
NativeArray d_data = new NativeArray(ctx, 20, Datatype.TILEDB_STRING_ASCII);
NativeArray d_off = new NativeArray(ctx, 20, Datatype.TILEDB_UINT64);

NativeArray d2_data = new NativeArray(ctx, 20, Datatype.TILEDB_INT32);

Query q = new Query(new Array(ctx, arrayURI), TILEDB_READ);
q.setLayout(TILEDB_GLOBAL_ORDER);

q.setBuffer("d1", d_off, d_data);
q.setBuffer("d2", d2_data);

q.addRangeVar(0, "a", "z");

q.submit();

byte[] data = (byte[]) q.getBuffer("d1");
long[] offsets = q.getVarBuffer("d1");
int[] d2 = (int[]) q.getBuffer("d2");

String[] results = new String[offsets.length];

results = Util.bytesToStrings(offsets, data);

Assert.assertArrayEquals(results, new String[] {"aa", "bb", "cc", "dd", "ee"});
Assert.assertArrayEquals(d2, new int[] {1, 4, 9, 10, 12});
}
}
Loading