我想创建一个表,该表的名称来自查询结果。任何非常基本的示例都可以。结果可能是单列,也可能是单行。我只需要一个基本示例,即可根据需要进行调整和修改。
答案 0 :(得分:0)
任何创建表的控制命令都需要事先知道表名以及该命令文本的一部分。
您可以以编程方式运行两步流程,其中:
.create table
或.set
命令字符串(基于第一步),然后调用命令。使用.NET客户端库的示例:
using Kusto.Data;
using Kusto.Data.Common;
using Kusto.Data.Net.Client;
using System.Linq;
namespace Playground
{
class Program
{
static void Main(string[] args)
{
const string clusterName = "myClusterName";
const string regionName = "westus";
const string databaseName = "myDatabaseName";
const string queryForTableName = "MyExistingTable | summarize count() by TableName | top 1 by count_ desc | project TableName";
var kcsb = new KustoConnectionStringBuilder($"https://{clusterName}.{regionName}.kusto.windows.net", databaseName).WithAadUserPromptAuthentication();
using (var queryProvider = KustoClientFactory.CreateCslQueryProvider(kcsb))
{
// step 1: get the table name, based on the result of a query
var tableName = queryProvider.ExecuteQuery<string>(queryForTableName).Single();
using (var adminProvider = KustoClientFactory.CreateCslAdminProvider(kcsb))
{
// step 2.1: generate the control command's text, using the value from step 1
var createTableCommand = CslCommandGenerator.GenerateTableSetCommand(tableName, "print value = 'This is a value in my new table'", isAsync: false);
// step 2.2: invoke the control command
adminProvider.ExecuteControlCommand(createTableCommand);
}
}
}
}
}