mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Changed logic around loading tables in MonitorDataSource. Added DisplayName to TableGroupsModel (#1225)
This commit is contained in:
@@ -41,46 +41,36 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource.Monitor
|
|||||||
{
|
{
|
||||||
var workspace = _metadata.Workspaces.First(x => x.Id == workspaceId);
|
var workspace = _metadata.Workspaces.First(x => x.Id == workspaceId);
|
||||||
DatabaseName = $"{workspace.Name} ({workspace.Id})";
|
DatabaseName = $"{workspace.Name} ({workspace.Id})";
|
||||||
var metadataTableGroups = _metadata.TableGroups.ToDictionary(x => x.Id);
|
|
||||||
|
|
||||||
foreach (string workspaceTableGroup in workspace.TableGroups)
|
var tableGroups = _metadata.TableGroups.Where(x => workspace.TableGroups.Contains(x.Id));
|
||||||
{
|
|
||||||
var tableGroup = metadataTableGroups[workspaceTableGroup];
|
|
||||||
|
|
||||||
|
foreach (TableGroupsModel workspaceTableGroup in tableGroups)
|
||||||
|
{
|
||||||
|
var name = workspaceTableGroup.DisplayName ?? workspaceTableGroup.Name;
|
||||||
var tableGroupNodeInfo =
|
var tableGroupNodeInfo =
|
||||||
MetadataFactory.CreateDataSourceObjectMetadata(DataSourceMetadataType.Folder, tableGroup.Name, $"{workspace.Id}.{tableGroup.Name}");
|
MetadataFactory.CreateDataSourceObjectMetadata(DataSourceMetadataType.Folder, name, $"{workspace.Id}.{name}");
|
||||||
|
|
||||||
_nodes.SafeAdd($"{workspace.Id}", tableGroupNodeInfo);
|
_nodes.SafeAdd($"{workspace.Id}", tableGroupNodeInfo);
|
||||||
|
|
||||||
SetupTables(tableGroupNodeInfo);
|
SetupTables(tableGroupNodeInfo, workspaceTableGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupTables(DataSourceObjectMetadata tableGroupNodeInfo)
|
private void SetupTables(DataSourceObjectMetadata tableGroupNodeInfo, TableGroupsModel workspaceTableGroup)
|
||||||
{
|
{
|
||||||
var tables = GetNonEmptyTableNames();
|
var tableGroupTables = _metadata.Tables.Where(x => workspaceTableGroup.Tables.Contains(x.Id));
|
||||||
var metadataTables = _metadata.Tables.ToDictionary(x => x.Name);
|
|
||||||
|
|
||||||
foreach (string tableName in tables)
|
foreach (TablesModel metadataTable in tableGroupTables)
|
||||||
{
|
{
|
||||||
var table = metadataTables[tableName];
|
var tableNodeInfo = MetadataFactory.CreateDataSourceObjectMetadata(DataSourceMetadataType.Table, metadataTable.Name,
|
||||||
|
$"{tableGroupNodeInfo.Urn}.{metadataTable.Name}");
|
||||||
var tableNodeInfo = MetadataFactory.CreateDataSourceObjectMetadata(DataSourceMetadataType.Table, table.Name,
|
|
||||||
$"{tableGroupNodeInfo.Urn}.{table.Name}");
|
|
||||||
|
|
||||||
_nodes.SafeAdd(tableGroupNodeInfo.Urn, tableNodeInfo);
|
_nodes.SafeAdd(tableGroupNodeInfo.Urn, tableNodeInfo);
|
||||||
|
|
||||||
SetupColumns(table, tableNodeInfo);
|
SetupColumns(metadataTable, tableNodeInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<string> GetNonEmptyTableNames()
|
|
||||||
{
|
|
||||||
string query = "union * | summarize count() by Type";
|
|
||||||
var results = _monitorClient.Query(query);
|
|
||||||
return results.Tables[0].Rows.Select(x => x[0]).OrderBy(x => x);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetupColumns(TablesModel table, DataSourceObjectMetadata tableNodeInfo)
|
private void SetupColumns(TablesModel table, DataSourceObjectMetadata tableNodeInfo)
|
||||||
{
|
{
|
||||||
foreach (var column in table.Columns)
|
foreach (var column in table.Columns)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource.Monitor.Responses.Models
|
|||||||
{
|
{
|
||||||
public class TableGroupsModel
|
public class TableGroupsModel
|
||||||
{
|
{
|
||||||
|
public string DisplayName { get; set; }
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Source { get; set; }
|
public string Source { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user