Skip to content

Commit 907fc12

Browse files
Addressed comments from Adrian.
1 parent 593e5f1 commit 907fc12

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

src/main/java/com/salesforce/datacloud/jdbc/core/DataCloudConnection.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,18 @@ private DataCloudPreparedStatement getQueryPreparedStatement(String sql) {
176176
}
177177

178178
/**
179-
* Use getQueryStatus to determine if your query is "ready" then use this to get a collection of rows.
180-
* When using {@link RowBased.Mode#FULL_RANGE} this method is not responsible for calculating the offset near the end of available rows,
181-
* you must calculate the correct "pages" of offset and limit.
179+
* Retrieves a collection of rows for the specified query once it is ready.
180+
* Use {@link #getQueryStatus(String)} to check if the query has produced results or finished execution before calling this method.
181+
* <p>
182+
* When using {@link RowBased.Mode#FULL_RANGE}, this method does not handle pagination near the end of available rows.
183+
* The caller is responsible for calculating the correct offset and limit to avoid out-of-range errors.
184+
*
185+
* @param queryId The identifier of the query to fetch results for.
186+
* @param offset The starting row offset.
187+
* @param limit The maximum number of rows to retrieve.
188+
* @param mode The fetching mode—either {@link RowBased.Mode#SINGLE_RPC} for a single request or
189+
* {@link RowBased.Mode#FULL_RANGE} to iterate through all available rows.
190+
* @return A {@link DataCloudResultSet} containing the query results.
182191
*/
183192
public DataCloudResultSet getRowBasedResultSet(String queryId, long offset, long limit, RowBased.Mode mode) {
184193
val iterator = RowBased.of(executor, queryId, offset, limit, mode);

src/main/java/com/salesforce/datacloud/jdbc/core/DataCloudQueryStatus.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
import salesforce.cdp.hyperdb.v1.QueryInfo;
2222
import salesforce.cdp.hyperdb.v1.QueryStatus;
2323

24+
/**
25+
* Represents the status of a query.
26+
* The {@link CompletionStatus} enum defines the possible states of the query, which are:
27+
* <ul>
28+
* <li><b>RUNNING</b>: The query is still running or its status is unspecified.</li>
29+
* <li><b>RESULTS_PRODUCED</b>: The query has completed, and the results are ready for retrieval.</li>
30+
* <li><b>FINISHED</b>: The query has finished execution and its results have been persisted, guaranteed to be available until the expiration time.</li>
31+
* </ul>
32+
*/
2433
@Value
2534
public class DataCloudQueryStatus {
2635
public enum CompletionStatus {
@@ -39,10 +48,20 @@ public enum CompletionStatus {
3948

4049
CompletionStatus completionStatus;
4150

42-
public boolean isResultsProduced() {
51+
/**
52+
* Checks if the query's results have been produced.
53+
*
54+
* @return {@code true} if the query's results are available for retrieval, otherwise {@code false}.
55+
*/
56+
public boolean isResultProduced() {
4357
return completionStatus == CompletionStatus.RESULTS_PRODUCED;
4458
}
4559

60+
/**
61+
* Checks if the query execution is finished.
62+
*
63+
* @return {@code true} if the query has completed execution and results have been persisted, otherwise {@code false}.
64+
*/
4665
public boolean isExecutionFinished() {
4766
return completionStatus == CompletionStatus.FINISHED;
4867
}

src/test/java/com/salesforce/datacloud/jdbc/core/partial/RowBasedTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void fetchWithRowsNearEndRange_FULL_RANGE() {
122122
final long rows;
123123
try (val conn = getHyperQueryConnection()) {
124124
rows = conn.getQueryStatus(small)
125-
.filter(t -> t.isResultsProduced() || t.isExecutionFinished())
125+
.filter(t -> t.isResultProduced() || t.isExecutionFinished())
126126
.map(DataCloudQueryStatus::getRowCount)
127127
.findFirst()
128128
.orElseThrow(() -> new RuntimeException("boom"));
@@ -180,7 +180,7 @@ private void waitForQuery(String queryId) {
180180
}
181181

182182
private boolean isReady(DataCloudConnection connection, String queryId) {
183-
return connection.getQueryStatus(queryId).anyMatch(t -> t.isExecutionFinished() || t.isResultsProduced());
183+
return connection.getQueryStatus(queryId).anyMatch(t -> t.isExecutionFinished() || t.isResultProduced());
184184
}
185185

186186
private static List<Integer> rangeClosed(int start, int end) {

0 commit comments

Comments
 (0)