Skip to content

Commit db0ddd1

Browse files
adding new Query Condition constructor and deprecating old one
1 parent 0302ba1 commit db0ddd1

File tree

3 files changed

+66
-10
lines changed

3 files changed

+66
-10
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
}
1010

1111
group 'io.tiledb'
12-
version '0.17.6-SNAPSHOT'
12+
version '0.17.8-SNAPSHOT'
1313

1414
repositories {
1515
jcenter()

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public QueryCondition(Context ctx, SWIGTYPE_p_p_tiledb_query_condition_t conditi
3939
this.conditionpp = conditionpp;
4040
}
4141

42+
@Deprecated
43+
/** Use new constructor instead. */
4244
public QueryCondition(
4345
Context ctx,
4446
String attributeName,
@@ -84,6 +86,58 @@ public QueryCondition(
8486
this.ctx = ctx;
8587
}
8688

89+
/**
90+
* Constructor
91+
*
92+
* @param ctx The context
93+
* @param attributeName The name of the field this operation applies to
94+
* @param type The datatype
95+
* @param value The value to compare to
96+
* @param OP The relational operation between the value of the field and `condition_value`
97+
* @throws TileDBError
98+
*/
99+
public QueryCondition(
100+
Context ctx,
101+
String attributeName,
102+
Datatype type,
103+
Object value,
104+
tiledb_query_condition_op_t OP)
105+
throws TileDBError {
106+
try {
107+
conditionpp = tiledb.new_tiledb_query_condition_tpp();
108+
ctx.handleError(tiledb.tiledb_query_condition_alloc(ctx.getCtxp(), conditionpp));
109+
NativeArray array = null;
110+
if (value.getClass().isArray()) {
111+
array = new NativeArray(ctx, value, type.javaClass());
112+
} else {
113+
if (type != null) {
114+
int byteSize = type.getNativeSize();
115+
array = new NativeArray(ctx, byteSize, type);
116+
array.setItem(0, value);
117+
}
118+
}
119+
conditionp = tiledb.tiledb_query_condition_tpp_value(conditionpp);
120+
if (type == null) {
121+
ctx.handleError(
122+
tiledb.tiledb_query_condition_init(
123+
ctx.getCtxp(), conditionp, attributeName, null, BigInteger.valueOf(0), OP));
124+
} else {
125+
ctx.handleError(
126+
tiledb.tiledb_query_condition_init(
127+
ctx.getCtxp(),
128+
conditionp,
129+
attributeName,
130+
array.toVoidPointer(),
131+
BigInteger.valueOf(array.getSize()),
132+
OP));
133+
}
134+
} catch (TileDBError err) {
135+
tiledb.delete_tiledb_query_condition_tpp(conditionpp);
136+
throw err;
137+
}
138+
this.ctx = ctx;
139+
}
140+
87141
public SWIGTYPE_p_tiledb_query_condition_t getConditionp() {
88142
return this.conditionp;
89143
}

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
package io.tiledb.java.api;
2626

2727
import static io.tiledb.java.api.ArrayType.*;
28+
import static io.tiledb.java.api.Datatype.TILEDB_FLOAT32;
29+
import static io.tiledb.java.api.Datatype.TILEDB_INT32;
2830
import static io.tiledb.java.api.Datatype.TILEDB_UINT8;
2931
import static io.tiledb.java.api.Layout.*;
3032
import static io.tiledb.java.api.QueryType.*;
@@ -114,9 +116,9 @@ public void arrayCreate() throws Exception {
114116
domain.addDimension(d2);
115117

116118
// Create and add getAttributes
117-
Attribute a1 = new Attribute(ctx, "a1", Integer.class);
119+
Attribute a1 = new Attribute(ctx, "a1", TILEDB_INT32);
118120
a1.setNullable(true);
119-
Attribute a2 = new Attribute(ctx, "a2", Float.class);
121+
Attribute a2 = new Attribute(ctx, "a2", TILEDB_FLOAT32);
120122

121123
ArraySchema schema = new ArraySchema(ctx, TILEDB_DENSE);
122124
schema.setTileOrder(TILEDB_ROW_MAJOR);
@@ -136,13 +138,13 @@ public void arrayWrite() throws Exception {
136138

137139
// Prepare cell buffers
138140
NativeArray a1_data =
139-
new NativeArray(ctx, new int[] {8, 9, 10, 11, 12, 13, 14, 15, 16}, Integer.class);
141+
new NativeArray(ctx, new int[] {8, 9, 10, 11, 12, 13, 14, 15, 16}, TILEDB_INT32);
140142

141143
NativeArray buffer_a2 =
142144
new NativeArray(
143145
ctx,
144146
new float[] {13.2f, 14.1f, 14.2f, 15.1f, 15.2f, 15.3f, 16.1f, 18.3f, 19.1f},
145-
Float.class);
147+
TILEDB_FLOAT32);
146148

147149
// Create query
148150
NativeArray a1Bytemap =
@@ -176,15 +178,15 @@ private void arrayRead() throws Exception {
176178
max_sizes.put("a2", new Pair<>(0L, query.getEstResultSize(ctx, "a2")));
177179
query.setBufferNullable(
178180
"a1",
179-
new NativeArray(ctx, max_sizes.get("a1").getSecond().intValue(), Integer.class),
181+
new NativeArray(ctx, max_sizes.get("a1").getSecond().intValue(), TILEDB_INT32),
180182
new NativeArray(ctx, 16, TILEDB_UINT8));
181183
query.setBuffer(
182184
"a2", new NativeArray(ctx, max_sizes.get("a2").getSecond().intValue(), Float.class));
183185
// null + normal + combined condition test
184-
QueryCondition con1 = new QueryCondition(ctx, "a2", 15.0f, Float.class, TILEDB_GT);
185-
QueryCondition con2 = new QueryCondition(ctx, "a1", 0, null, TILEDB_EQ);
186+
QueryCondition con1 = new QueryCondition(ctx, "a2", TILEDB_FLOAT32, 15.0f, TILEDB_GT);
187+
QueryCondition con2 = new QueryCondition(ctx, "a1", null, 0, TILEDB_EQ);
186188
QueryCondition con3 = con1.combine(con2, TILEDB_AND);
187-
QueryCondition con4 = new QueryCondition(ctx, "a1", 9, Integer.class, TILEDB_EQ);
189+
QueryCondition con4 = new QueryCondition(ctx, "a1", TILEDB_INT32, 9, TILEDB_EQ);
188190
QueryCondition con5 = con4.combine(con3, TILEDB_OR);
189191
query.setCondition(con5);
190192

@@ -237,7 +239,7 @@ public void testDataDeletion() throws TileDBError {
237239
// delete data with appropriate QC
238240
Array array = new Array(ctx, arrayURISparse, TILEDB_DELETE);
239241
Query query = new Query(array, TILEDB_DELETE);
240-
QueryCondition deleteQc = new QueryCondition(ctx, "a1", 3, Integer.class, TILEDB_GT);
242+
QueryCondition deleteQc = new QueryCondition(ctx, "a1", TILEDB_INT32, 3, TILEDB_GT);
241243
query.setCondition(deleteQc);
242244
query.submit();
243245
// close resources

0 commit comments

Comments
 (0)