From c366b391f0ed4376279437b02a4bf0faa474584b Mon Sep 17 00:00:00 2001 From: Basel Shaheen Date: Tue, 15 Dec 2020 18:24:17 +0200 Subject: [PATCH 1/4] Update DataClassificationAdapter.cs --- .../Services/DataClassificationAdapter.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs b/src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs index edf72dd529d3..d7b1e9129237 100644 --- a/src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs +++ b/src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs @@ -285,12 +285,16 @@ private static SensitivityLabel ToSensitivityLabel(SensitivityLabelModel sensiti private static SensitivityLabelModel ToSensitivityLabelModel(SensitivityLabel sensitivityLabel) { - string[] idComponents = sensitivityLabel.Id.Split('/'); + int indexOfSchema = sensitivityLabel.Id.IndexOf("/schemas/"); + int indexOfTables = sensitivityLabel.Id.IndexOf("/tables/"); + int indexOfColumns = sensitivityLabel.Id.IndexOf("/columns/"); + int indexOfSensitivityLabels = sensitivityLabel.Id.IndexOf("/sensitivityLabels/"); + return new SensitivityLabelModel { - SchemaName = idComponents[12], - TableName = idComponents[14], - ColumnName = idComponents[16], + SchemaName = sensitivityLabel.Id.Substring(indexOfSchema + 9, indexOfTables - indexOfSchema + 9), + TableName = sensitivityLabel.Id.Substring(indexOfTables + 8, indexOfColumns - indexOfTables + 8), + ColumnName = sensitivityLabel.Id.Substring(indexOfColumns + 9, indexOfSensitivityLabels - indexOfColumns + 8), SensitivityLabel = NullifyStringIfEmpty(sensitivityLabel.LabelName), SensitivityLabelId = NullifyStringIfEmpty(sensitivityLabel.LabelId), InformationType = NullifyStringIfEmpty(sensitivityLabel.InformationType), From 2863042812599307cf1251679a32d7580bc7698f Mon Sep 17 00:00:00 2001 From: bashahee Date: Tue, 15 Dec 2020 21:18:37 +0200 Subject: [PATCH 2/4] Update DataClassificationAdapter.cs --- .../Services/DataClassificationAdapter.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs b/src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs index d7b1e9129237..c53845719be0 100644 --- a/src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs +++ b/src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs @@ -285,16 +285,20 @@ private static SensitivityLabel ToSensitivityLabel(SensitivityLabelModel sensiti private static SensitivityLabelModel ToSensitivityLabelModel(SensitivityLabel sensitivityLabel) { - int indexOfSchema = sensitivityLabel.Id.IndexOf("/schemas/"); - int indexOfTables = sensitivityLabel.Id.IndexOf("/tables/"); - int indexOfColumns = sensitivityLabel.Id.IndexOf("/columns/"); - int indexOfSensitivityLabels = sensitivityLabel.Id.IndexOf("/sensitivityLabels/"); + const string schemas = "/schemas/"; + const string tables = "/tables/"; + const string columns = "/columns/"; + const string sensitivityLabels = "/sensitivityLabels/"; + int indexOfSchema = sensitivityLabel.Id.IndexOf(schemas); + int indexOfTables = sensitivityLabel.Id.IndexOf(tables); + int indexOfColumns = sensitivityLabel.Id.IndexOf(columns); + int indexOfSensitivityLabels = sensitivityLabel.Id.IndexOf(sensitivityLabels); return new SensitivityLabelModel { - SchemaName = sensitivityLabel.Id.Substring(indexOfSchema + 9, indexOfTables - indexOfSchema + 9), - TableName = sensitivityLabel.Id.Substring(indexOfTables + 8, indexOfColumns - indexOfTables + 8), - ColumnName = sensitivityLabel.Id.Substring(indexOfColumns + 9, indexOfSensitivityLabels - indexOfColumns + 8), + SchemaName = sensitivityLabel.Id.Substring(indexOfSchema + schemas.Length, indexOfTables - indexOfSchema - schemas.Length), + TableName = sensitivityLabel.Id.Substring(indexOfTables + tables.Length, indexOfColumns - indexOfTables - tables.Length), + ColumnName = sensitivityLabel.Id.Substring(indexOfColumns + columns.Length, indexOfSensitivityLabels - indexOfColumns - columns.Length), SensitivityLabel = NullifyStringIfEmpty(sensitivityLabel.LabelName), SensitivityLabelId = NullifyStringIfEmpty(sensitivityLabel.LabelId), InformationType = NullifyStringIfEmpty(sensitivityLabel.InformationType), From 8d3d340bf4dad470acc71b88de8bfb85adfc608c Mon Sep 17 00:00:00 2001 From: bashahee Date: Tue, 15 Dec 2020 21:20:03 +0200 Subject: [PATCH 3/4] Update ChangeLog.md --- src/Sql/Sql/ChangeLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Sql/Sql/ChangeLog.md b/src/Sql/Sql/ChangeLog.md index 71c6ad9ca37b..af72873bf284 100644 --- a/src/Sql/Sql/ChangeLog.md +++ b/src/Sql/Sql/ChangeLog.md @@ -19,6 +19,7 @@ --> ## Upcoming Release * Fixed parameter description for `InstanceFailoverGroup` command. +* SQL Data Classification commands - Updated the logic in which schemaName, tableName and columnName are being extracted from the id. ## Version 2.13.0 * Added SecondaryType to the following: From 744aa72bda986c357cceed7e40527d319f745ea9 Mon Sep 17 00:00:00 2001 From: bashahee Date: Wed, 16 Dec 2020 16:43:13 +0200 Subject: [PATCH 4/4] Update DataClassificationAdapter.cs --- .../Services/DataClassificationAdapter.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs b/src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs index c53845719be0..fb8141be4290 100644 --- a/src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs +++ b/src/Sql/Sql/DataClassification/Services/DataClassificationAdapter.cs @@ -285,20 +285,14 @@ private static SensitivityLabel ToSensitivityLabel(SensitivityLabelModel sensiti private static SensitivityLabelModel ToSensitivityLabelModel(SensitivityLabel sensitivityLabel) { - const string schemas = "/schemas/"; - const string tables = "/tables/"; - const string columns = "/columns/"; - const string sensitivityLabels = "/sensitivityLabels/"; - int indexOfSchema = sensitivityLabel.Id.IndexOf(schemas); - int indexOfTables = sensitivityLabel.Id.IndexOf(tables); - int indexOfColumns = sensitivityLabel.Id.IndexOf(columns); - int indexOfSensitivityLabels = sensitivityLabel.Id.IndexOf(sensitivityLabels); + var match = new global::System.Text.RegularExpressions.Regex("/schemas/(?.*)/tables/(?.*)/columns/(?.*)/sensitivityLabels/", + global::System.Text.RegularExpressions.RegexOptions.IgnoreCase).Match(sensitivityLabel.Id); return new SensitivityLabelModel { - SchemaName = sensitivityLabel.Id.Substring(indexOfSchema + schemas.Length, indexOfTables - indexOfSchema - schemas.Length), - TableName = sensitivityLabel.Id.Substring(indexOfTables + tables.Length, indexOfColumns - indexOfTables - tables.Length), - ColumnName = sensitivityLabel.Id.Substring(indexOfColumns + columns.Length, indexOfSensitivityLabels - indexOfColumns - columns.Length), + SchemaName = match.Groups["schemaName"].Value, + TableName = match.Groups["tableName"].Value, + ColumnName = match.Groups["columnName"].Value, SensitivityLabel = NullifyStringIfEmpty(sensitivityLabel.LabelName), SensitivityLabelId = NullifyStringIfEmpty(sensitivityLabel.LabelId), InformationType = NullifyStringIfEmpty(sensitivityLabel.InformationType),