-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Limit results generated by SELECT queries in MSQ #14370
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d8dc7e3
Limit select results in MSQ
LakshSingla 3097e05
reduce number of files in test
LakshSingla 0b14367
add truncated flag
LakshSingla acd78d7
avoid materializing select results to list, use iterable instead
LakshSingla f44138f
javadocs
LakshSingla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the end user, we need to set a flag in the report mentioning the results are truncated. |
||
.withBaggage(resultReaderExec::shutdownNow) | ||
); | ||
} else { | ||
return null; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.