in jdbc/src/main/java/software/amazon/timestream/jdbc/TimestreamStatement.java [191:276]
public synchronized ResultSet executeQuery(final String sql) throws SQLException {
verifyOpen();
if (this.resultSet != null) {
this.resultSet.close();
}
final QueryRequest request = new QueryRequest().withQueryString(sql);
final int queryFetchSize = this.getFetchSize();
if (queryFetchSize != 0) {
request.withMaxRows(queryFetchSize);
}
QueryResult result;
try {
try {
result = retrieveResult(request);
this.queryId.set(result.getQueryId());
LOGGER.info("Query ID: {}", this.queryId);
this.canCancel.set(true);
List<Row> rows = result.getRows();
String nextToken = result.getNextToken();
while ((rows.size() == 0) && (nextToken != null)) {
this.numEmptyPages.incrementAndGet();
if (isClosed.get()) {
doCancel();
throw Error.createSQLException(
LOGGER,
Error.STMT_CLOSED_DURING_EXECUTE,
this.queryId.get());
}
try {
result = retrieveResult(request.withNextToken(nextToken));
rows = result.getRows();
nextToken = result.getNextToken();
} catch (final ConflictException conflictException) {
// ConflictException is thrown when attempting to retrieve more rows on a
// query that has been canceled.
throw Error.createSQLException(
LOGGER,
Constants.OPERATION_CANCELED_SQL_STATE,
conflictException,
Error.QUERY_CANCELED,
this.queryId.get());
}
}
} finally {
this.canCancel.set(false);
}
this.resultSet = new TimestreamResultSet(
this,
sql,
result,
this.typeMap,
this.largeMaxRows,
this.maxFieldSize,
this.totalExecutionTime.get(),
this.numPages.get());
LOGGER.info(
"Query ID: {}\n"
+ "Time to first result: {}ms\n"
+ "Total number of pages: {}\n"
+ "Number of empty pages: {}\n"
+ "Number of rows: {}",
this.queryId,
this.totalExecutionTime,
this.numPages,
this.numEmptyPages,
result.getRows().size());
return resultSet;
} catch (final AmazonTimestreamQueryException e) {
throw Error.createSQLException(
LOGGER,
e,
Error.INVALID_QUERY,
this.queryId.get(),
e.getLocalizedMessage());
} catch (final ClientExecutionTimeoutException e) {
throw new SQLTimeoutException(
Error.getErrorMessage(LOGGER, Error.QUERY_TIMED_OUT, this.queryId.get()),
e);
}
}