1
1
package io .tiledb .java .api ;
2
2
3
3
import static io .tiledb .java .api .ArrayType .TILEDB_DENSE ;
4
+ import static io .tiledb .java .api .ArrayType .TILEDB_SPARSE ;
4
5
import static io .tiledb .java .api .Constants .TILEDB_VAR_NUM ;
5
6
import static io .tiledb .java .api .Layout .TILEDB_ROW_MAJOR ;
6
7
import static io .tiledb .java .api .QueryType .TILEDB_READ ;
@@ -110,59 +111,154 @@ private List<Datatype> allDatatypes() {
110
111
public void testEnumeratedDatatype () throws Exception {
111
112
// test api
112
113
Dimension <Integer > rows =
113
- new Dimension <>(ctx , "rows" , Integer . class , new Pair <Integer , Integer >(1 , 4 ), 2 );
114
+ new Dimension <>(ctx , "rows" , Datatype . TILEDB_INT32 , new Pair <Integer , Integer >(1 , 100 ), 2 );
114
115
115
116
Domain domain = new Domain (ctx );
116
117
domain .addDimension (rows );
117
118
119
+ Attribute a0 = new Attribute (ctx , "a0" , Datatype .TILEDB_INT16 );
118
120
Attribute a1 = new Attribute (ctx , "a1" , Datatype .TILEDB_INT32 );
121
+ Attribute a2 = new Attribute (ctx , "a2" , Datatype .TILEDB_INT64 );
122
+ Attribute a3 = new Attribute (ctx , "a3" , Datatype .TILEDB_INT32 );
119
123
120
- ArraySchema schema = new ArraySchema (ctx , TILEDB_DENSE );
124
+ ArraySchema schema = new ArraySchema (ctx , TILEDB_SPARSE );
121
125
schema .setTileOrder (TILEDB_ROW_MAJOR );
122
126
schema .setCellOrder (TILEDB_ROW_MAJOR );
123
127
schema .setDomain (domain );
124
128
129
+ NativeArray enumsOffsetsa0 =
130
+ new NativeArray (ctx , new long [] {0 , 2 , 4 , 6 }, Datatype .TILEDB_UINT64 );
131
+ NativeArray enumsa0 = new NativeArray (ctx , "eeffgghh" , Datatype .TILEDB_STRING_ASCII );
132
+
133
+ Enumeration ena0 =
134
+ new Enumeration (
135
+ ctx ,
136
+ "a0_enum" ,
137
+ TILEDB_VAR_NUM ,
138
+ Datatype .TILEDB_STRING_ASCII ,
139
+ false ,
140
+ enumsa0 ,
141
+ BigInteger .valueOf (enumsa0 .getSize () * Datatype .TILEDB_STRING_ASCII .getNativeSize ()),
142
+ enumsOffsetsa0 ,
143
+ BigInteger .valueOf (enumsOffsetsa0 .getSize () * Datatype .TILEDB_UINT64 .getNativeSize ()));
144
+
145
+ schema .addEnumeration (ena0 );
146
+
125
147
NativeArray enumsOffsets =
126
148
new NativeArray (ctx , new long [] {0 , 2 , 4 , 6 }, Datatype .TILEDB_UINT64 );
127
149
NativeArray enums = new NativeArray (ctx , "aabbccdd" , Datatype .TILEDB_STRING_ASCII );
128
150
129
151
Enumeration en =
130
152
new Enumeration (
131
153
ctx ,
132
- "test_enum " ,
154
+ "a1_enum " ,
133
155
TILEDB_VAR_NUM ,
134
- Datatype .TILEDB_INT32 ,
156
+ Datatype .TILEDB_STRING_ASCII ,
135
157
false ,
136
158
enums ,
137
159
BigInteger .valueOf (enums .getSize () * Datatype .TILEDB_STRING_ASCII .getNativeSize ()),
138
160
enumsOffsets ,
139
161
BigInteger .valueOf (enumsOffsets .getSize () * Datatype .TILEDB_UINT64 .getNativeSize ()));
140
162
141
163
schema .addEnumeration (en );
142
- a1 .setEnumerationName ("test_enum" );
143
164
165
+ NativeArray enumsOffsetsa2 =
166
+ new NativeArray (ctx , new long [] {0 , 2 , 4 , 6 }, Datatype .TILEDB_UINT64 );
167
+ NativeArray enumsa2 = new NativeArray (ctx , "iijjkkll" , Datatype .TILEDB_STRING_ASCII );
168
+
169
+ Enumeration ena2 =
170
+ new Enumeration (
171
+ ctx ,
172
+ "a2_enum" ,
173
+ TILEDB_VAR_NUM ,
174
+ Datatype .TILEDB_STRING_ASCII ,
175
+ false ,
176
+ enumsa2 ,
177
+ BigInteger .valueOf (enumsa2 .getSize () * Datatype .TILEDB_STRING_ASCII .getNativeSize ()),
178
+ enumsOffsetsa2 ,
179
+ BigInteger .valueOf (enumsOffsetsa2 .getSize () * Datatype .TILEDB_UINT64 .getNativeSize ()));
180
+
181
+ schema .addEnumeration (ena2 );
182
+
183
+ NativeArray enumsa3 =
184
+ new NativeArray (ctx , new int [] {1000 , 2000 , 3000 , 4000 }, Datatype .TILEDB_INT32 );
185
+
186
+ Enumeration ena3 =
187
+ new Enumeration (
188
+ ctx ,
189
+ "a3_enum" ,
190
+ 1 ,
191
+ Datatype .TILEDB_INT32 ,
192
+ false ,
193
+ enumsa3 ,
194
+ BigInteger .valueOf (enumsa3 .getSize () * Datatype .TILEDB_INT32 .getNativeSize ()),
195
+ null ,
196
+ BigInteger .ZERO );
197
+
198
+ schema .addEnumeration (ena3 );
199
+
200
+ a0 .setEnumerationName ("a0_enum" );
201
+ a1 .setEnumerationName ("a1_enum" );
202
+ a2 .setEnumerationName ("a2_enum" );
203
+ a3 .setEnumerationName ("a3_enum" );
204
+
205
+ schema .addAttribute (a0 );
144
206
schema .addAttribute (a1 );
207
+ schema .addAttribute (a2 );
208
+ schema .addAttribute (a3 );
145
209
146
210
Array .create (arrayURI , schema );
147
211
148
212
Array array = new Array (ctx , arrayURI );
149
213
String attGetEnumName = array .getSchema ().getAttribute ("a1" ).getEnumerationName ();
150
- Assert .assertEquals ("test_enum" , attGetEnumName );
214
+ Assert .assertEquals ("a1_enum" , attGetEnumName );
215
+ attGetEnumName = array .getSchema ().getAttribute ("a0" ).getEnumerationName ();
216
+ Assert .assertEquals ("a0_enum" , attGetEnumName );
217
+ attGetEnumName = array .getSchema ().getAttribute ("a2" ).getEnumerationName ();
218
+ Assert .assertEquals ("a2_enum" , attGetEnumName );
219
+ attGetEnumName = array .getSchema ().getAttribute ("a3" ).getEnumerationName ();
220
+ Assert .assertEquals ("a3_enum" , attGetEnumName );
221
+
222
+ Enumeration e = array .getEnumeration ("a0_enum" );
223
+ Assert .assertEquals ("a0_enum" , e .getName ());
224
+ Assert .assertEquals (Datatype .TILEDB_STRING_ASCII , e .getType ());
225
+ Assert .assertFalse (e .getOrdered ());
226
+ Assert .assertEquals ("eeffgghh" , new String ((byte []) e .getData ()));
151
227
152
- Enumeration e = array .getEnumeration ("test_enum" );
228
+ e = array .getEnumeration ("a1_enum" );
229
+ Assert .assertEquals ("a1_enum" , e .getName ());
230
+ Assert .assertEquals (Datatype .TILEDB_STRING_ASCII , e .getType ());
231
+ Assert .assertFalse (e .getOrdered ());
232
+ Assert .assertEquals ("aabbccdd" , new String ((byte []) e .getData ()));
233
+
234
+ e = array .getEnumeration ("a2_enum" );
235
+ Assert .assertEquals ("a2_enum" , e .getName ());
236
+ Assert .assertEquals (Datatype .TILEDB_STRING_ASCII , e .getType ());
237
+ Assert .assertFalse (e .getOrdered ());
238
+ Assert .assertEquals ("iijjkkll" , new String ((byte []) e .getData ()));
153
239
154
- Assert .assertEquals ("test_enum" , e .getName ());
240
+ e = array .getEnumeration ("a3_enum" );
241
+ Assert .assertEquals ("a3_enum" , e .getName ());
155
242
Assert .assertEquals (Datatype .TILEDB_INT32 , e .getType ());
156
243
Assert .assertFalse (e .getOrdered ());
157
- // Assert.assertArrayEquals(new int[] {0, 1, 2, 3}, (int[]) e.getData());
244
+ Assert .assertArrayEquals (new int [] {1000 , 2000 , 3000 , 4000 }, (int []) e .getData ());
245
+
158
246
array .close ();
159
247
160
248
// test data write
161
- NativeArray na1 = new NativeArray (ctx , new int [] {0 , 1 , 2 , 0 }, Datatype .TILEDB_INT32 );
249
+ NativeArray ndim = new NativeArray (ctx , new int [] {10 , 20 , 30 , 40 }, Datatype .TILEDB_INT32 );
250
+ NativeArray na0 = new NativeArray (ctx , new short [] {1 , 2 , 3 , 4 }, Datatype .TILEDB_INT16 );
251
+ NativeArray na1 = new NativeArray (ctx , new int [] {1 , 2 , 3 , 4 }, Datatype .TILEDB_INT32 );
252
+ NativeArray na2 = new NativeArray (ctx , new long [] {1 , 2 , 3 , 4 }, Datatype .TILEDB_INT64 );
253
+ NativeArray na3 = new NativeArray (ctx , new int [] {1 , 2 , 3 , 4 }, Datatype .TILEDB_INT32 );
162
254
array = new Array (ctx , arrayURI , TILEDB_WRITE );
163
255
Query query = new Query (array , TILEDB_WRITE );
164
256
257
+ query .setDataBuffer ("rows" , ndim );
258
+ query .setDataBuffer ("a0" , na0 );
165
259
query .setDataBuffer ("a1" , na1 );
260
+ query .setDataBuffer ("a2" , na2 );
261
+ query .setDataBuffer ("a3" , na3 );
166
262
query .submit ();
167
263
168
264
query .close ();
@@ -172,48 +268,45 @@ public void testEnumeratedDatatype() throws Exception {
172
268
array = new Array (ctx , arrayURI , TILEDB_READ );
173
269
query = new Query (array , TILEDB_READ );
174
270
SubArray sub = new SubArray (ctx , array );
175
- sub .addRange (0 , 1 , 4 , null );
271
+ sub .addRange (0 , 1 , 100 , null );
176
272
query .setSubarray (sub );
177
273
query .setDataBuffer ("a1" , new NativeArray (ctx , 4 , Datatype .TILEDB_INT32 ));
178
274
query .submit ();
179
275
180
276
int [] a1Result = (int []) query .getBuffer ("a1" );
181
- Assert .assertArrayEquals (new int [] {0 , 1 , 2 , 0 }, a1Result );
277
+ Assert .assertArrayEquals (new int [] {1 , 2 , 3 , 4 }, a1Result );
182
278
183
279
// test data read with QC
184
280
query = new Query (array , TILEDB_READ );
185
281
query .setSubarray (sub );
186
282
QueryCondition qc =
187
- new QueryCondition (ctx , Datatype .TILEDB_STRING_ASCII , "a1" , "aa " , TILEDB_EQ );
283
+ new QueryCondition (ctx , Datatype .TILEDB_STRING_ASCII , "a1" , "bb " , TILEDB_EQ );
188
284
query .setCondition (qc );
189
285
query .setDataBuffer ("a1" , new NativeArray (ctx , 4 , Datatype .TILEDB_INT32 ));
190
286
query .submit ();
191
287
int [] a1ResultAfterQC = (int []) query .getBuffer ("a1" );
192
- Assert .assertArrayEquals (
193
- new int [] {0 , Integer .MIN_VALUE , Integer .MIN_VALUE , 0 }, a1ResultAfterQC );
288
+ Assert .assertArrayEquals (new int [] {1 }, a1ResultAfterQC );
194
289
195
290
// test Schema evolution
196
- // ArraySchemaEvolution evolution = new ArraySchemaEvolution(ctx);
197
- // Enumeration en2 =
198
- // new Enumeration(
199
- // ctx,
200
- // "test_enum2",
201
- // TILEDB_VAR_NUM,
202
- // Datatype.TILEDB_INT32,
203
- // false,
204
- // enums,
205
- // BigInteger.valueOf(enums.getSize() *
206
- // Datatype.TILEDB_STRING_ASCII.getNativeSize()),
207
- // enumsOffsets,
208
- // BigInteger.valueOf(enumsOffsets.getSize() *
209
- // Datatype.TILEDB_UINT64.getNativeSize()));
210
- // evolution.addEnumeration(en2);
211
- // evolution.evolveArray(arrayURI);
212
- //
213
- // // reopen array
214
- // array = new Array(ctx, arrayURI);
215
- // e = array.getEnumeration("test_enum2");
216
- // Assert.assertEquals(e.getName(), "test_enum2");
291
+ ArraySchemaEvolution evolution = new ArraySchemaEvolution (ctx );
292
+ Enumeration en2 =
293
+ new Enumeration (
294
+ ctx ,
295
+ "test_enum2" ,
296
+ TILEDB_VAR_NUM ,
297
+ Datatype .TILEDB_INT32 ,
298
+ false ,
299
+ enums ,
300
+ BigInteger .valueOf (enums .getSize () * Datatype .TILEDB_STRING_ASCII .getNativeSize ()),
301
+ enumsOffsets ,
302
+ BigInteger .valueOf (enumsOffsets .getSize () * Datatype .TILEDB_UINT64 .getNativeSize ()));
303
+ evolution .addEnumeration (en2 );
304
+ evolution .evolveArray (arrayURI );
305
+
306
+ // reopen array
307
+ array = new Array (ctx , arrayURI );
308
+ e = array .getEnumeration ("test_enum2" );
309
+ Assert .assertEquals (e .getName (), "test_enum2" );
217
310
}
218
311
219
312
public void arrayCreate () throws Exception {
0 commit comments