mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-29 01:25:41 -05:00
Adds new graph comparison request handler to the Execution Plan Service. (#1438)
* Adds new graph comparison request handler to the Execution Plan Service. * Code review changes * Renames execution plan compare params, result, and request classes.
This commit is contained in:
@@ -6,12 +6,15 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ExecutionPlan.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan;
|
||||
using Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan.Comparison;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan
|
||||
{
|
||||
/// <summary>
|
||||
/// Main class for Migration Service functionality
|
||||
/// Main class for Execution Plan Service functionality
|
||||
/// </summary>
|
||||
public sealed class ExecutionPlanService : IDisposable
|
||||
{
|
||||
@@ -20,9 +23,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan
|
||||
private bool disposed;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new MigrationService instance with default parameters
|
||||
/// Construct a new Execution Plan Service instance with default parameters
|
||||
/// </summary>
|
||||
public ExecutionPlanService()
|
||||
private ExecutionPlanService()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -38,26 +41,23 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan
|
||||
/// Service host object for sending/receiving requests/events.
|
||||
/// Internal for testing purposes.
|
||||
/// </summary>
|
||||
internal IProtocolEndpoint ServiceHost
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
internal IProtocolEndpoint ServiceHost { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the ShowPlan Service instance
|
||||
/// Initializes the Execution Plan Service instance
|
||||
/// </summary>
|
||||
public void InitializeService(ServiceHost serviceHost)
|
||||
{
|
||||
this.ServiceHost = serviceHost;
|
||||
this.ServiceHost.SetRequestHandler(GetExecutionPlanRequest.Type, HandleGetExecutionPlan);
|
||||
ServiceHost = serviceHost;
|
||||
ServiceHost.SetRequestHandler(GetExecutionPlanRequest.Type, HandleGetExecutionPlan);
|
||||
ServiceHost.SetRequestHandler(ExecutionPlanComparisonRequest.Type, HandleExecutionPlanComparisonRequest);
|
||||
}
|
||||
|
||||
private async Task HandleGetExecutionPlan(GetExecutionPlanParams requestParams, RequestContext<GetExecutionPlanResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var plans = ShowPlanGraphUtils.CreateShowPlanGraph(requestParams.GraphInfo.GraphFileContent, "");
|
||||
var plans = ExecutionPlanGraphUtils.CreateShowPlanGraph(requestParams.GraphInfo.GraphFileContent, "");
|
||||
await requestContext.SendResult(new GetExecutionPlanResult
|
||||
{
|
||||
Graphs = plans
|
||||
@@ -70,7 +70,46 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the ShowPlan Service
|
||||
/// Handles requests for color matching similar nodes.
|
||||
/// </summary>
|
||||
internal async Task HandleExecutionPlanComparisonRequest(
|
||||
ExecutionPlanComparisonParams requestParams,
|
||||
RequestContext<ExecutionPlanComparisonResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var firstGraphSet = ShowPlanGraph.ParseShowPlanXML(requestParams.FirstExecutionPlanGraphInfo.GraphFileContent, ShowPlanType.Unknown);
|
||||
var firstRootNode = firstGraphSet?[0]?.Root;
|
||||
|
||||
var secondGraphSet = ShowPlanGraph.ParseShowPlanXML(requestParams.SecondExecutionPlanGraphInfo.GraphFileContent, ShowPlanType.Unknown);
|
||||
var secondRootNode = secondGraphSet?[0]?.Root;
|
||||
|
||||
var manager = new SkeletonManager();
|
||||
var firstSkeletonNode = manager.CreateSkeleton(firstRootNode);
|
||||
var secondSkeletonNode = manager.CreateSkeleton(secondRootNode);
|
||||
manager.ColorMatchingSections(firstSkeletonNode, secondSkeletonNode, requestParams.IgnoreDatabaseName);
|
||||
|
||||
var firstGraphComparisonResultDTO = firstSkeletonNode.ConvertToDTO();
|
||||
var secondGraphComparisonResultDTO = secondSkeletonNode.ConvertToDTO();
|
||||
ExecutionPlanGraphUtils.CopyMatchingNodesIntoSkeletonDTO(firstGraphComparisonResultDTO, secondGraphComparisonResultDTO);
|
||||
ExecutionPlanGraphUtils.CopyMatchingNodesIntoSkeletonDTO(secondGraphComparisonResultDTO, firstGraphComparisonResultDTO);
|
||||
|
||||
var result = new ExecutionPlanComparisonResult()
|
||||
{
|
||||
FirstComparisonResult = firstGraphComparisonResultDTO,
|
||||
SecondComparisonResult = secondGraphComparisonResultDTO
|
||||
};
|
||||
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the Execution Plan Service
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user