Skip to content

Commit

Permalink
Dropped Ledger Columns folders for ledger primary tables (#1688)
Browse files Browse the repository at this point in the history
* dropped ledger columns strings, nodetypes, definition

* work in progress

* WIP- dropped columns folder showing for all tables

* Dropped Ledger Column folder only for primary ledger tables

* cleaning up

* undoing changes to kusto layer

* formatting

* undoing formatting

* undoing formatting

* removing IsLedger property and instead filtering on NodeTypeId

* updating column path test
  • Loading branch information
nofield authored Sep 15, 2022
1 parent fddf734 commit 8bdf1d8
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,14 @@ public static string SchemaHierarchy_ExternalTables
}
}

public static string SchemaHierarchy_DroppedLedgerColumns
{
get
{
return Keys.GetString(Keys.SchemaHierarchy_DroppedLedgerColumns);
}
}

public static string SchemaHierarchy_DroppedLedgerTables
{
get
Expand Down Expand Up @@ -10877,6 +10885,9 @@ public class Keys
public const string SchemaHierarchy_ExternalTables = "SchemaHierarchy_ExternalTables";


public const string SchemaHierarchy_DroppedLedgerColumns = "SchemaHierarchy_DroppedLedgerColumns";


public const string SchemaHierarchy_DroppedLedgerTables = "SchemaHierarchy_DroppedLedgerTables";


Expand Down
4 changes: 4 additions & 0 deletions src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,10 @@
<value>External Tables</value>
<comment></comment>
</data>
<data name="SchemaHierarchy_DroppedLedgerColumns" xml:space="preserve">
<value>Dropped Ledger Columns</value>
<comment></comment>
</data>
<data name="SchemaHierarchy_DroppedLedgerTables" xml:space="preserve">
<value>Dropped Ledger Tables</value>
<comment></comment>
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ SchemaHierarchy_ExternalResources = External Resources

SchemaHierarchy_ExternalTables = External Tables

SchemaHierarchy_DroppedLedgerColumns = Dropped Ledger Columns

SchemaHierarchy_DroppedLedgerTables = Dropped Ledger Tables

SchemaHierarchy_DroppedLedgerViews = Dropped Ledger Views
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -6331,6 +6331,11 @@ The Query Processor estimates that implementing the following index could improv
<target state="new">Dropped Ledger Views</target>
<note></note>
</trans-unit>
<trans-unit id="SchemaHierarchy_DroppedLedgerColumns">
<source>Dropped Ledger Columns</source>
<target state="new">Dropped Ledger Columns</target>
<note></note>
</trans-unit>
<trans-unit id="SqlProjectModelNotFound">
<source>Could not find SQL model from project: {0}.</source>
<target state="new">Could not find SQL model from project: {0}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public bool IsSorted
bool anyDroppedFolders = this.Any(
node => node is FolderNode &&
(node.NodeTypeId == NodeTypes.DroppedLedgerTables ||
node.NodeTypeId == NodeTypes.DroppedLedgerViews));
node.NodeTypeId == NodeTypes.DroppedLedgerViews ||
node.NodeTypeId == NodeTypes.DroppedLedgerColumns));
return this.FirstOrDefault() is SmoTreeNode && !anyDroppedFolders;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,6 @@ public enum NodeTypes
ColumnEncryptionKeys,
DroppedLedgerTables,
DroppedLedgerViews,
DroppedLedgerColumns,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private void OnExpandPopulateFoldersAndFilter(List<TreeNode> allChildren, TreeNo
{
allChildren.RemoveAll(x => x.IsSystemObject);
}

if (context != null && context.ValidFor != 0 && context.ValidFor != ValidForFlag.All)
{
allChildren.RemoveAll(x =>
Expand All @@ -64,6 +65,22 @@ private void OnExpandPopulateFoldersAndFilter(List<TreeNode> allChildren, TreeNo
}
return false;
});

// Remove the Dropped Ledger Columns folder if this isn't under a ledger table
allChildren.RemoveAll(x =>
{
if (x.NodeTypeId == NodeTypes.DroppedLedgerColumns)
{
Table? parentTable = context.Parent as Table;
if (parentTable == null ||
!(parentTable.LedgerType == LedgerTableType.UpdatableLedgerTable ||
parentTable.LedgerType == LedgerTableType.AppendOnlyLedgerTable))
{
return true;
}
}
return false;
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public override string GetNodeCustomName(object smoObject, SmoQueryContext smoCo
{
Name = "XmlDocumentConstraint",
ValidFor = ValidForFlag.NotSqlDw
},
new NodeSmoProperty
{
Name = "IsDroppedLedgerColumn",
ValidFor = ValidForFlag.Sql2022|ValidForFlag.AzureV12
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,34 @@ internal partial class ColumnsChildFactory : SmoChildFactoryBase
{
public override IEnumerable<string> ApplicableParents() { return new[] { "Columns" }; }

public override IEnumerable<INodeFilter> Filters
{
get
{
var filters = new List<INodeFilter>();
filters.Add(new NodePropertyFilter
{
Property = "IsDroppedLedgerColumn",
Type = typeof(bool),
ValidFor = ValidForFlag.Sql2022|ValidForFlag.AzureV12,
Values = new List<object> { 0 },
});
return filters;
}
}

protected override void OnExpandPopulateFolders(IList<TreeNode> currentChildren, TreeNode parent)
{
currentChildren.Add(new FolderNode {
NodeValue = SR.SchemaHierarchy_DroppedLedgerColumns,
NodeType = "Folder",
NodeTypeId = NodeTypes.DroppedLedgerColumns,
IsSystemObject = false,
ValidFor = ValidForFlag.Sql2022|ValidForFlag.AzureV12,
SortPriority = Int32.MaxValue,
});
}

internal override Type[] ChildQuerierTypes
{
get
Expand All @@ -1663,6 +1691,46 @@ public override TreeNode CreateChild(TreeNode parent, object context)
}
}

[Export(typeof(ChildFactory))]
[Shared]
internal partial class DroppedLedgerColumnsChildFactory : SmoChildFactoryBase
{
public override IEnumerable<string> ApplicableParents() { return new[] { "DroppedLedgerColumns" }; }

public override IEnumerable<INodeFilter> Filters
{
get
{
var filters = new List<INodeFilter>();
filters.Add(new NodePropertyFilter
{
Property = "IsDroppedLedgerColumn",
Type = typeof(bool),
ValidFor = ValidForFlag.Sql2022|ValidForFlag.AzureV12,
Values = new List<object> { 1 },
});
return filters;
}
}

internal override Type[] ChildQuerierTypes
{
get
{
return new [] { typeof(SqlColumnQuerier), };
}
}

public override TreeNode CreateChild(TreeNode parent, object context)
{
var child = new SmoTreeNode();
child.IsAlwaysLeaf = true;
child.NodeType = "Column";
InitializeChild(parent, child, context);
return child;
}
}

[Export(typeof(ChildFactory))]
[Shared]
internal partial class KeysChildFactory : SmoChildFactoryBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,19 @@
<Child Name="Statistics"/>
</Node>

<Node Name="Columns" LocLabel="SR.SchemaHierarchy_Columns" BaseClass="ModelBased" Strategy="PopulateParentDetails" NodeType="Column" ChildQuerierTypes="SqlColumn" DisableSort=""/>
<Node Name="Columns" LocLabel="SR.SchemaHierarchy_Columns" BaseClass="ModelBased" Strategy="PopulateParentDetails" NodeType="Column" ChildQuerierTypes="SqlColumn" DisableSort="">
<Filters>
<Filter Property="IsDroppedLedgerColumn" Value="0" Type="bool" ValidFor="Sql2022|AzureV12" />
</Filters>
<Child Name="DroppedLedgerColumns"/>
</Node>

<Node Name="DroppedLedgerColumns" LocLabel="SR.SchemaHierarchy_DroppedLedgerColumns" BaseClass="ModelBased" Strategy="PopulateParentDetails" NodeType="Column" ChildQuerierTypes="SqlColumn" ValidFor="Sql2022|AzureV12" SortPriority="Int32.MaxValue">
<Filters>
<Filter Property="IsDroppedLedgerColumn" Value="1" Type="bool" ValidFor="Sql2022|AzureV12" />
</Filters>
</Node>

<Node Name="Keys" LocLabel="SR.SchemaHierarchy_Keys" BaseClass="ModelBased" Strategy="ElementsInRelationship" NodeType="Key" ChildQuerierTypes="SqlIndex;SqlForeignKeyConstraint" ValidFor="NotSqlDw">
<Filters>
<Filter TypeToReverse="SqlIndex" Property="IndexKeyType" Type="Enum" ValidFor="AllOnPrem|AzureV12">
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.SqlTools.ServiceLayer/Scripting/ScripterCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ internal DataTable GetColumnNames(Server server, Urn urn, bool isDw)
filterExpressions.Add("@GeneratedAlwaysType=0");
}

// Check if we're called for EDIT for SQL2022+/Sterling+.
// We need to omit dropped ledger columns if such are present
if (server.Version.Major >= 16 || (DatabaseEngineType.SqlAzureDatabase == server.DatabaseEngineType && server.Version.Major >= 12))
{
filterExpressions.Add("@IsDroppedLedgerColumn=0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,29 @@ public void FindCorrectPathsForColumnWithServerRoot()
var expectedPaths = new List<string>
{
"testServer/Databases/testDatabase/Tables/testSchema.testTable/Columns/testColumn",
"testServer/Databases/testDatabase/Tables/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Tables/testSchema.testTable/Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Tables/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/Databases/testDatabase/Tables/System Tables/testSchema.testTable/Columns/testColumn",
"testServer/Databases/testDatabase/Tables/System Tables/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Tables/System Tables/testSchema.testTable/Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Tables/System Tables/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/Databases/testDatabase/Tables/Dropped Ledger Tables/testSchema.testTable/Columns/testColumn",
"testServer/Databases/testDatabase/Tables/Dropped Ledger Tables/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Tables/Dropped Ledger Tables/testSchema.testTable/Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Tables/Dropped Ledger Tables/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/Databases/testDatabase/Views/testSchema.testTable/Columns/testColumn",
"testServer/Databases/testDatabase/Views/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Views/testSchema.testTable/Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Views/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/Databases/testDatabase/Views/System Views/testSchema.testTable/Columns/testColumn",
"testServer/Databases/testDatabase/Views/System Views/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Views/System Views/testSchema.testTable/Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Views/System Views/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/Databases/testDatabase/Views/Dropped Ledger Views/testSchema.testTable/Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Views/Dropped Ledger Views/testSchema.testTable/Columns/testColumn"
"testServer/Databases/testDatabase/Views/Dropped Ledger Views/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Views/Dropped Ledger Views/testSchema.testTable/Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Views/Dropped Ledger Views/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn"
};

Assert.AreEqual(expectedPaths.Count, paths.Count);
Expand All @@ -112,11 +124,17 @@ public void FindCorrectPathsForColumnWithDatabaseRoot()
var expectedPaths = new List<string>
{
"testServer/testDatabase/Tables/testSchema.testTable/Columns/testColumn",
"testServer/testDatabase/Tables/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/testDatabase/Tables/System Tables/testSchema.testTable/Columns/testColumn",
"testServer/testDatabase/Tables/System Tables/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/testDatabase/Tables/Dropped Ledger Tables/testSchema.testTable/Columns/testColumn",
"testServer/testDatabase/Tables/Dropped Ledger Tables/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/testDatabase/Views/testSchema.testTable/Columns/testColumn",
"testServer/testDatabase/Views/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/testDatabase/Views/System Views/testSchema.testTable/Columns/testColumn",
"testServer/testDatabase/Views/Dropped Ledger Views/testSchema.testTable/Columns/testColumn"
"testServer/testDatabase/Views/System Views/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn",
"testServer/testDatabase/Views/Dropped Ledger Views/testSchema.testTable/Columns/testColumn",
"testServer/testDatabase/Views/Dropped Ledger Views/testSchema.testTable/Columns/Dropped Ledger Columns/testColumn"
};

Assert.AreEqual(expectedPaths.Count, paths.Count);
Expand Down

0 comments on commit 8bdf1d8

Please sign in to comment.