Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions KustoSchemaTools/Changes/DatabaseChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ public static List<IChange> GenerateChanges(Database oldState, Database newState
result.AddRange(mvChanges);
result.AddRange(GenerateScriptCompareChanges(oldState, newState, db => db.ContinuousExports, nameof(newState.ContinuousExports), log));
result.AddRange(GenerateScriptCompareChanges(oldState, newState, db => db.Functions, nameof(newState.Functions), log));

// For delta external tables, the schema is auto-inferred from the delta log.
// If the YAML doesn't specify a schema, clear the cluster-side schema so it
// doesn't cause a perpetual diff. If the YAML does specify a schema, keep the
// cluster-side schema for proper comparison.
foreach (var et in newState.ExternalTables)
{
if (et.Value.Kind?.ToLower() == "delta"
&& et.Value.Schema?.Any() != true
&& oldState.ExternalTables.ContainsKey(et.Key))
{
oldState.ExternalTables[et.Key].Schema = null;
}
}

result.AddRange(GenerateScriptCompareChanges(oldState, newState, db => db.ExternalTables, nameof(newState.ExternalTables), log));

if (newState.EntityGroups.Any())
Expand Down
13 changes: 9 additions & 4 deletions KustoSchemaTools/Model/ExternalTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,25 @@ private string CreateSqlScript(string name)

private string CreateDeltaScript(string name)
{
if (string.IsNullOrWhiteSpace(DataFormat)) throw new ArgumentException("DataFormat can't be empty");

var sb = new StringBuilder();
sb.AppendLine($".create-or-alter external table {name}");
if (Schema?.Any() == true)
{
sb.AppendLine($"({string.Join(", ", Schema.Select(c => $"{c.Key.BracketIfIdentifier()}:{c.Value}"))})");
}
sb.AppendLine("kind=delta");
sb.AppendLine($"(h@'{ConnectionString}'");
sb.AppendLine($"(h@'{ConnectionString}')");

var withProps = new List<string>();
if (!string.IsNullOrEmpty(Folder)) withProps.Add($"folder='{Folder}'");
if (!string.IsNullOrEmpty(DocString)) withProps.Add($"docString='{DocString}'");
var ext = string.IsNullOrWhiteSpace(FileExtensions) ? "" : FileExtensions.StartsWith(".") ? FileExtensions : "." + FileExtensions;
if (!string.IsNullOrEmpty(ext)) withProps.Add($"fileExtension='{ext}'");

sb.AppendLine($"with(folder='{Folder}', docString='{DocString}', fileExtension='{ext}') ");
if (withProps.Any())
{
sb.AppendLine($"with({string.Join(", ", withProps)})");
}

return sb.ToString();
}
Expand Down
Loading