From 454e4a4671c7f5c3fbc2f8541d023913f58ecfa1 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Fri, 8 Apr 2022 15:20:54 -0700 Subject: [PATCH] Adding node overlays to execution plans (#1451) * Adding node overlays to execution plans * Adding critical warnings and parallelism * adding critical warning, badge type enum * Renaming badge type class * Adding explicit values to Badge Type --- .../Contracts/ExecutionPlanGraph.cs | 24 +++++++++++++ .../ExecutionPlan/ExecutionPlanGraphUtils.cs | 35 +++++++++++++++++++ .../ExecutionPlan/ShowPlan/Node.cs | 2 +- .../Localization/sr.cs | 22 ++++++++++++ .../Localization/sr.resx | 8 +++++ .../Localization/sr.strings | 5 ++- .../Localization/sr.xlf | 10 ++++++ 7 files changed, 104 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/Contracts/ExecutionPlanGraph.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/Contracts/ExecutionPlanGraph.cs index ac27249d..3590bcd6 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/Contracts/ExecutionPlanGraph.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/Contracts/ExecutionPlanGraph.cs @@ -74,6 +74,10 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.Contracts public string[] Subtext { get; set; } public List Children { get; set; } public List Edges { get; set; } + /// + /// Add badge icon to nodes like warnings and parallelism + /// + public List Badges { get; set; } } public class ExecutionPlanGraphPropertyBase @@ -161,4 +165,24 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.Contracts /// public string GraphFileType { get; set; } } + + public class Badge + { + /// + /// Type of the node overlay. This determines the icon that is displayed for it + /// + public BadgeType Type { get; set; } + + /// + /// Text to display for the overlay tooltip + /// + public string Tooltip { get; set; } + } + + public enum BadgeType + { + WARNING = 0, + CRITICALWARNING = 1, + PARALLELISM = 2 + } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ExecutionPlanGraphUtils.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ExecutionPlanGraphUtils.cs index b4978ad3..1d71d3ee 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ExecutionPlanGraphUtils.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ExecutionPlanGraphUtils.cs @@ -46,11 +46,46 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan Properties = GetProperties(currentNode.Properties), Children = currentNode.Children.Select(x => ConvertShowPlanTreeToExecutionPlanTree(x)).ToList(), Edges = currentNode.Edges.Select(x => ConvertShowPlanEdgeToExecutionPlanEdge(x)).ToList(), + Badges = GenerateNodeOverlay(currentNode), Name = currentNode.DisplayName, ElapsedTimeInMs = currentNode.ElapsedTimeInMs }; } + public static List GenerateNodeOverlay(Node currentNode) + { + List overlays = new List(); + + if (currentNode.HasWarnings) + { + if (currentNode.HasCriticalWarnings) + { + overlays.Add(new Badge + { + Type = BadgeType.CRITICALWARNING, + Tooltip = SR.WarningOverlayTooltip + }); + } + else + { + overlays.Add(new Badge + { + Type = BadgeType.WARNING, + Tooltip = SR.WarningOverlayTooltip + }); + } + } + if (currentNode.IsParallel) + { + overlays.Add(new Badge + { + Type = BadgeType.PARALLELISM, + Tooltip = SR.ParallelismOverlayTooltip + }); + } + return overlays; + } + public static ExecutionPlanEdges ConvertShowPlanEdgeToExecutionPlanEdge(Edge edge) { return new ExecutionPlanEdges diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Node.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Node.cs index 740dd41f..57b0f5d9 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Node.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Node.cs @@ -161,7 +161,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan /// /// Gets the value that indicates whether the Node has critical warnings. /// - private bool HasCriticalWarnings + public bool HasCriticalWarnings { get { diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs index fbfa8477..f31d7669 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs @@ -8445,6 +8445,22 @@ namespace Microsoft.SqlTools.ServiceLayer } } + public static string WarningOverlayTooltip + { + get + { + return Keys.GetString(Keys.WarningOverlayTooltip); + } + } + + public static string ParallelismOverlayTooltip + { + get + { + return Keys.GetString(Keys.ParallelismOverlayTooltip); + } + } + public static string TableEditPathNotProvidedException { get @@ -12664,6 +12680,12 @@ namespace Microsoft.SqlTools.ServiceLayer public const string MissingIndexDetailsTitle = "MissingIndexDetailsTitle"; + public const string WarningOverlayTooltip = "WarningOverlayTooltip"; + + + public const string ParallelismOverlayTooltip = "ParallelismOverlayTooltip"; + + public const string TableNotInitializedException = "TableNotInitializedException"; diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx index 233a660f..51ba6d1d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx @@ -4619,6 +4619,14 @@ The Query Processor estimates that implementing the following index could improv title of missing index details. Parameters: 0 - fileName (string), 1 - impact (string) + + Warnings + tooltip text for node warning overlay + + + Parallel Execution + tooltip text for node parallelism overlay + Initialization is not properly done for table with id '{0}' . diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings index 11b0c30c..0259dbb6 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings @@ -2223,7 +2223,10 @@ ActualOfEstimated(string actual, string estimated, decimal percent) = {0} of\n{1 MissingIndexFormat(string impact, string queryText) = Missing Index (Impact {0}): {1} ;title of missing index details MissingIndexDetailsTitle(string fileName, string impact) = /*\r\nMissing Index Details from {0}\r\nThe Query Processor estimates that implementing the following index could improve the query cost by {1}%.\r\n*/ - +;tooltip text for node warning overlay +WarningOverlayTooltip = Warnings +;tooltip text for node parallelism overlay +ParallelismOverlayTooltip = Parallel Execution ############################################################################ # Table Designer diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf index 12830ce1..7e42651f 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf @@ -5993,6 +5993,16 @@ The Query Processor estimates that implementing the following index could improv New Clause + + Warnings + Warnings + tooltip text for node warning overlay + + + Parallel Execution + Parallel Execution + tooltip text for node parallelism overlay + \ No newline at end of file