Skip to content

Exceed 2GB limit for SQL queries #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ apply plugin: 'java'
apply plugin: 'com.diffplug.spotless'

group 'io.tiledb'
version = '0.1.1-SNAPSHOT'
version = '0.2.1-SNAPSHOT'

repositories {
mavenCentral()
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/examples/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

// Import classes:
import io.tiledb.cloud.TileDBClient;
import io.tiledb.cloud.TileDBSQL;
import io.tiledb.cloud.TileDBUDF;
import io.tiledb.cloud.rest_api.ApiClient;
import io.tiledb.cloud.rest_api.ApiException;
import io.tiledb.cloud.TileDBLogin;
import io.tiledb.cloud.rest_api.api.GroupsApi;
import io.tiledb.cloud.rest_api.api.ArrayApi;
import io.tiledb.cloud.rest_api.model.*;
import io.tiledb.java.api.Pair;
import org.apache.arrow.vector.ValueVector;

import java.math.BigDecimal;
import java.util.ArrayList;
Expand Down Expand Up @@ -37,6 +40,7 @@ public static void main(String[] args) {

// Uncomment to run whichever example you want
// runGenericUDF(tileDBClient);
// runSQL("SELECT * FROM `tiledb://TileDB-Inc/quickstart_sparse`", tileDBClient);
// runArrayUDF(tileDBClient);
// runMultiArrayUDF(tileDBClient);
// getArraySchema(apiInstance);
Expand All @@ -48,6 +52,27 @@ public static void main(String[] args) {
// deregisterArray(apiInstance);
}

/**
* Runs a simple SQL query
* @param s the query
* @param tileDBClient
*/
private static void runSQL(String s, TileDBClient tileDBClient) {
SQLParameters sqlParameters = new SQLParameters();
sqlParameters.setQuery(s);
// get results in arrow format
sqlParameters.setResultFormat(ResultFormat.ARROW);

//set timeout to unlimited
tileDBClient.setReadTimeout(0);

// create TileDBSQL object
TileDBSQL tileDBSQL = new TileDBSQL(tileDBClient, "TileDB-Inc", sqlParameters);

// run query and expect results in arrow format
Pair<ArrayList<ValueVector>, Integer> valueVectors = tileDBSQL.execArrow();
}

/**
* Runs a generic UDF
* @param tileDBClient
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/io/tiledb/cloud/TileDBSQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import org.apache.arrow.compression.CommonsCompressionFactory;

Expand Down Expand Up @@ -54,16 +55,16 @@ public TileDBSQL(TileDBClient tileDBClient, String namespace, SQLParameters sql)
* @return A pair that consists of an ArrayList of all valueVectors and the
* number of batches read.
*/
public io.tiledb.java.api.Pair<ArrayList<ValueVector>, Integer> execArrow(){
public io.tiledb.java.api.Pair<ArrayList<ValueVector>, Integer> execArrow() {
try {
assert sql.getResultFormat() != null;
byte[] bytes = apiInstance.runSQLBytes(namespace, sql, "none");
InputStream in = apiInstance.runSQLBytes(namespace, sql, "none");

ArrayList<ValueVector> valueVectors = null;
int readBatchesCount = 0;

// RootAllocator allocator = new RootAllocator(Long.MAX_VALUE);
RootAllocator allocator = new RootAllocator(RootAllocator.configBuilder().allocationManagerFactory(UnsafeAllocationManager.FACTORY).build());
ArrowStreamReader reader = new ArrowStreamReader(new ByteArrayInputStream(bytes), allocator, CommonsCompressionFactory.INSTANCE);
ArrowStreamReader reader = new ArrowStreamReader(in, allocator, CommonsCompressionFactory.INSTANCE);

VectorSchemaRoot root = reader.getVectorSchemaRoot();

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/tiledb/cloud/rest_api/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,8 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
} else if (returnType.equals(File.class)) {
// Handle file downloading.
return (T) downloadFileFromResponse(response);
} else if ("class java.io.InputStream".equals(returnType.toString())) {
return (T) response.body().byteStream();
}

String respBody;
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/io/tiledb/cloud/rest_api/api/SqlApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@

import io.tiledb.cloud.rest_api.model.SQLParameters;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -180,7 +184,7 @@ public List<Object> runSQL(String namespace, SQLParameters sql, String acceptEnc
* @param namespace namespace to run task under is in (an organization name or user&#39;s username) (required)
* @param sql sql being submitted (required)
* @param acceptEncoding Encoding to use (optional)
* @return byte[]
* @return Input stream of bytes
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
Expand All @@ -190,8 +194,8 @@ public List<Object> runSQL(String namespace, SQLParameters sql, String acceptEnc
<tr><td> 0 </td><td> error response </td><td> - </td></tr>
</table>
*/
public byte[] runSQLBytes(String namespace, SQLParameters sql, String acceptEncoding) throws ApiException {
ApiResponse<byte[]> localVarResp = runSQLWithHttpInfoBytes(namespace, sql, acceptEncoding);
public InputStream runSQLBytes(String namespace, SQLParameters sql, String acceptEncoding) throws ApiException {
ApiResponse<InputStream> localVarResp = runSQLWithHttpInfoBytes(namespace, sql, acceptEncoding);
return localVarResp.getData();
}

Expand Down Expand Up @@ -223,7 +227,7 @@ public ApiResponse<List<Object>> runSQLWithHttpInfo(String namespace, SQLParamet
* @param namespace namespace to run task under is in (an organization name or user&#39;s username) (required)
* @param sql sql being submitted (required)
* @param acceptEncoding Encoding to use (optional)
* @return ApiResponse with byte[]
* @return ApiResponse with an InputStream of bytes
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
Expand All @@ -233,9 +237,9 @@ public ApiResponse<List<Object>> runSQLWithHttpInfo(String namespace, SQLParamet
<tr><td> 0 </td><td> error response </td><td> - </td></tr>
</table>
*/
public ApiResponse<byte[]> runSQLWithHttpInfoBytes(String namespace, SQLParameters sql, String acceptEncoding) throws ApiException {
public ApiResponse<InputStream> runSQLWithHttpInfoBytes(String namespace, SQLParameters sql, String acceptEncoding) throws ApiException {
okhttp3.Call localVarCall = runSQLValidateBeforeCall(namespace, sql, acceptEncoding, null);
Type localVarReturnType = new TypeToken<byte[]>(){}.getType();
Type localVarReturnType = new TypeToken<InputStream>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

Expand Down