Skip to content

Commit

Permalink
almost done with docs
Browse files Browse the repository at this point in the history
  • Loading branch information
santisq committed Dec 24, 2024
1 parent 2f1dc69 commit f4abd1f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/en-US/New-KustoIngestionMapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Accept wildcard characters: False
### -Kind
Specifies the type of mapping. __Default value is `Unknown`__.
Specifies the type of mapping. __Default value is `Csv`__.

```yaml
Type: IngestionMappingKind
Expand Down
73 changes: 54 additions & 19 deletions docs/en-US/Set-KustoIngestionMapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,63 @@ schema: 2.0.0

## SYNOPSIS

{{ Fill in the Synopsis }}
Creates or updates an ingestion mapping that can be associated with a specific format and a specific table or database.

## SYNTAX

```powershell
Set-KustoIngestionMapping
[-MappingName] <String>
[-Table] <String>
[-Name] <String>
[[-Table] <String>]
[[-Database] <String>]
-IngestionMapping <IngestionMapping>
[-RemoveOldestIfRequired]
-Mapping <IngestionMapping>
[-Force]
[-OutputType <OutputType>]
[-RequestProperties <ClientRequestProperties>]
[<CommonParameters>]
```

## DESCRIPTION

{{ Fill in the Description }}
The `Set-KustoIngestionMapping` cmdlet can be used to create or update an ingestion mapping that can be associated with a specific format and a specific table or database. For more information see [__.create ingestion mapping command__](https://learn.microsoft.com/en-us/kusto/management/create-ingestion-mapping-command?view=microsoft-fabric)
and [__.create-or-alter ingestion mapping command__](https://learn.microsoft.com/en-us/kusto/management/create-or-alter-ingestion-mapping-command?view=microsoft-fabric).

## EXAMPLES

### Example 1
### Example 1: Creates a new ingestion mapping on a Table

```powershell
PS C:\> {{ Add example code here }}
$mapping = New-KustoIngestionMapping -Columns $columns -Kind Json
Set-KustoIngestionMapping myNewMapping -Table myTable -Mapping $mapping
```

{{ Add example description here }}
This example demonstrates how to create a new `Json` mapping with name `myNewMapping` on `myTable` in a Database specified by `Connect-Kusto -Database`.

### Example 2: Creates a new ingestion mapping on a Database

```powershell
$mapping = New-KustoIngestionMapping -Columns $columns
Set-KustoIngestionMapping myNewMapping -Database myDb -Mapping $mapping
```

This example demonstrates how to create a new `Csv` mapping with name `myNewMapping` on `myDb`.

> [!TIP]
>
> When `-Table` isn't specified, the mapping is created at Database level.
### Example 3: Update an ingestion mapping on a Database

```powershell
$mapping = New-KustoIngestionMapping -Columns $columns
Set-KustoIngestionMapping myNewMapping -Database myDb -Mapping $mapping -Force
```

## PARAMETERS

### -Database

{{ Fill Database Description }}
Specifies the Kusto Database where the new ingestion mapping is being created.

> [!NOTE]
>
Expand All @@ -61,9 +83,14 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -IngestionMapping
### -Mapping
{{ Fill IngestionMapping Description }}
This parameter indicates how to map data from the source file to the actual columns in the table.
You can define the format value with the relevant mapping type.
To create a new mapping object, checkout [`New-KustoIngestionMapping`](New-KustoIngestionMapping.md) and [`New-KustoColumnMapping`](New-KustoColumnMapping.md) documentations.

See [__data mappings__](https://learn.microsoft.com/en-us/kusto/management/mappings?view=microsoft-fabric) and [__Class `KustoIngestionProperties`__](https://learn.microsoft.com/en-us/kusto/api/netfx/kusto-ingest-client-reference?view=microsoft-fabric#class-kustoingestionproperties) for more information.

```yaml
Type: IngestionMapping
Expand All @@ -77,9 +104,9 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -MappingName
### -Name

{{ Fill MappingName Description }}
The name for the ingestion mapping.

