Skip to content

Commit 5d8b1b0

Browse files
add UDF wrapping
1 parent f3b83a1 commit 5d8b1b0

File tree

3 files changed

+245
-1
lines changed

3 files changed

+245
-1
lines changed

src/main/java/io/tiledb/cloud/CustomCode.txt

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,74 @@ public byte[] runSQLBytes(String namespace, SQLParameters sql, String acceptEnco
4646
}
4747

4848

49+
UdfApi.java
50+
51+
/**
52+
*
53+
* submit a generic UDF in the given namespace
54+
* @param namespace namespace array is in (an organization name or user's username) (required)
55+
* @param udf UDF to run (required)
56+
* @param acceptEncoding Encoding to use (optional)
57+
* @return ApiResponse<File>
58+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
59+
* @http.response.details
60+
<table summary="Response Details" border="1">
61+
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
62+
<tr><td> 200 </td><td> UDF completed and the UDF-type specific result is returned </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
63+
<tr><td> 0 </td><td> error response </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
64+
</table>
65+
*/
66+
public ApiResponse<String> submitGenericUDFWithHttpInfoString(String namespace, GenericUDF udf, String acceptEncoding) throws ApiException {
67+
okhttp3.Call localVarCall = submitGenericUDFValidateBeforeCall(namespace, udf, acceptEncoding, null);
68+
Type localVarReturnType = new TypeToken<String>(){}.getType();
69+
return localVarApiClient.execute(localVarCall, localVarReturnType);
70+
}
71+
72+
/**
73+
*
74+
* submit a generic UDF in the given namespace
75+
* @param namespace namespace array is in (an organization name or user&#39;s username) (required)
76+
* @param udf UDF to run (required)
77+
* @param acceptEncoding Encoding to use (optional)
78+
* @return String
79+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
80+
* @http.response.details
81+
<table summary="Response Details" border="1">
82+
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
83+
<tr><td> 200 </td><td> UDF completed and the UDF-type specific result is returned </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
84+
<tr><td> 0 </td><td> error response </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
85+
</table>
86+
*/
87+
public String submitGenericUDFString(String namespace, GenericUDF udf, String acceptEncoding) throws ApiException {
88+
ApiResponse<String> localVarResp = submitGenericUDFWithHttpInfoString(namespace, udf, acceptEncoding);
89+
return localVarResp.getData();
90+
}
91+
92+
93+
/**
94+
*
95+
* send a UDF to run against a specified array/URI registered to a group/project
96+
* @param namespace namespace array is in (an organization name or user&#39;s username) (required)
97+
* @param array name/uri of array that is url-encoded (required)
98+
* @param udf UDF to run (required)
99+
* @param xPayer Name of organization or user who should be charged for this request (optional)
100+
* @param acceptEncoding Encoding to use (optional)
101+
* @param v2 flag to indicate if v2 array UDFs should be used, currently in beta testing. Setting any value will enable v2 array UDFs. (optional)
102+
* @return String
103+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
104+
* @http.response.details
105+
<table summary="Response Details" border="1">
106+
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
107+
<tr><td> 200 </td><td> UDF completed and the UDF-type specific result is returned </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
108+
<tr><td> 0 </td><td> error response </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
109+
</table>
110+
*/
111+
public String submitUDF(String namespace, String array, MultiArrayUDF udf, String xPayer, String acceptEncoding, String v2) throws ApiException {
112+
ApiResponse<String> localVarResp = submitUDFWithHttpInfoString(namespace, array, udf, xPayer, acceptEncoding, v2);
113+
return localVarResp.getData();
114+
}
115+
116+
117+
118+
119+
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package io.tiledb.cloud;
2+
3+
import com.google.gson.Gson;
4+
import io.tiledb.cloud.rest_api.ApiException;
5+
import io.tiledb.cloud.rest_api.api.UdfApi;
6+
import io.tiledb.cloud.rest_api.model.GenericUDF;
7+
import io.tiledb.cloud.rest_api.model.MultiArrayUDF;
8+
import java.util.HashMap;
9+
10+
public class TileDBUDFManager {
11+
private TileDBClient tileDBClient;
12+
private String namespace;
13+
private UdfApi apiInstance;
14+
15+
public TileDBUDFManager(TileDBClient tileDBClient, String namespace) {
16+
this.tileDBClient = tileDBClient;
17+
this.namespace = namespace;
18+
this.apiInstance = new UdfApi(this.tileDBClient.getApiClient());
19+
20+
}
21+
22+
/**
23+
* Executes a generic-UDF. A generic-UDF is a UDF that is not using a TIleDB array.
24+
*
25+
* @param genericUDF The generic UDF definition
26+
* @param arguments The UDF arguments
27+
* @return
28+
*/
29+
public String executeGenericUDF(GenericUDF genericUDF, HashMap<String, Object> arguments){
30+
String serializedArgs = serializeArgs(arguments);
31+
genericUDF.setArgument(serializedArgs);
32+
try {
33+
return apiInstance.submitGenericUDFString(namespace, genericUDF, "none");
34+
} catch (ApiException e) {
35+
System.err.println("Exception when calling UdfApi#submitGenericUDF");
36+
System.err.println("Status code: " + e.getCode());
37+
System.err.println("Reason: " + e.getResponseBody());
38+
System.err.println("Response headers: " + e.getResponseHeaders());
39+
e.printStackTrace();
40+
}
41+
return null;
42+
}
43+
44+
/**
45+
* Executes an array-UDF. An array-UDF is a UDF applied to a TileDB array
46+
*
47+
* @param multiArrayUDF The array-UDF. Can reference one arrays
48+
* @param arguments The UDF arguments
49+
* @param arrayURI The array URI
50+
* @param xPayer Name of organization or user who should be charged for this request
51+
* @return
52+
*/
53+
public String executeSingleArrayUDF(MultiArrayUDF multiArrayUDF, HashMap<String, Object> arguments, String arrayURI, String xPayer){
54+
String serializedArgs = serializeArgs(arguments);
55+
multiArrayUDF.setArgument(serializedArgs);
56+
//split uri to get namespace and array name
57+
arrayURI = arrayURI.replaceAll("tiledb://", ""); //remove tiledb prefix
58+
String[] split = arrayURI.split("/");
59+
if (split.length != 2)
60+
throw new RuntimeException(
61+
"TileDB URI is in the wrong format. The format should be: tiledb://namespace/array_name");
62+
try {
63+
return apiInstance.submitUDFString(split[0], split[1], multiArrayUDF, xPayer, "none", "");
64+
} catch (ApiException e) {
65+
System.err.println("Exception when calling UdfApi#submitUDF");
66+
System.err.println("Status code: " + e.getCode());
67+
System.err.println("Reason: " + e.getResponseBody());
68+
System.err.println("Response headers: " + e.getResponseHeaders());
69+
e.printStackTrace();
70+
}
71+
return null;
72+
}
73+
74+
/**
75+
* Serializes the arguments to a String
76+
*
77+
* @param arguments The input arguments in a HashMap
78+
* @return The arguments in a String
79+
*/
80+
private String serializeArgs(HashMap<String, Object> arguments) {
81+
if (arguments == null || arguments.isEmpty()) return "";
82+
Gson gson = new Gson();
83+
return gson.toJson(arguments);
84+
}
85+
}

