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
Allow Presto clients to receive query results in binary format #20932
Conversation
0bc1bed
to
743288d
Compare
5bca17d
to
9955f8c
Compare
Please consider adding either a query or path parameter to toggle the client results, as clients may set arbitrary headers, and without migration of clients to support this format, it will cause them to break unexpectedly (the |
9955f8c
to
5ba0235
Compare
@tdcmeehan Tim, thank you for reviewing. I updated to use query parameter binaryResults=true instead of the header. Would you, please, take another look? |
5ba0235
to
c022068
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, whereas data
is Object
because we don't know the underlying types (primitives, lists, etc.), don't we know that binaryData
is String
since it's Base64 encoded?
data.addAll(queryResults.getBinaryData()); | ||
} | ||
} | ||
assertNull(queryResults.getError()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps print out the error in case this test becomes flaky
@@ -442,25 +447,48 @@ private synchronized QueryResults getNextResult(long token, UriInfo uriInfo, Str | |||
// last page is removed. If another thread observes this state before the response is cached | |||
// the pages will be lost. | |||
Iterable<List<Object>> data = null; | |||
List<Object> binaryData = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: don't we know that the parameter of the List is String?
c022068
to
a1e7cfd
Compare
@tdcmeehan Good points, Tim. Updated. Please, take another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM % a few more nits, feel free to merge after addressing!
if (serializedPage == null) { | ||
break; | ||
if (binaryResults) { | ||
binaryData = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: use immutable list (consistent with below branch)?
DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1000); | ||
PagesSerdeUtil.writeSerializedPage(sliceOutput, serializedPage); | ||
|
||
String encodedPage = Base64.getEncoder().encodeToString(sliceOutput.slice().byteArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Add a constant?
String encodedPage = Base64.getEncoder().encodeToString(sliceOutput.slice().byteArray()); | |
String encodedPage = BASE64_ENCODER.encodeToString(sliceOutput.slice().byteArray()); |
bytes += serializedPage.getSizeInBytes(); | ||
|
||
DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1000); | ||
PagesSerdeUtil.writeSerializedPage(sliceOutput, serializedPage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: static import?
PagesSerdeUtil.writeSerializedPage(sliceOutput, serializedPage); | |
writeSerializedPage(sliceOutput, serializedPage); |
a1e7cfd
to
c64d903
Compare
@tdcmeehan Tim, thank you for the review and offline discussion. Addressed all comments and updated the PR. |
c03ecc5
to
9550d77
Compare
9550d77
to
d218176
Compare
Codenotify: Notifying subscribers in CODENOTIFY files for diff dd5b168...d218176.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! (docs)
.scheme(getScheme(xForwardedProto, uriInfo)) | ||
.replacePath("/v1/statement/queued/") | ||
.replacePath("/v1/statement/queued") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a Q : Why was the trailing slash removed ?
if (serializedPage == null) { | ||
break; | ||
if (binaryResults) { | ||
ImmutableList.Builder<String> pages = ImmutableList.builder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: How do you feel about merging these two of the loops ?
Also is it expensive to recreate DynamicSliceOutput(1000) each time in the loop ? No idea, so just asking :-)
} | ||
} | ||
|
||
if (queryResults.getError() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Is there a Util class where we can create this helper method that is an improvement on assertNull(queryResults.getError()) that is used in a couple of places now (this whole check and fail descriptively thing) :-)
Introduce 'binaryResults=true' query parameter to request query results returned in binary format https://prestodb.io/docs/current/develop/serialized-page.html
With binaryResults=true, the result json will contain 'binaryData' field of type array with one or
more pages of the results. The 'data' field will not be included in the result JSON.
See #20886