```yaml
Type: String
Expand All @@ -104,15 +131,15 @@ Aliases:
Accepted values: PSObject, Json, Csv, DataTable, Html
Required: False
Position: 1
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -RemoveOldestIfRequired
### -Force

{{ Fill RemoveOldestIfRequired Description }}
If a mapping with same name in the given scope already exists, `.create` fails. Use this switch to execute a `.create-or-alter` control command instead.

```yaml
Type: SwitchParameter
Expand Down Expand Up @@ -148,14 +175,18 @@ Accept wildcard characters: False

### -Table

{{ Fill Table Description }}
Specifies the Table where the new ingestion mapping is being created.

> [!NOTE]
>
> This parameter is optional. If not specified, the ingestion mapping is created on Database level.

```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Required: False
Position: 0
Default value: None
Accept pipeline input: False
Expand All @@ -182,3 +213,7 @@ For more information, see [about_CommonParameters](http://go.microsoft.com/fwlin
## NOTES

## RELATED LINKS

[__.create ingestion mapping command__](https://learn.microsoft.com/en-us/kusto/management/create-ingestion-mapping-command?view=microsoft-fabric)

[__.create-or-alter ingestion mapping command__](https://learn.microsoft.com/en-us/kusto/management/create-or-alter-ingestion-mapping-command?view=microsoft-fabric)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class NewKustoIngestionMappingCommand : PSCmdlet
public ColumnMapping[]? Columns { get; set; }

[Parameter(Position = 1)]
public IngestionMappingKind Kind { get; set; } = IngestionMappingKind.Unknown;
public IngestionMappingKind Kind { get; set; } = IngestionMappingKind.Csv;

[Parameter]
[ValidateNotNullOrEmpty]
Expand Down
45 changes: 33 additions & 12 deletions src/PowerShellKusto/Commands/SetKustoIngestionMappingCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,27 @@ namespace PowerShellKusto.Commands;
public sealed class SetKustoIngestionMappingCommand : KustoReaderCommandBase
{
[Parameter(Mandatory = true, Position = 0)]
public string Table { get; set; } = null!;
public string Name { get; set; } = null!;

[Parameter(Mandatory = true, Position = 2)]
public string MappingName { get; set; } = null!;
[Parameter(Position = 2)]
public string? Table { get; set; }

[Parameter(Mandatory = true)]
public IngestionMapping IngestionMapping { get; set; } = null!;
public IngestionMapping Mapping { get; set; } = null!;

[Parameter]
public SwitchParameter RemoveOldestIfRequired { get; set; }
public SwitchParameter Force { get; set; }

protected override void EndProcessing()
{
try
{
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);
string command = Table is null
? GetDatabaseCommand()
: GetTableCommand();

using ICslAdminProvider client = KustoClientFactory.CreateCslAdminProvider(Builder);
using IDataReader reader = RequestProperties is null
? client.ExecuteControlCommand(Database, command)
: client.ExecuteControlCommand(Database, command, RequestProperties);
Expand All @@ -48,4 +45,28 @@ protected override void EndProcessing()
WriteError(error);
}
}

private string GetTableCommand() => Force
? CslCommandGenerator.GenerateTableMappingCreateOrAlterCommand(
mappingKind: Mapping.IngestionMappingKind,
tableName: Table,
mappingName: Name,
mapping: Mapping.IngestionMappings)
: CslCommandGenerator.GenerateTableMappingCreateCommand(
mappingKind: Mapping.IngestionMappingKind,
entityName: Table,
mappingName: Name,
mapping: Mapping.IngestionMappings);

private string GetDatabaseCommand() => Force
? CslCommandGenerator.GenerateDatabaseMappingCreateOrAlterCommand(
mappingKind: Mapping.IngestionMappingKind,
entityName: Database,
mappingName: Name,
mapping: Mapping.IngestionMappings)
: CslCommandGenerator.GenerateDatabaseMappingCreateCommand(
mappingKind: Mapping.IngestionMappingKind,
entityName: Database,
mappingName: Name,
mapping: Mapping.IngestionMappings);
}

0 comments on commit f4abd1f

Please sign in to comment.