Github user paul-rogers commented on a diff in the pull request:
https://github.com/apache/drill/pull/788#discussion_r109539506
--- Diff:
exec/java-exec/src/test/java/org/apache/drill/test/QueryBuilder.java ---
@@ -271,6 +276,91 @@ public QuerySummary run() throws Exception {
}
/**
+ * Run the query and return the first result set as a
+ * {@link DirectRowSet} object that can be inspected directly
+ * by the code using a {@link RowSetReader}.
+ * <p>
+ * An enhancement is to provide a way to read a series of result
+ * batches as row sets.
+ * @return a row set that represents the first batch returned from
+ * the query
+ * @throws RpcException if anything goes wrong
+ */
+
+ public DirectRowSet rowSet() throws RpcException {
+
+ // Ignore all but the first non-empty batch.
+
+ QueryDataBatch dataBatch = null;
+ for (QueryDataBatch batch : results()) {
+ if (dataBatch == null && batch.getHeader().getRowCount() != 0) {
+ dataBatch = batch;
--- End diff --
The comment says, "Ignore all but the first non-empty batch." We detect if
a batch is non-empty by checking the row count. We detect if it is the first
such batch by checking if we already have our desired batch. The reason for the
funny code is that we want to release memory for all but the first batch.
The reason we get only the first batch is that this bit of test code only
makes sense for small result sets; one would not use this for, say, 10K
records. So, the bit about non-first batches is just for hygiene, no nasty
memory complaints if you happen to return more than one batch.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---