Skip to content

Commit b9fe0d3

Browse files
Add support for Dictionary and CheckSum* filters
1 parent 43b2646 commit b9fe0d3

File tree

6 files changed

+183
-0
lines changed

6 files changed

+183
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.tiledb.java.api;
2+
3+
import io.tiledb.libtiledb.SWIGTYPE_p_p_tiledb_filter_t;
4+
import io.tiledb.libtiledb.tiledb_filter_type_t;
5+
6+
public class CheckSumMD5Filter extends Filter {
7+
public CheckSumMD5Filter(Context ctx) throws TileDBError {
8+
super(ctx, tiledb_filter_type_t.TILEDB_FILTER_CHECKSUM_MD5);
9+
}
10+
11+
protected CheckSumMD5Filter(Context ctx, SWIGTYPE_p_p_tiledb_filter_t filterpp) {
12+
super(ctx, filterpp);
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.tiledb.java.api;
2+
3+
import io.tiledb.libtiledb.SWIGTYPE_p_p_tiledb_filter_t;
4+
import io.tiledb.libtiledb.tiledb_filter_type_t;
5+
6+
public class CheckSumSHA256Filter extends Filter {
7+
public CheckSumSHA256Filter(Context ctx) throws TileDBError {
8+
super(ctx, tiledb_filter_type_t.TILEDB_FILTER_CHECKSUM_SHA256);
9+
}
10+
11+
protected CheckSumSHA256Filter(Context ctx, SWIGTYPE_p_p_tiledb_filter_t filterpp) {
12+
super(ctx, filterpp);
13+
}
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.tiledb.java.api;
2+
3+
import io.tiledb.libtiledb.SWIGTYPE_p_p_tiledb_filter_t;
4+
import io.tiledb.libtiledb.tiledb_filter_type_t;
5+
6+
public class DictionaryFilter extends CompressionFilter {
7+
public DictionaryFilter(Context ctx) throws TileDBError {
8+
super(ctx, tiledb_filter_type_t.TILEDB_FILTER_DICTIONARY);
9+
}
10+
11+
public DictionaryFilter(Context ctx, int level) throws TileDBError {
12+
super(ctx, tiledb_filter_type_t.TILEDB_FILTER_DICTIONARY, level);
13+
}
14+
15+
protected DictionaryFilter(Context ctx, SWIGTYPE_p_p_tiledb_filter_t filterpp) {
16+
super(ctx, filterpp);
17+
}
18+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ public Filter getFilter(long idx) throws TileDBError {
8484
return new BitWidthReductionFilter(this.ctx, _filterpp);
8585
case TILEDB_FILTER_POSITIVE_DELTA:
8686
return new PositiveDeltaFilter(this.ctx, _filterpp);
87+
case TILEDB_FILTER_CHECKSUM_MD5:
88+
return new CheckSumMD5Filter(this.ctx, _filterpp);
89+
case TILEDB_FILTER_CHECKSUM_SHA256:
90+
return new CheckSumSHA256Filter(this.ctx, _filterpp);
91+
case TILEDB_FILTER_DICTIONARY:
92+
return new DictionaryFilter(this.ctx, _filterpp);
8793
default:
8894
{
8995
tiledb.delete_tiledb_filter_tpp(_filterpp);

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

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
package io.tiledb.java.api;
22

3+
import static io.tiledb.java.api.ArrayType.TILEDB_DENSE;
4+
import static io.tiledb.java.api.Layout.TILEDB_GLOBAL_ORDER;
5+
import static io.tiledb.java.api.Layout.TILEDB_ROW_MAJOR;
6+
import static io.tiledb.java.api.QueryType.TILEDB_READ;
7+
import static io.tiledb.java.api.QueryType.TILEDB_WRITE;
8+
9+
import java.nio.file.Files;
10+
import java.nio.file.Paths;
11+
import org.junit.After;
312
import org.junit.Assert;
13+
import org.junit.Before;
414
import org.junit.Test;
515

616
public class FilterTest {
17+
private Context ctx;
18+
private String arrayURI;
19+
20+
@Before
21+
public void before() throws TileDBError {
22+
this.ctx = new Context();
23+
this.arrayURI = "dict_filter_array";
24+
if (Files.exists(Paths.get(arrayURI))) {
25+
TileDBObject.remove(ctx, arrayURI);
26+
}
27+
}
28+
29+
@After
30+
public void after() throws TileDBError {
31+
if (Files.exists(Paths.get(arrayURI))) {
32+
TileDBObject.remove(ctx, arrayURI);
33+
}
34+
}
735

836
@Test
937
public void testNoneFiler() throws Exception {
@@ -120,4 +148,105 @@ public void testPositiveDeltaFilter() throws Exception {
120148
}
121149
}
122150
}
151+
152+
@Test
153+
public void testCheckSumMD5() throws Exception {
154+
try (Context ctx = new Context();
155+
CheckSumMD5Filter filter = new CheckSumMD5Filter(ctx)) {}
156+
}
157+
158+
@Test
159+
public void testCheckSumSHA256() throws Exception {
160+
try (Context ctx = new Context();
161+
CheckSumSHA256Filter filter = new CheckSumSHA256Filter(ctx)) {}
162+
}
163+
164+
@Test
165+
public void testDictionaryFilter() throws Exception {
166+
try (Context ctx = new Context()) {
167+
try (DictionaryFilter filter = new DictionaryFilter(ctx, 5)) {
168+
Assert.assertEquals(filter.getLevel(), 5);
169+
}
170+
try (DictionaryFilter filter = new DictionaryFilter(ctx)) {
171+
Assert.assertEquals(filter.getLevel(), -1);
172+
}
173+
}
174+
}
175+
176+
public void arrayCreate() throws TileDBError {
177+
Dimension<Integer> d1 =
178+
new Dimension<Integer>(ctx, "d1", Datatype.TILEDB_INT32, new Pair<>(0, 5), 1);
179+
180+
// Create and set getDomain
181+
Domain domain = new Domain(ctx);
182+
domain.addDimension(d1);
183+
184+
Attribute a1 = new Attribute(ctx, "a1", Datatype.TILEDB_STRING_ASCII);
185+
a1.setCellVar();
186+
// add dictionary filter to variable length string attribute
187+
a1.setFilterList(new FilterList(ctx).addFilter(new DictionaryFilter(ctx)));
188+
189+
ArraySchema schema = new ArraySchema(ctx, TILEDB_DENSE);
190+
schema.setTileOrder(TILEDB_ROW_MAJOR);
191+
schema.setCellOrder(TILEDB_ROW_MAJOR);
192+
schema.setDomain(domain);
193+
schema.addAttribute(a1);
194+
195+
Array.create(arrayURI, schema);
196+
}
197+
198+
public void arrayWrite() throws TileDBError {
199+
200+
NativeArray a1_data =
201+
new NativeArray(
202+
ctx, "foo" + "foo" + "foobar" + "bar" + "bar" + "bar", Datatype.TILEDB_STRING_ASCII);
203+
NativeArray a1_off =
204+
new NativeArray(ctx, new long[] {0, 3, 6, 12, 15, 18}, Datatype.TILEDB_UINT64);
205+
206+
// Create query
207+
Array array = new Array(ctx, arrayURI, TILEDB_WRITE);
208+
Query query = new Query(array);
209+
query.setLayout(TILEDB_GLOBAL_ORDER);
210+
211+
query.setBuffer("a1", a1_off, a1_data);
212+
213+
// Submit query
214+
query.submit();
215+
216+
query.finalizeQuery();
217+
query.close();
218+
array.close();
219+
}
220+
221+
@Test
222+
public void testDictionaryFilterWithData() throws TileDBError {
223+
arrayCreate();
224+
arrayWrite();
225+
226+
NativeArray subarray = new NativeArray(ctx, new int[] {0, 5}, Integer.class);
227+
// Create array and query
228+
try (Array array = new Array(ctx, arrayURI, TILEDB_READ);
229+
ArraySchema schema = array.getSchema();
230+
Query query = new Query(array, TILEDB_READ)) {
231+
232+
query.setSubarray(subarray);
233+
234+
query.setLayout(TILEDB_ROW_MAJOR);
235+
236+
NativeArray a1Data = new NativeArray(ctx, 100, Datatype.TILEDB_STRING_ASCII);
237+
NativeArray a1Offsets = new NativeArray(ctx, 100, Datatype.TILEDB_UINT64);
238+
239+
query.setBuffer("a1", a1Offsets, a1Data);
240+
241+
// Submit query
242+
query.submit();
243+
244+
long[] a1_offsets = (long[]) query.getVarBuffer("a1");
245+
byte[] a1_data = (byte[]) query.getBuffer("a1");
246+
247+
Assert.assertArrayEquals(a1_offsets, new long[] {0, 3, 6, 12, 15, 18});
248+
String[] results = Util.bytesToStrings(a1_offsets, a1_data);
249+
Assert.assertArrayEquals(new String[] {"foo", "foo", "foobar", "bar", "bar", "bar"}, results);
250+
}
251+
}
123252
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public void arrayCreate() throws Exception {
5656
// a character on "a1" and a vector of two floats on "a2".
5757
Attribute a1 = new Attribute(ctx, "a1", Character.class);
5858
Attribute a2 = new Attribute(ctx, "a2", Float.class);
59+
a1.setFilterList(new FilterList(ctx).addFilter(new CheckSumMD5Filter(ctx)));
60+
a2.setFilterList(new FilterList(ctx).addFilter(new CheckSumSHA256Filter(ctx)));
5961
a2.setCellValNum(2);
6062

6163
ArraySchema schema = new ArraySchema(ctx, TILEDB_DENSE);

0 commit comments

Comments
 (0)