Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A powerful VS Code extension for querying multiple data sources with AI assistan

| Source | Language | Description |
|--------|----------|-------------|
| **Azure Data Explorer** | KQL | Query Kusto clusters with full IntelliSense and schema explorer |
| **Azure Data Explorer** | KQL | Query Kusto clusters with full IntelliSense and schema explorer. Supports both KQL queries and control commands (`.show`, `.alter`, `.create`, `.drop`) |
| **Azure DevOps** | WIQL | Query work items with preview panel showing description/repro steps |
| **Outlook** | OQL | Query local Outlook mail, calendar, contacts using KQL-like syntax |

Expand Down
7 changes: 7 additions & 0 deletions extension/resources/walkthrough/create-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ StormEvents
| take 100
```

### KQL Control Command
```kql
.show tables
```

Control commands (starting with `.`) are also supported — `.show version`, `.show database schema as json`, `.show operations`, etc.

### OQL Query
```oql
Inbox
Expand Down
21 changes: 18 additions & 3 deletions libs/MyTools.Core/KustoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,20 @@ public async Task<KustoResult> RunQueryAsync(
logAction?.Invoke($"Running query on {clusterName}:{database}");
}

// Detect if this is a control command (starts with '.')
var isControlCommand = query.TrimStart().StartsWith(".");

// Run the entire query execution on a background thread to avoid UI freezing
return await Task.Run(async () =>
{
var result = new KustoResult();
var rows = new List<string[]>();
ICslQueryProvider queryProvider = null;
ICslAdminProvider adminProvider = null;
IDataReader reader = null;

try
{
queryProvider = KustoClientFactory.CreateCslQueryProvider(kcsb);

var clientRequestProperties = new ClientRequestProperties
{
ClientRequestId = "MyKusto " + Guid.NewGuid(),
Expand All @@ -102,6 +104,7 @@ public async Task<KustoResult> RunQueryAsync(
{
reader?.Dispose();
queryProvider?.Dispose();
adminProvider?.Dispose();
logAction?.Invoke("Query cancellation requested - cleaning up resources");
}
catch
Expand All @@ -110,7 +113,18 @@ public async Task<KustoResult> RunQueryAsync(
}
}))
{
reader = await queryProvider.ExecuteQueryAsync(database, query, clientRequestProperties);
if (isControlCommand)
{
// Control commands (.show, .alter, .create, .drop, etc.) use the admin/mgmt endpoint
adminProvider = KustoClientFactory.CreateCslAdminProvider(kcsb);
reader = await adminProvider.ExecuteControlCommandAsync(database, query, clientRequestProperties);
}
else
{
// Regular KQL queries use the query endpoint
queryProvider = KustoClientFactory.CreateCslQueryProvider(kcsb);
reader = await queryProvider.ExecuteQueryAsync(database, query, clientRequestProperties);
}

cancellationToken.ThrowIfCancellationRequested();

Expand Down Expand Up @@ -150,6 +164,7 @@ public async Task<KustoResult> RunQueryAsync(
// Ensure resources are disposed even if an exception occurs
try { reader?.Dispose(); } catch { }
try { queryProvider?.Dispose(); } catch { }
try { adminProvider?.Dispose(); } catch { }
}

return result;
Expand Down
27 changes: 27 additions & 0 deletions server/Models/KustoDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,27 @@ public QueryExample[] GetExamples()
Description = "Create time series chart",
Query = "TableName\n| where Timestamp > ago(7d)\n| summarize count() by bin(Timestamp, 1h)\n| render timechart",
Category = "Visualization"
},
new QueryExample
{
Title = "Show Tables",
Description = "List all tables in the database",
Query = ".show tables",
Category = "Commands"
},
new QueryExample
{
Title = "Show Version",
Description = "Show the cluster version",
Query = ".show version",
Category = "Commands"
},
new QueryExample
{
Title = "Show Schema",
Description = "Show the database schema as JSON",
Query = ".show database schema as json",
Category = "Commands"
}
};
}
Expand All @@ -346,6 +367,12 @@ public QueryExample[] GetExamples()
5. Sort: | order by Column desc
6. Project columns: | project Col1, Col2, Col3

Control Commands (start with '.'):
7. .show tables — List all tables
8. .show version — Show cluster version
9. .show database schema as json — Show schema
10. .show operations — List recent operations

Press Ctrl+Space for autocomplete.";

// ============ IExternalViewer ============
Expand Down