mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 17:23:27 -05:00
Progressive Results Part 1: Batch Completion Notification (#95)
The main feature of this pull request is a new callback that's added to the query class that is called when a batch has completed execution and retrieval of results. This callback will send an event to the extension with the batch summary information. After that, the extension can submit subset requests for the resultsets of the batch. Other smaller changes in this pull request: Refactor to assign a batch a id when its created instead of when returning the list of batch summaries Passing the SelectionData around instead of extracting the values for it Moving creation of BatchSummary into the Batch class Retrieval of results is now permitted even if the entire query has not completed, as long as the batch requested has completed. Also note, this does not break the protocol. It adds a new event that a queryRunner can listen to, but it doesn't require it to be listened to. * Refactor to remove SectionData class in favor of BufferRange * Adding callback for batch completion that will let the extension know that a batch has completed execution * Refactoring to make progressive results work as per async query execution * Allowing retrieval of batch results while query is in progress * reverting global.json, whoops * Adding a few missing comments, and fixing a couple code style bugs * Using SelectionData everywhere again * One more missing comment
This commit is contained in:
@@ -51,11 +51,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
/// </summary>
|
||||
private bool hasExecuteBeenCalled;
|
||||
|
||||
/// <summary>
|
||||
/// The factory to use for outputting the results of this query
|
||||
/// </summary>
|
||||
private readonly IFileStreamFactory outputFileFactory;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@@ -77,7 +72,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
QueryText = queryText;
|
||||
editorConnection = connection;
|
||||
cancellationSource = new CancellationTokenSource();
|
||||
outputFileFactory = outputFactory;
|
||||
|
||||
// Process the query into batches
|
||||
ParseResult parseResult = Parser.Parse(queryText, new ParseOptions
|
||||
@@ -85,13 +79,17 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
BatchSeparator = settings.BatchSeparator
|
||||
});
|
||||
// NOTE: We only want to process batches that have statements (ie, ignore comments and empty lines)
|
||||
Batches = parseResult.Script.Batches.Where(b => b.Statements.Count > 0)
|
||||
.Select(b => new Batch(b.Sql,
|
||||
b.StartLocation.LineNumber - 1,
|
||||
b.StartLocation.ColumnNumber - 1,
|
||||
b.EndLocation.LineNumber - 1,
|
||||
b.EndLocation.ColumnNumber - 1,
|
||||
outputFileFactory)).ToArray();
|
||||
var batchSelection = parseResult.Script.Batches
|
||||
.Where(batch => batch.Statements.Count > 0)
|
||||
.Select((batch, index) =>
|
||||
new Batch(batch.Sql,
|
||||
new SelectionData(
|
||||
batch.StartLocation.LineNumber - 1,
|
||||
batch.StartLocation.ColumnNumber - 1,
|
||||
batch.EndLocation.LineNumber - 1,
|
||||
batch.EndLocation.ColumnNumber - 1),
|
||||
index, outputFactory));
|
||||
Batches = batchSelection.ToArray();
|
||||
}
|
||||
|
||||
#region Properties
|
||||
@@ -102,10 +100,15 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
/// <param name="q">The query that completed</param>
|
||||
public delegate Task QueryAsyncEventHandler(Query q);
|
||||
|
||||
/// <summary>
|
||||
/// Event to be called when a batch is completed.
|
||||
/// </summary>
|
||||
public event Batch.BatchAsyncEventHandler BatchCompleted;
|
||||
|
||||
/// <summary>
|
||||
/// Delegate type for callback when a query connection fails
|
||||
/// </summary>
|
||||
/// <param name="q">The query that completed</param>
|
||||
/// <param name="message">Message to return</param>
|
||||
public delegate Task QueryAsyncErrorEventHandler(string message);
|
||||
|
||||
/// <summary>
|
||||
@@ -139,18 +142,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
{
|
||||
throw new InvalidOperationException("Query has not been executed.");
|
||||
}
|
||||
|
||||
return Batches.Select((batch, index) => new BatchSummary
|
||||
{
|
||||
Id = index,
|
||||
ExecutionStart = batch.ExecutionStartTimeStamp,
|
||||
ExecutionEnd = batch.ExecutionEndTimeStamp,
|
||||
ExecutionElapsed = batch.ExecutionElapsedTime,
|
||||
HasError = batch.HasError,
|
||||
Messages = batch.ResultMessages.ToArray(),
|
||||
ResultSetSummaries = batch.ResultSummaries,
|
||||
Selection = batch.Selection
|
||||
}).ToArray();
|
||||
return Batches.Select(b => b.Summary).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,12 +206,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
/// <returns>A subset of results</returns>
|
||||
public Task<ResultSetSubset> GetSubset(int batchIndex, int resultSetIndex, int startRow, int rowCount)
|
||||
{
|
||||
// Sanity check that the results are available
|
||||
if (!HasExecuted)
|
||||
{
|
||||
throw new InvalidOperationException(SR.QueryServiceSubsetNotCompleted);
|
||||
}
|
||||
|
||||
// Sanity check to make sure that the batch is within bounds
|
||||
if (batchIndex < 0 || batchIndex >= Batches.Length)
|
||||
{
|
||||
@@ -278,6 +264,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
// We need these to execute synchronously, otherwise the user will be very unhappy
|
||||
foreach (Batch b in Batches)
|
||||
{
|
||||
b.BatchCompletion += BatchCompleted;
|
||||
await b.Execute(conn, cancellationSource.Token);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user