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:
Benjamin Russell
2016-11-02 17:43:38 -07:00
committed by GitHub
parent d79842f24b
commit d5fbebc287
15 changed files with 487 additions and 196 deletions

View File

@@ -1,19 +1,20 @@
//
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.IO;
using System.Data.SqlClient;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.SmoMetadataProvider;
using Microsoft.SqlServer.Management.SqlParser.Binder;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
@@ -29,37 +30,61 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
{
public class Common
{
public const SelectionData WholeDocument = null;
public const string StandardQuery = "SELECT * FROM sys.objects";
#region Constants
public const string InvalidQuery = "SELECT *** FROM sys.objects";
public const string NoOpQuery = "-- No ops here, just us chickens.";
public const string UdtQuery = "SELECT hierarchyid::Parse('/')";
public const int Ordinal = 0;
public const string OwnerUri = "testFile";
public const int StandardRows = 5;
public const int StandardColumns = 5;
public static string TestServer { get; set; }
public const string StandardQuery = "SELECT * FROM sys.objects";
public static string TestDatabase { get; set; }
public const int StandardRows = 5;
static Common()
public const string UdtQuery = "SELECT hierarchyid::Parse('/')";
public const SelectionData WholeDocument = null;
public static readonly ConnectionDetails StandardConnectionDetails = new ConnectionDetails
{
TestServer = "sqltools11";
TestDatabase = "master";
}
DatabaseName = "123",
Password = "456",
ServerName = "789",
UserName = "012"
};
public static readonly SelectionData SubsectionDocument = new SelectionData(0, 0, 2, 2);
#endregion
public static Dictionary<string, string>[] StandardTestData
{
get { return GetTestData(StandardRows, StandardColumns); }
}
#region Public Methods
public static Batch GetBasicExecutedBatch()
{
Batch batch = new Batch(StandardQuery, SubsectionDocument, 1, GetFileStreamFactory());
batch.Execute(CreateTestConnection(new[] {StandardTestData}, false), CancellationToken.None).Wait();
return batch;
}
public static Query GetBasicExecutedQuery()
{
ConnectionInfo ci = CreateTestConnectionInfo(new[] {StandardTestData}, false);
Query query = new Query(StandardQuery, ci, new QueryExecutionSettings(), GetFileStreamFactory());
query.Execute();
query.ExecutionTask.Wait();
return query;
}
public static Dictionary<string, string>[] GetTestData(int columns, int rows)
{
Dictionary<string, string>[] output = new Dictionary<string, string>[rows];
@@ -76,26 +101,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
return output;
}
public static SelectionData GetSubSectionDocument()
{
return new SelectionData(0, 0, 2, 2);
}
public static Batch GetBasicExecutedBatch()
{
Batch batch = new Batch(StandardQuery, 0, 0, 2, 2, GetFileStreamFactory());
batch.Execute(CreateTestConnection(new[] {StandardTestData}, false), CancellationToken.None).Wait();
return batch;
}
public static Query GetBasicExecutedQuery()
{
ConnectionInfo ci = CreateTestConnectionInfo(new[] {StandardTestData}, false);
Query query = new Query(StandardQuery, ci, new QueryExecutionSettings(), GetFileStreamFactory());
query.Execute();
query.ExecutionTask.Wait();
return query;
}
#endregion
#region FileStreamWriteMocking
@@ -113,20 +119,30 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
public class InMemoryWrapper : IFileStreamWrapper
{
private readonly byte[] storage = new byte[8192];
private readonly MemoryStream memoryStream;
private bool readingOnly;
private readonly byte[] storage = new byte[8192];
public InMemoryWrapper()
{
memoryStream = new MemoryStream(storage);
}
public void Close()
{
memoryStream.Dispose();
}
public void Dispose()
{
// We'll dispose this via a special method
}
public void Flush()
{
if (readingOnly) { throw new InvalidOperationException(); }
}
public void Init(string fileName, int bufferSize, FileAccess fAccess)
{
readingOnly = fAccess == FileAccess.Read;
@@ -150,16 +166,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
memoryStream.Flush();
return bytes;
}
public void Flush()
{
if (readingOnly) { throw new InvalidOperationException(); }
}
public void Close()
{
memoryStream.Dispose();
}
}
#endregion
@@ -213,27 +219,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
public static ConnectionInfo CreateTestConnectionInfo(Dictionary<string, string>[][] data, bool throwOnRead)
{
// Create connection info
ConnectionDetails connDetails = new ConnectionDetails
{
UserName = "sa",
Password = "Yukon900",
DatabaseName = Common.TestDatabase,
ServerName = Common.TestServer
};
return new ConnectionInfo(CreateMockFactory(data, throwOnRead), OwnerUri, connDetails);
return new ConnectionInfo(CreateMockFactory(data, throwOnRead), OwnerUri, StandardConnectionDetails);
}
#endregion
#region Service Mocking
public static void GetAutoCompleteTestObjects(
out TextDocumentPosition textDocument,
out ScriptFile scriptFile,
out ConnectionInfo connInfo
)
)
{
textDocument = new TextDocumentPosition
{
@@ -245,6 +242,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
}
};
connInfo = CreateTestConnectionInfo(null, false);
var srvConn = GetServerConnection(connInfo);
var metadataProvider = SmoMetadataProvider.CreateConnectedProvider(srvConn);
var binder = BinderProvider.CreateBinder(metadataProvider);
connInfo = Common.CreateTestConnectionInfo(null, false);
LanguageService.Instance.ScriptParseInfoMap.Add(textDocument.TextDocument.Uri, new ScriptParseInfo());
@@ -259,17 +262,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
var sqlConnection = new SqlConnection(connectionString);
return new ServerConnection(sqlConnection);
}
public static ConnectionDetails GetTestConnectionDetails()
{
return new ConnectionDetails
{
DatabaseName = "123",
Password = "456",
ServerName = "789",
UserName = "012"
};
}
public static async Task<QueryExecutionService> GetPrimedExecutionService(ISqlConnectionFactory factory, bool isConnected, WorkspaceService<SqlToolsSettings> workspaceService)
{
@@ -278,7 +270,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
{
await connectionService.Connect(new ConnectParams
{
Connection = GetTestConnectionDetails(),
Connection = StandardConnectionDetails,
OwnerUri = OwnerUri
});
}
@@ -300,6 +292,5 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
}
#endregion
}
}