Cabazure.Kusto 1.0.0

dotnet add package Cabazure.Kusto --version 1.0.0                
NuGet\Install-Package Cabazure.Kusto -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Cabazure.Kusto" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Cabazure.Kusto --version 1.0.0                
#r "nuget: Cabazure.Kusto, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Cabazure.Kusto as a Cake Addin
#addin nuget:?package=Cabazure.Kusto&version=1.0.0

// Install Cabazure.Kusto as a Cake Tool
#tool nuget:?package=Cabazure.Kusto&version=1.0.0                

GitHub Actions Workflow Status GitHub Release Date NuGet Version NuGet Downloads

Branch Coverage Line Coverage Method Coverage

Cabazure.Kusto

Cabazure.Kusto is a library for handling and executing Kusto scripts against an Azure Data Explorer cluster.

The library extents the official .NET SDK, and adds functionality for:

  • Handling embedded .kusto scripts in your .NET projects
  • Passing parameters to your .kusto scripts
  • Deserialization of query results
  • Pagination using stored query results

Getting started

1. Configuring the Cabazure.Kusto library

The Cabazure.Kusto is initialized by calling the AddCabazureKusto() on the IServiceCollection during startup of your application, like this:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddCabazureKusto(o =>
{
    o.HostAddress = "https://help.kusto.windows.net/";
    o.DatabaseName = "ContosoSales";
    o.Credential = new DefaultAzureCredential();
});

Note: The CabazureKustoOptions can also be configured using the Microsoft.Extensions.Options framework, by registering an implementation of IConfigureOptions<CabazureKustoOptions>. In this case, it can be omitted on the AddCabazureKusto() call.

2. Adding a Kusto query

A Kusto query is added by creating two files to your project:

  • A .kusto script file containing the Kusto query itself, added with "Build Action" set to "Embedded resource"
  • A .NET record with the same name (and namespace) as the embedded .kusto script.

The .NET record should to derive from one of the following base types:

Base type Description
KustoCommand Used for Kusto commands that do not produce an output.
KustoQuery<T> Used for Kusto queries that returns a result.

Note: The base types handles the loading of the embedded .kusto script file, passing of parameters and deserialization of the output.

Parameters are specified by adding them to record, and declare them at the top of the .kusto script, like this:

// file: CustomerQuery.cs
public record CustomerQuery(
  string CustomerType)
  : KustoQuery<Customer>;
// file: CustomerQuery.kusto
declare query_parameters (
    customerType:string)
;
Customers
| where type == customerType
| project
    customerId,
    name,
    type,
    lastUpdated = timestamp,

The query result is mapped to the specified output contract, my matching parameter names like this:

// file: Customer.cs
public record Customer(
  string CustomerId,
  string Name,
  CustomerType Type,
  DateTimeOffset LastUpdated);

3. Execute a Kusto query

Kusto scripts can be executed using the IKustoProcessor registered in the Dependency Injection container, like this:

app.MapGet(
  "/customers",
  (IKustoProcessor processor, CancellationToken cancellationToken)
    => processor
      .ExecuteAsync(
        new CustomerQuery("type"),
        cancellationToken));

The processor can also perform pagination by using the ExecuteAsync overload, taking in a session id, a continuation token and a max item count, like this:

app.MapGet(
  "/customers",
  ([FromHeader(Name = "x-max-item-count")] int? maxItemCount,
  [FromHeader(Name = "x-continuation")] string? continuation,
  [FromHeader(Name = "x-session-id")] string? sessionId,
  IKustoProcessor processor,
  CancellationToken cancellationToken)
    => processor
      .ExecuteAsync(
        new CustomerQuery("type"),
        sessionId,
        maxItemCount,
        continuationToken,
        cancellationToken));

The maxItemCount specifies how many items to return for each page. Each page is returned with a continuationToken that can be specified to fetch the next page.

The optional sessionId can be provided to optimize the use of storage on the ADX. If the same sessionId is specified for two calls they will share the underlying storage for pagination results.

Sample

Please see the SampleApi project, for an example of how Cabazure.Kusto can be setup to query the "ContosoSales" database of the ADX sample cluster.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 72 11/19/2024
0.3.0 110 10/11/2024