private void MapIndexList(IDataReader kustoResults, IndexListResponseElement response) { while (kustoResults.Read()) { var termBucket = TermBucketFactory.CreateFromDataRecord(kustoResults); response.Aggregations.IndexCollection.AddBucket(termBucket); Logger.LogDebug("Found table/function: {@termBucket}", termBucket); } }
/// <summary> /// Executes a query to Kusto for Index List. /// Searches for all tables and all functions that match the index name pattern. /// </summary> /// <param name="indexName">Index name pattern, e.g. "*", "orders*", "orders".</param> /// <returns>A list of Indexes matching the given name pattern.</returns> public async Task <IndexListResponseElement> GetIndexListAsync(string indexName) { var response = new IndexListResponseElement(); try { Logger.LogDebug("Listing tables matching '{@indexName}'", indexName); var(databaseName, tableName) = KustoDatabaseTableNames.FromElasticIndexName(indexName, Kusto.DefaultDatabaseName); string readTablesCommand = $".show {KustoQLOperators.Databases} {KustoQLOperators.Schema} | {KustoQLOperators.Where} TableName != '' | {KustoQLOperators.Distinct} TableName, DatabaseName | {KustoQLOperators.Search} TableName: '{tableName}' | {KustoQLOperators.Search} DatabaseName: '{databaseName}' | {KustoQLOperators.Project} strcat(DatabaseName, \"{KustoDatabaseTableNames.Separator}\", TableName)"; using IDataReader kustoTables = await Kusto.ExecuteControlCommandAsync(readTablesCommand, RequestContext); if (kustoTables != null) { MapIndexList(kustoTables, response); } Logger.LogDebug("Listing functions matching '{@indexName}'", indexName); var defaultDb = Kusto.DefaultDatabaseName; string readFunctionsCommand = $".show {KustoQLOperators.Functions} | {KustoQLOperators.Where} Parameters == '()' | {KustoQLOperators.Distinct} Name | {KustoQLOperators.Search} Name: '{tableName}' | {KustoQLOperators.Project} strcat(\"{defaultDb}\", \"{KustoDatabaseTableNames.Separator}\", Name)"; using IDataReader kustoFunctions = await Kusto.ExecuteControlCommandAsync(readFunctionsCommand, RequestContext); if (kustoFunctions != null) { MapIndexList(kustoFunctions, response); } } catch (Exception ex) { Logger.LogError(ex, "Error while executing GetIndexList."); throw; } return(response); }