Skip to content

Commit

Permalink
Support default workspace for queries (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaldwin-rs authored Apr 10, 2024
1 parent da1d4a0 commit 0080e24
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 47 deletions.
11 changes: 8 additions & 3 deletions src/main/java/com/rockset/jdbc/RocksetStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,24 @@ private static String getQueryIdFromQueryResponse(QueryResponse response) {
protected boolean executeWithParams(String sql, List<QueryParameter> params) throws SQLException {
clearCurrentResults();
checkOpen();
final String schema = this.connection.get().getSchema();

final String sqlWithWorkspace = schema.equals(RocksetConnection.DEFAULT_SCHEMA)
? sql
: String.format("OPTION(default_workspace='%s')\n %s", schema, sql);

ResultSet resultSet = null;
try {
// Make query to rockset service. We do not use queryTimeoutSeconds
// because rockset queries do not yet have a client-side timeout.
QueryResponse resp =
connection()
.startQuery(sql, this.fetchSize.get(), params, getStatementSessionProperties());
.startQuery(sqlWithWorkspace, this.fetchSize.get(), params, getStatementSessionProperties());

// store resuts in memory
resultSet =
new RocksetResultSet(
sql,
sqlWithWorkspace,
resp,
this.maxRows.get(),
RocksetResultSetPaginationParams.builder()
Expand All @@ -210,7 +215,7 @@ protected boolean executeWithParams(String sql, List<QueryParameter> params) thr
this.currentResult.set(resultSet);
return true;
} catch (RuntimeException e) {
String msg = "Error executing query '" + sql + "'" + " error = " + e.getMessage();
String msg = "Error executing query '" + sqlWithWorkspace + "'" + " error = " + e.getMessage();
RocksetDriver.log(msg);
throw new SQLException(msg, e);
} catch (Exception e) {
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/com/rockset/client/TestWorkspace.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.rockset.client;

import com.rockset.client.model.*;

import java.sql.Time;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.RandomStringUtils;
Expand Down Expand Up @@ -61,7 +63,7 @@ public void testDeleteWorkspace() throws Exception {
// wait for collection to go away
Awaitility.await("Waiting for collection to be cleaned up ")
.atMost(3, TimeUnit.MINUTES)
.pollInterval(1, TimeUnit.SECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.until(
(Callable<Boolean>)
() -> {
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/rockset/client/util/RetryHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.rockset.client.util;

import com.rockset.client.ApiException;
import org.awaitility.Awaitility;
import org.hamcrest.Matchers;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

public class RetryHelper {
public static <T> T retryOnApiException(Callable<T> request) {
return Awaitility
.await()
.atMost(5, TimeUnit.MINUTES)
.pollInterval(1, TimeUnit.SECONDS)
.until(() -> {
try {
return request.call();
} catch (ApiException e) {
System.out.println("Encountered error, retrying request: " + e.getMessage());
return null;
}
}, Matchers.notNullValue());
}
}
Loading

0 comments on commit 0080e24

Please sign in to comment.