You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "LakshSingla (via GitHub)" <gi...@apache.org> on 2023/06/05 06:29:53 UTC
[GitHub] [druid] LakshSingla opened a new pull request, #14370: Limit results generated by SELECT queries in MSQ
LakshSingla opened a new pull request, #14370:
URL: https://github.com/apache/druid/pull/14370
### Description
MSQ queries return the results in the query reports. Querying large data sources can generate a lot of rows, all of which will get materialized in the query reports, causing them to grow very large. This PR limits the results of the SELECT queries that we put in the reports.
Note: Only way to fetch the complete result set after this change would be to run the query using the native engine, however, we might add a way to execute long-running queries that post their complete results in a different. Therefore the rows in the reports would serve as a preview to the actual result set.
#### Release note
SELECT queries executed using MSQ generate only a subset of the results in the query reports.
<hr>
##### Key changed/added classes in this PR
* `ControllerImpl`
<hr>
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
This PR has:
- [x] been self-reviewed.
- [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [x] a release note entry in the PR description.
- [x] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [x] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] cryptoe commented on a diff in pull request #14370: Limit results generated by SELECT queries in MSQ
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on code in PR #14370:
URL: https://github.com/apache/druid/pull/14370#discussion_r1223926405
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/ControllerImpl.java:
##########
@@ -1393,67 +1393,71 @@ private Yielder<Object[]> getFinalResultsYielder(
return Yielders.each(
Sequences.concat(
- StreamSupport.stream(queryKernel.getResultPartitionsForStage(finalStageId).spliterator(), false)
- .map(
- readablePartition -> {
- try {
- return new FrameChannelSequence(
- inputChannels.openChannel(
- new StagePartition(
- queryKernel.getStageDefinition(finalStageId).getId(),
- readablePartition.getPartitionNumber()
- )
- )
- );
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- ).collect(Collectors.toList())
- ).flatMap(
- frame -> {
- final Cursor cursor = FrameProcessors.makeCursor(
- frame,
- queryKernel.getStageDefinition(finalStageId).getFrameReader()
- );
-
- final ColumnSelectorFactory columnSelectorFactory = cursor.getColumnSelectorFactory();
- final ColumnMappings columnMappings = task.getQuerySpec().getColumnMappings();
- @SuppressWarnings("rawtypes")
- final List<ColumnValueSelector> selectors =
- columnMappings.getMappings()
- .stream()
- .map(
- mapping ->
- columnSelectorFactory.makeColumnValueSelector(mapping.getQueryColumn())
- ).collect(Collectors.toList());
-
- final List<SqlTypeName> sqlTypeNames = task.getSqlTypeNames();
- final List<Object[]> retVal = new ArrayList<>();
- while (!cursor.isDone()) {
- final Object[] row = new Object[columnMappings.size()];
- for (int i = 0; i < row.length; i++) {
- final Object value = selectors.get(i).getObject();
- if (sqlTypeNames == null || task.getSqlResultsContext() == null) {
- // SQL type unknown, or no SQL results context: pass-through as is.
- row[i] = value;
- } else {
- row[i] = SqlResults.coerce(
- context.jsonMapper(),
- task.getSqlResultsContext(),
- value,
- sqlTypeNames.get(i)
- );
- }
- }
- retVal.add(row);
- cursor.advance();
- }
-
- return Sequences.simple(retVal);
- }
- ).withBaggage(resultReaderExec::shutdownNow)
+ StreamSupport.stream(queryKernel.getResultPartitionsForStage(finalStageId).spliterator(), false)
+ .map(
+ readablePartition -> {
+ try {
+ return new FrameChannelSequence(
+ inputChannels.openChannel(
+ new StagePartition(
+ queryKernel.getStageDefinition(finalStageId).getId(),
+ readablePartition.getPartitionNumber()
+ )
+ )
+ );
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ ).collect(Collectors.toList())
+ ).flatMap(
+ frame -> {
+ final Cursor cursor = FrameProcessors.makeCursor(
+ frame,
+ queryKernel.getStageDefinition(finalStageId).getFrameReader()
+ );
+
+ final ColumnSelectorFactory columnSelectorFactory = cursor.getColumnSelectorFactory();
+ final ColumnMappings columnMappings = task.getQuerySpec().getColumnMappings();
+ @SuppressWarnings("rawtypes")
+ final List<ColumnValueSelector> selectors =
+ columnMappings.getMappings()
+ .stream()
+ .map(
+ mapping ->
+ columnSelectorFactory.makeColumnValueSelector(mapping.getQueryColumn())
+ ).collect(Collectors.toList());
+
+ final List<SqlTypeName> sqlTypeNames = task.getSqlTypeNames();
+ final List<Object[]> retVal = new ArrayList<>();
Review Comment:
This might blow up.
A good test case for this issue is to try to do a select * on a datasource with 1 million rows.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] cryptoe merged pull request #14370: Limit results generated by SELECT queries in MSQ
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe merged PR #14370:
URL: https://github.com/apache/druid/pull/14370
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] cryptoe commented on pull request #14370: Limit results generated by SELECT queries in MSQ
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on PR #14370:
URL: https://github.com/apache/druid/pull/14370#issuecomment-1588949644
Please add the truncated flag in the read me.
LGTM to me otherwise.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] cryptoe commented on a diff in pull request #14370: Limit results generated by SELECT queries in MSQ
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on code in PR #14370:
URL: https://github.com/apache/druid/pull/14370#discussion_r1220855468
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/ControllerImpl.java:
##########
@@ -1393,67 +1393,69 @@ private Yielder<Object[]> getFinalResultsYielder(
return Yielders.each(
Sequences.concat(
- StreamSupport.stream(queryKernel.getResultPartitionsForStage(finalStageId).spliterator(), false)
- .map(
- readablePartition -> {
- try {
- return new FrameChannelSequence(
- inputChannels.openChannel(
- new StagePartition(
- queryKernel.getStageDefinition(finalStageId).getId(),
- readablePartition.getPartitionNumber()
- )
- )
- );
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- ).collect(Collectors.toList())
- ).flatMap(
- frame -> {
- final Cursor cursor = FrameProcessors.makeCursor(
- frame,
- queryKernel.getStageDefinition(finalStageId).getFrameReader()
- );
-
- final ColumnSelectorFactory columnSelectorFactory = cursor.getColumnSelectorFactory();
- final ColumnMappings columnMappings = task.getQuerySpec().getColumnMappings();
- @SuppressWarnings("rawtypes")
- final List<ColumnValueSelector> selectors =
- columnMappings.getMappings()
- .stream()
- .map(
- mapping ->
- columnSelectorFactory.makeColumnValueSelector(mapping.getQueryColumn())
- ).collect(Collectors.toList());
-
- final List<SqlTypeName> sqlTypeNames = task.getSqlTypeNames();
- final List<Object[]> retVal = new ArrayList<>();
- while (!cursor.isDone()) {
- final Object[] row = new Object[columnMappings.size()];
- for (int i = 0; i < row.length; i++) {
- final Object value = selectors.get(i).getObject();
- if (sqlTypeNames == null || task.getSqlResultsContext() == null) {
- // SQL type unknown, or no SQL results context: pass-through as is.
- row[i] = value;
- } else {
- row[i] = SqlResults.coerce(
- context.jsonMapper(),
- task.getSqlResultsContext(),
- value,
- sqlTypeNames.get(i)
- );
- }
- }
- retVal.add(row);
- cursor.advance();
- }
-
- return Sequences.simple(retVal);
- }
- ).withBaggage(resultReaderExec::shutdownNow)
+ StreamSupport.stream(queryKernel.getResultPartitionsForStage(finalStageId).spliterator(), false)
+ .map(
+ readablePartition -> {
+ try {
+ return new FrameChannelSequence(
+ inputChannels.openChannel(
+ new StagePartition(
+ queryKernel.getStageDefinition(finalStageId).getId(),
+ readablePartition.getPartitionNumber()
+ )
+ )
+ );
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ ).collect(Collectors.toList())
+ ).flatMap(
+ frame -> {
+ final Cursor cursor = FrameProcessors.makeCursor(
+ frame,
+ queryKernel.getStageDefinition(finalStageId).getFrameReader()
+ );
+
+ final ColumnSelectorFactory columnSelectorFactory = cursor.getColumnSelectorFactory();
+ final ColumnMappings columnMappings = task.getQuerySpec().getColumnMappings();
+ @SuppressWarnings("rawtypes")
+ final List<ColumnValueSelector> selectors =
+ columnMappings.getMappings()
+ .stream()
+ .map(
+ mapping ->
+ columnSelectorFactory.makeColumnValueSelector(mapping.getQueryColumn())
+ ).collect(Collectors.toList());
+
+ final List<SqlTypeName> sqlTypeNames = task.getSqlTypeNames();
+ final List<Object[]> retVal = new ArrayList<>();
+ while (!cursor.isDone()) {
+ final Object[] row = new Object[columnMappings.size()];
+ for (int i = 0; i < row.length; i++) {
+ final Object value = selectors.get(i).getObject();
+ if (sqlTypeNames == null || task.getSqlResultsContext() == null) {
+ // SQL type unknown, or no SQL results context: pass-through as is.
+ row[i] = value;
+ } else {
+ row[i] = SqlResults.coerce(
+ context.jsonMapper(),
+ task.getSqlResultsContext(),
+ value,
+ sqlTypeNames.get(i)
+ );
+ }
+ }
+ retVal.add(row);
+ cursor.advance();
+ }
+
+ return Sequences.simple(retVal);
+ }
+ )
+ .limit(Limits.MAX_SELECT_RESULT_ROWS)
Review Comment:
For the end user, we need to set a flag in the report mentioning the results are truncated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] cryptoe commented on pull request #14370: Limit results generated by SELECT queries in MSQ
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on PR #14370:
URL: https://github.com/apache/druid/pull/14370#issuecomment-1592530974
cc @vogievetsky We now have a new field inside the task report : `multiStageQuery.payload.results.resultsTruncated` which denotes if the results are truncated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org