src/main/java/io/tiledb/cloud/rest_api/api/UdfApi.java

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,47 @@ public File submitGenericUDF(String namespace, GenericUDF udf, String acceptEnco
10701070
return localVarResp.getData();
10711071
}
10721072

1073+
/**
1074+
*
1075+
* submit a generic UDF in the given namespace
1076+
* @param namespace namespace array is in (an organization name or user&#39;s username) (required)
1077+
* @param udf UDF to run (required)
1078+
* @param acceptEncoding Encoding to use (optional)
1079+
* @return ApiResponse&lt;File&gt;
1080+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
1081+
* @http.response.details
1082+
<table summary="Response Details" border="1">
1083+
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
1084+
<tr><td> 200 </td><td> UDF completed and the UDF-type specific result is returned </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
1085+
<tr><td> 0 </td><td> error response </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
1086+
</table>
1087+
*/
1088+
public ApiResponse<String> submitGenericUDFWithHttpInfoString(String namespace, GenericUDF udf, String acceptEncoding) throws ApiException {
1089+
okhttp3.Call localVarCall = submitGenericUDFValidateBeforeCall(namespace, udf, acceptEncoding, null);
1090+
Type localVarReturnType = new TypeToken<String>(){}.getType();
1091+
return localVarApiClient.execute(localVarCall, localVarReturnType);
1092+
}
1093+
1094+
/**
1095+
*
1096+
* submit a generic UDF in the given namespace
1097+
* @param namespace namespace array is in (an organization name or user&#39;s username) (required)
1098+
* @param udf UDF to run (required)
1099+
* @param acceptEncoding Encoding to use (optional)
1100+
* @return File
1101+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
1102+
* @http.response.details
1103+
<table summary="Response Details" border="1">
1104+
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
1105+
<tr><td> 200 </td><td> UDF completed and the UDF-type specific result is returned </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
1106+
<tr><td> 0 </td><td> error response </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
1107+
</table>
1108+
*/
1109+
public String submitGenericUDFString(String namespace, GenericUDF udf, String acceptEncoding) throws ApiException {
1110+
ApiResponse<String> localVarResp = submitGenericUDFWithHttpInfoString(namespace, udf, acceptEncoding);
1111+
return localVarResp.getData();
1112+
}
1113+
10731114
/**
10741115
*
10751116
* submit a generic UDF in the given namespace
@@ -1387,7 +1428,7 @@ public File submitUDF(String namespace, String array, MultiArrayUDF udf, String
13871428
}
13881429

13891430
/**
1390-
*
1431+
*
13911432
* send a UDF to run against a specified array/URI registered to a group/project
13921433
* @param namespace namespace array is in (an organization name or user&#39;s username) (required)
13931434
* @param array name/uri of array that is url-encoded (required)
@@ -1410,6 +1451,53 @@ public ApiResponse<File> submitUDFWithHttpInfo(String namespace, String array, M
14101451
return localVarApiClient.execute(localVarCall, localVarReturnType);
14111452
}
14121453

1454+
/**
1455+
*
1456+
* send a UDF to run against a specified array/URI registered to a group/project
1457+
* @param namespace namespace array is in (an organization name or user&#39;s username) (required)
1458+
* @param array name/uri of array that is url-encoded (required)
1459+
* @param udf UDF to run (required)
1460+
* @param xPayer Name of organization or user who should be charged for this request (optional)
1461+
* @param acceptEncoding Encoding to use (optional)
1462+
* @param v2 flag to indicate if v2 array UDFs should be used, currently in beta testing. Setting any value will enable v2 array UDFs. (optional)
1463+
* @return String
1464+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
1465+
* @http.response.details
1466+
<table summary="Response Details" border="1">
1467+
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
1468+
<tr><td> 200 </td><td> UDF completed and the UDF-type specific result is returned </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
1469+
<tr><td> 0 </td><td> error response </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
1470+
</table>
1471+
*/
1472+
public String submitUDFString(String namespace, String array, MultiArrayUDF udf, String xPayer, String acceptEncoding, String v2) throws ApiException {
1473+
ApiResponse<String> localVarResp = submitUDFWithHttpInfoString(namespace, array, udf, xPayer, acceptEncoding, v2);
1474+
return localVarResp.getData();
1475+
}
1476+
1477+
/**
1478+
*
1479+
* send a UDF to run against a specified array/URI registered to a group/project
1480+
* @param namespace namespace array is in (an organization name or user&#39;s username) (required)
1481+
* @param array name/uri of array that is url-encoded (required)
1482+
* @param udf UDF to run (required)
1483+
* @param xPayer Name of organization or user who should be charged for this request (optional)
1484+
* @param acceptEncoding Encoding to use (optional)
1485+
* @param v2 flag to indicate if v2 array UDFs should be used, currently in beta testing. Setting any value will enable v2 array UDFs. (optional)
1486+
* @return ApiResponse&lt;File&gt;
1487+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
1488+
* @http.response.details
1489+
<table summary="Response Details" border="1">
1490+
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
1491+
<tr><td> 200 </td><td> UDF completed and the UDF-type specific result is returned </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
1492+
<tr><td> 0 </td><td> error response </td><td> * X-TILEDB-CLOUD-TASK-ID - Task ID for just completed request <br> </td></tr>
1493+
</table>
1494+
*/
1495+
public ApiResponse<String> submitUDFWithHttpInfoString(String namespace, String array, MultiArrayUDF udf, String xPayer, String acceptEncoding, String v2) throws ApiException {
1496+
okhttp3.Call localVarCall = submitUDFValidateBeforeCall(namespace, array, udf, xPayer, acceptEncoding, v2, null);
1497+
Type localVarReturnType = new TypeToken<String>(){}.getType();
1498+
return localVarApiClient.execute(localVarCall, localVarReturnType);
1499+
}
1500+
14131501
/**
14141502
* (asynchronously)
14151503
* send a UDF to run against a specified array/URI registered to a group/project

0 commit comments

Comments
 (0)