3
3
// Import classes:
4
4
import io .tiledb .cloud .TileDBClient ;
5
5
import io .tiledb .cloud .TileDBUDF ;
6
- import io .tiledb .cloud .rest_api .ApiClient ;
7
6
import io .tiledb .cloud .rest_api .ApiException ;
8
7
import io .tiledb .cloud .TileDBLogin ;
9
8
import io .tiledb .cloud .rest_api .api .GroupsApi ;
16
15
import java .util .HashMap ;
17
16
import java .util .List ;
18
17
18
+ import static io .tiledb .cloud .TileDBUtils .serializeArgs ;
19
+
19
20
public class Examples
20
21
{
21
22
public static void main (String [] args ) {
@@ -33,19 +34,18 @@ public static void main(String[] args) {
33
34
// to pass any credentials from now on. Just create the client as follows:
34
35
// TileDBClient tileDBClient = new TileDBClient();
35
36
36
- ArrayApi apiInstance = new ArrayApi (tileDBClient .getApiClient ());
37
37
38
38
// Uncomment to run whichever example you want
39
39
// runGenericUDF(tileDBClient);
40
40
// runArrayUDF(tileDBClient);
41
41
// runMultiArrayUDF(tileDBClient);
42
- // getArraySchema(apiInstance );
43
- // createArray(apiInstance );
44
- // registerArray(apiInstance );
45
- // listArrays(apiInstance );
46
- // listGroups(defaultClient );
47
- // deleteArray(apiInstance );
48
- // deregisterArray(apiInstance );
42
+ // getArraySchema(tileDBClient );
43
+ // createArray(tileDBClient );
44
+ // registerArray(tileDBClient );
45
+ // listArrays(tileDBClient );
46
+ // listGroups(tileDBClient );
47
+ // deleteArray(tileDBClient );
48
+ // deregisterArray(tileDBClient );
49
49
}
50
50
51
51
/**
@@ -59,11 +59,12 @@ private static void runGenericUDF(TileDBClient tileDBClient){
59
59
HashMap <String ,Object > arguments = new HashMap <>();
60
60
arguments .put ("arg1" , "a1" );
61
61
arguments .put ("arg2" , "a2" );
62
- System .out .println (tileDBUDF .executeGeneric (genericUDF , arguments )); //could be JSON or Arrow
62
+ genericUDF .setArgument (serializeArgs (arguments ));
63
+ System .out .println (tileDBUDF .executeGeneric (genericUDF )); //could be JSON or Arrow
63
64
}
64
65
65
66
/**
66
- * Runs an array UDF on a TileDB Arrray
67
+ * Runs an array UDF on a TileDB Array
67
68
* @param tileDBClient
68
69
*/
69
70
public static void runArrayUDF (TileDBClient tileDBClient ){
@@ -80,15 +81,18 @@ public static void runArrayUDF(TileDBClient tileDBClient){
80
81
queryRanges .addRangesItem (range1 );
81
82
queryRanges .addRangesItem (range2 );
82
83
83
-
84
84
HashMap <String ,Object > argumentsForArrayUDF = new HashMap <>();
85
85
argumentsForArrayUDF .put ("attr" , "rows" );
86
86
argumentsForArrayUDF .put ("scale" , 9 );
87
87
88
- MultiArrayUDF multiArrayUDF = new MultiArrayUDF ();
89
- multiArrayUDF .setUdfInfoName ("TileDB-Inc/array-udf" );
90
- multiArrayUDF .setRanges (queryRanges );
91
- System .out .println (tileDBUDF .executeSingleArray (multiArrayUDF , argumentsForArrayUDF , "tiledb://TileDB-Inc/quickstart_sparse" , "TileDB-Inc" ));
88
+ GenericUDF genericUDF = new GenericUDF ();
89
+ genericUDF .setUdfInfoName ("TileDB-Inc/array-udf" );
90
+ genericUDF .setArgument (serializeArgs (argumentsForArrayUDF ));
91
+
92
+ UDFArrayDetails array = new UDFArrayDetails ();
93
+ array .setUri ("tiledb://TileDB-Inc/quickstart_sparse" );
94
+
95
+ System .out .println (tileDBUDF .executeSingleArray (genericUDF , array , queryRanges , "TileDB-Inc" ));
92
96
}
93
97
94
98
/**
@@ -117,7 +121,7 @@ public static void runMultiArrayUDF(TileDBClient tileDBClient){
117
121
118
122
//array1
119
123
UDFArrayDetails array1 = new UDFArrayDetails ();
120
- array1 .setUri ("tiledb://TileDB-Inc /dense-array" );
124
+ array1 .setUri ("tiledb://shaunreed /dense-array" );
121
125
array1 .setRanges (queryRanges );
122
126
array1 .setBuffers (Arrays .asList ("rows" , "cols" , "a1" ));
123
127
arrays .add (array1 );
@@ -135,17 +139,19 @@ public static void runMultiArrayUDF(TileDBClient tileDBClient){
135
139
arguments .put ("attr1" , "a1" );
136
140
arguments .put ("attr2" , "a" );
137
141
138
- System .out .println (tileDBUDF .executeMultiArray (multiArrayUDF , arguments ));
142
+ multiArrayUDF .setArgument (serializeArgs (arguments ));
143
+
144
+ System .out .println (tileDBUDF .executeMultiArray (multiArrayUDF ));
139
145
}
140
146
141
147
/**
142
148
* Deregister an array
143
- * @param apiInstance
144
149
*/
145
- private static void deregisterArray (ArrayApi apiInstance )
150
+ private static void deregisterArray (TileDBClient tileDBClient )
146
151
{
147
152
String namespace = "<TILEDB_NAMESPACE>" ; // String | namespace array is in (an organization name or user's username)
148
153
String array = "<ARRAY_NAME>" ; // String | name/uri of array that is url-encoded
154
+ ArrayApi apiInstance = new ArrayApi (tileDBClient .getApiClient ());
149
155
try {
150
156
apiInstance .deregisterArray (namespace , array );
151
157
} catch (ApiException e ) {
@@ -159,13 +165,13 @@ private static void deregisterArray(ArrayApi apiInstance)
159
165
160
166
/**
161
167
* Delete an array
162
- * @param apiInstance
163
168
*/
164
- private static void deleteArray (ArrayApi apiInstance )
169
+ private static void deleteArray (TileDBClient tileDBClient )
165
170
{
166
171
String namespace = "<TILEDB_NAMESPACE>" ; // String | namespace array is in (an organization name or user's username)
167
172
String array = "<ARRAY_NAME>" ; // String | name/uri of array that is url-encoded
168
173
String contentType = "application/json" ; // String | Content Type of input and return mime
174
+ ArrayApi apiInstance = new ArrayApi (tileDBClient .getApiClient ());
169
175
try {
170
176
apiInstance .deleteArray (namespace , array , contentType );
171
177
} catch (ApiException e ) {
@@ -177,13 +183,9 @@ private static void deleteArray(ArrayApi apiInstance)
177
183
}
178
184
}
179
185
180
- /**
181
- * List groups
182
- * @param defaultClient
183
- */
184
- private static void listGroups (ApiClient defaultClient )
186
+ private static void listGroups (TileDBClient tileDBClient )
185
187
{
186
- GroupsApi apiInstance = new GroupsApi (defaultClient );
188
+ GroupsApi apiInstance = new GroupsApi (tileDBClient . getApiClient () );
187
189
Integer page = null ; // Integer | pagination offset
188
190
Integer perPage = null ; // Integer | pagination limit
189
191
String search = null ; // String | search string that will look at name, namespace or description fields
@@ -208,13 +210,11 @@ private static void listGroups(ApiClient defaultClient)
208
210
209
211
}
210
212
211
- /**
212
- * List arrays
213
- * @param apiInstance
214
- */
215
- private static void listArrays (ArrayApi apiInstance )
213
+ private static void listArrays (TileDBClient tileDBClient )
216
214
{
217
215
String namespace = "<TILEDB_NAMESPACE>" ; // String | namespace array is in (an organization name or user's username)
216
+ ArrayApi apiInstance = new ArrayApi (tileDBClient .getApiClient ());
217
+
218
218
try {
219
219
List <ArrayInfo > result = apiInstance .getArraysInNamespace (namespace );
220
220
System .out .println (result );
@@ -228,12 +228,14 @@ private static void listArrays(ArrayApi apiInstance)
228
228
}
229
229
230
230
231
- private static void getArraySchema (ArrayApi arrayApi ){
232
- String namespace = "<TILEDB_NAMESPACE> " ; // String | namespace array is in (an organization name or user's username)
233
- String array = "<ARRAY_URI> " ; // String | name/uri of array that is url-encoded
231
+ private static void getArraySchema (TileDBClient tileDBClient ){
232
+ String namespace = "TileDB-Inc " ; // String | namespace array is in (an organization name or user's username)
233
+ String array = "quickstart_sparse " ; // String | name/uri of array that is url-encoded
234
234
String contentType = "application/json" ; // String | Content Type of input and return mime
235
+ ArrayApi apiInstance = new ArrayApi (tileDBClient .getApiClient ());
236
+
235
237
try {
236
- ArraySchema result = arrayApi .getArray (namespace , array , contentType );
238
+ ArraySchema result = apiInstance .getArray (namespace , array , contentType );
237
239
System .out .println (result );
238
240
} catch (ApiException e ) {
239
241
System .err .println ("Exception when calling ArrayApi#getArray" );
@@ -244,7 +246,7 @@ private static void getArraySchema(ArrayApi arrayApi){
244
246
}
245
247
}
246
248
247
- private static void createArray (ArrayApi arrayApi ){
249
+ private static void createArray (TileDBClient tileDBClient ){
248
250
String namespace = "<TILEDB_NAMESPACE>" ; // String | namespace array is in (an organization name or user's username)
249
251
String arrayName = "s3://<BUCKET-NAME>/my_array" ; // String | name/uri of array that is url-encoded //
250
252
String contentType = "application/json" ; // String | Content Type of input and return mime
@@ -294,8 +296,10 @@ private static void createArray(ArrayApi arrayApi){
294
296
schema .setCellOrder (Layout .ROW_MAJOR );
295
297
System .out .println (schema );
296
298
299
+ ArrayApi apiInstance = new ArrayApi (tileDBClient .getApiClient ());
300
+
297
301
try {
298
- arrayApi .createArray (namespace , arrayName , contentType , schema , null );
302
+ apiInstance .createArray (namespace , arrayName , contentType , schema , null );
299
303
} catch (ApiException e ) {
300
304
System .err .println ("Exception when calling ArrayApi#createArray" );
301
305
System .err .println ("Status code: " + e .getCode ());
@@ -305,14 +309,16 @@ private static void createArray(ArrayApi arrayApi){
305
309
}
306
310
}
307
311
308
- public static void registerArray (ArrayApi arrayApi ){
312
+ public static void registerArray (TileDBClient tileDBClient ){
309
313
String namespace = "<TILEDB_NAMESPACE>" ; // String | namespace array is in (an organization name or user's username)
310
314
String array = "s3://<BUCKET-NAME>/<ARRAY-URI>/" ; // String | name/uri of array that is url-encoded
311
315
ArrayInfoUpdate arrayMetadata = new ArrayInfoUpdate (); // ArrayInfoUpdate | metadata associated with array
312
316
arrayMetadata .setUri ("s3://<BUCKET-NAME>/<ARRAY-URI>/" );
313
317
arrayMetadata .setName ("<ARRAY-NAME>" );
318
+ ArrayApi apiInstance = new ArrayApi (tileDBClient .getApiClient ());
319
+
314
320
try {
315
- ArrayInfo result = arrayApi .registerArray (namespace , array , arrayMetadata );
321
+ ArrayInfo result = apiInstance .registerArray (namespace , array , arrayMetadata );
316
322
System .out .println (result );
317
323
} catch (ApiException e ) {
318
324
System .err .println ("Exception when calling ArrayApi#registerArray" );
0 commit comments