diff --git a/docs/en-US/New-KustoColumnMapping.md b/docs/en-US/New-KustoColumnMapping.md index 3ca7b6b..4581ff4 100644 --- a/docs/en-US/New-KustoColumnMapping.md +++ b/docs/en-US/New-KustoColumnMapping.md @@ -9,7 +9,7 @@ schema: 2.0.0 ## SYNOPSIS -{{ Fill in the Synopsis }} +Creates a `ColumnMapping` object. ## SYNTAX diff --git a/docs/en-US/Set-KustoBatchingPolicy.md b/docs/en-US/Set-KustoBatchingPolicy.md new file mode 100644 index 0000000..6c2cc51 --- /dev/null +++ b/docs/en-US/Set-KustoBatchingPolicy.md @@ -0,0 +1,192 @@ +--- +external help file: PowerShellKusto.dll-Help.xml +Module Name: PowerShellKusto +online version: https://github.com/santisq/PowerShellKusto/blob/main/docs/en-US/Set-KustoBatchingPolicy.md +schema: 2.0.0 +--- + +# Set-KustoBatchingPolicy + +## SYNOPSIS + +{{ Fill in the Synopsis }} + +## SYNTAX + +```powershell +Set-KustoBatchingPolicy + [-Table] + [-Database ] + [-MaximumBatchingTimeSpan ] + [-MaximumNumberOfItems ] + [-MaximumRawDataSizeMB ] + [[-OutputType] ] + [-RequestProperties ] + [] +``` + +## DESCRIPTION + +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 + +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Database + +{{ Fill Database Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MaximumBatchingTimeSpan + +{{ Fill MaximumBatchingTimeSpan Description }} + +```yaml +Type: TimeSpan +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MaximumNumberOfItems + +{{ Fill MaximumNumberOfItems Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MaximumRawDataSizeMB + +{{ Fill MaximumRawDataSizeMB Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OutputType + +{{ Fill OutputType Description }} + +```yaml +Type: OutputType +Parameter Sets: (All) +Aliases: +Accepted values: PSObject, Json, Csv, DataTable, Html + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RequestProperties + +{{ Fill RequestProperties Description }} + +```yaml +Type: ClientRequestProperties +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Table + +{{ Fill Table Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ProgressAction + +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters + +This cmdlet supports the common parameters. +For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Management.Automation.PSObject + +### System.String + +### System.Data.DataTable + +## NOTES + +## RELATED LINKS diff --git a/docs/en-US/Set-KustoIngestionMapping.md b/docs/en-US/Set-KustoIngestionMapping.md new file mode 100644 index 0000000..a444e16 --- /dev/null +++ b/docs/en-US/Set-KustoIngestionMapping.md @@ -0,0 +1,192 @@ +--- +external help file: PowerShellKusto.dll-Help.xml +Module Name: PowerShellKusto +online version: https://github.com/santisq/PowerShellKusto/blob/main/docs/en-US/Set-KustoIngestionMapping.md +schema: 2.0.0 +--- + +# Set-KustoIngestionMapping + +## SYNOPSIS + +{{ Fill in the Synopsis }} + +## SYNTAX + +```powershell +Set-KustoIngestionMapping + [-MappingName] + [-Table] + [[-Database] ] + -IngestionMapping + [-RemoveOldestIfRequired] + [[-OutputType] ] + [-RequestProperties ] + [] +``` + +## DESCRIPTION + +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 + +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Database + +{{ Fill Database Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -IngestionMapping + +{{ Fill IngestionMapping Description }} + +```yaml +Type: IngestionMapping +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -MappingName + +{{ Fill MappingName Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OutputType + +{{ Fill OutputType Description }} + +```yaml +Type: OutputType +Parameter Sets: (All) +Aliases: +Accepted values: PSObject, Json, Csv, DataTable, Html + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RemoveOldestIfRequired + +{{ Fill RemoveOldestIfRequired Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RequestProperties + +{{ Fill RequestProperties Description }} + +```yaml +Type: ClientRequestProperties +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Table + +{{ Fill Table Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ProgressAction + +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters + +This cmdlet supports the common parameters. +For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Management.Automation.PSObject + +### System.String + +### System.Data.DataTable + +## NOTES + +## RELATED LINKS diff --git a/module/PowerShellKusto.psd1 b/module/PowerShellKusto.psd1 index ee9b7df..0ac072c 100644 --- a/module/PowerShellKusto.psd1 +++ b/module/PowerShellKusto.psd1 @@ -80,6 +80,8 @@ 'New-KustoIngestionMapping' 'New-KustoColumnMapping' 'New-KustoClientRequestProperties' + 'Set-KustoBatchingPolicy' + 'Set-KustoIngestionMapping' ) # Variables to export from this module diff --git a/src/PowerShellKusto/Commands/InvokeKustoControlCommandCommand.cs b/src/PowerShellKusto/Commands/InvokeKustoControlCommandCommand.cs index a8a11c0..0005893 100644 --- a/src/PowerShellKusto/Commands/InvokeKustoControlCommandCommand.cs +++ b/src/PowerShellKusto/Commands/InvokeKustoControlCommandCommand.cs @@ -30,7 +30,7 @@ protected override void EndProcessing() } catch (Exception exception) { - ErrorRecord error = new(exception, "CommandError", ErrorCategory.SecurityError, null); + ErrorRecord error = new(exception, "CommandError", ErrorCategory.NotSpecified, null); WriteError(error); } } diff --git a/src/PowerShellKusto/Commands/SetKustoBatchingPolicyCommand.cs b/src/PowerShellKusto/Commands/SetKustoBatchingPolicyCommand.cs new file mode 100644 index 0000000..800eed1 --- /dev/null +++ b/src/PowerShellKusto/Commands/SetKustoBatchingPolicyCommand.cs @@ -0,0 +1,58 @@ +using System; +using System.Data; +using System.Management.Automation; +using Kusto.Data; +using Kusto.Data.Common; +using Kusto.Data.Net.Client; + +namespace PowerShellKusto.Commands; + +[Cmdlet(VerbsCommon.Set, "KustoBatchingPolicy")] +[OutputType(typeof(PSObject), typeof(string), typeof(DataTable))] +public sealed class SetKustoBatchingPolicyCommand : KustoReaderCommandBase +{ + [Parameter(Mandatory = true, Position = 0)] + public string Table { get; set; } = null!; + + [Parameter] + [ValidateNotNullOrEmpty] + public string? Database { get; set; } + + [Parameter] + [ValidateTimespan] + public TimeSpan MaximumBatchingTimeSpan { get; set; } = TimeSpan.FromSeconds(10); + + [Parameter] + [ValidateRange(1, int.MaxValue)] + public int MaximumNumberOfItems { get; set; } = 100; + + [Parameter] + [ValidateRange(1, int.MaxValue)] + public int MaximumRawDataSizeMB { get; set; } = 1024; + + protected override void EndProcessing() + { + try + { + using ICslAdminProvider client = KustoClientFactory.CreateCslAdminProvider(Builder); + string command = CslCommandGenerator.GenerateTableAlterIngestionBatchingPolicyCommand( + databaseName: Database ?? Builder?.InitialCatalog, + tableName: Table, + ingestionBatchingPolicy: new IngestionBatchingPolicy( + maximumBatchingTimeSpan: MaximumBatchingTimeSpan, + maximumNumberOfItems: MaximumNumberOfItems, + maximumRawDataSizeMB: MaximumRawDataSizeMB)); + + using IDataReader reader = RequestProperties is null + ? client.ExecuteControlCommand(command) + : client.ExecuteControlCommand(command, RequestProperties); + + HandleReader(reader); + } + catch (Exception exception) + { + ErrorRecord error = new(exception, "CommandError", ErrorCategory.NotSpecified, null); + WriteError(error); + } + } +} diff --git a/src/PowerShellKusto/Commands/SetKustoIngestionMappingCommand.cs b/src/PowerShellKusto/Commands/SetKustoIngestionMappingCommand.cs new file mode 100644 index 0000000..599de21 --- /dev/null +++ b/src/PowerShellKusto/Commands/SetKustoIngestionMappingCommand.cs @@ -0,0 +1,54 @@ +using System; +using System.Data; +using System.Management.Automation; +using Kusto.Data.Common; +using Kusto.Data.Net.Client; +using Kusto.Ingest; + +namespace PowerShellKusto.Commands; + +[Cmdlet(VerbsCommon.Set, "KustoIngestionMapping")] +[OutputType(typeof(PSObject), typeof(string), typeof(DataTable))] +public sealed class SetKustoIngestionMappingCommand : KustoReaderCommandBase +{ + [Parameter(Mandatory = true, Position = 0)] + public string MappingName { get; set; } = null!; + + [Parameter(Mandatory = true, Position = 1)] + public string Table { get; set; } = null!; + + [Parameter(Position = 2)] + public string? Database { get; set; } + + [Parameter(Mandatory = true)] + public IngestionMapping IngestionMapping { get; set; } = null!; + + [Parameter] + public SwitchParameter RemoveOldestIfRequired { get; set; } + + protected override void EndProcessing() + { + try + { + string? database = Database ?? Builder?.InitialCatalog; + using ICslAdminProvider client = KustoClientFactory.CreateCslAdminProvider(Builder); + string command = CslCommandGenerator.GenerateTableMappingCreateCommand( + mappingKind: IngestionMapping.IngestionMappingKind, + entityName: Table, + mappingName: MappingName, + mapping: IngestionMapping.IngestionMappings, + removeOldestIfRequired: RemoveOldestIfRequired); + + using IDataReader reader = RequestProperties is null + ? client.ExecuteControlCommand(database, command) + : client.ExecuteControlCommand(database, command, RequestProperties); + + HandleReader(reader); + } + catch (Exception exception) + { + ErrorRecord error = new(exception, "CommandError", ErrorCategory.NotSpecified, null); + WriteError(error); + } + } +}