Skip to content

Commit 2b2b886

Browse files
authored
Merge pull request #76 from github/caol-ila-mv-backfill-async
Add support for MV backfills
2 parents 36b8834 + 0f1e79a commit 2b2b886

12 files changed

Lines changed: 104 additions & 18 deletions

KustoSchemaTools/Changes/BaseChange.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ protected BaseChange(string entityType, string entity, T from, T to)
2222

2323
public string Markdown { get; protected set; }
2424

25+
public bool IsAsync { get; set; }
26+
2527
}
2628

2729
}

KustoSchemaTools/Changes/DatabaseScriptContainer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,25 @@ public DatabaseScriptContainer()
99

1010
}
1111

12-
public DatabaseScriptContainer(DatabaseScript script, string kind, bool? isValid = null)
12+
public DatabaseScriptContainer(DatabaseScript script, string kind, bool isAsync = false)
1313
{
1414
Script = script;
1515
Kind = kind;
16-
IsValid = isValid;
16+
IsAsync = isAsync;
1717
}
1818

19-
public DatabaseScriptContainer(string kind, int order, string script, bool? isValid = null)
19+
public DatabaseScriptContainer(string kind, int order, string script, bool isAsync = false)
2020
{
2121
Script = new DatabaseScript(script, order);
2222
Kind = kind;
23-
IsValid = isValid;
23+
IsAsync = isAsync;
2424
}
2525

2626
public DatabaseScript Script { get; set; }
2727
public string Kind{ get; set; }
2828
public bool? IsValid { get; set; }
2929
public string Text => Script.Text;
3030
public int Order => Script.Order;
31+
public bool IsAsync { get;set; }
3132
}
3233
}

KustoSchemaTools/Changes/GenericBaseEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public GenericBaseEntity(List<DatabaseScriptContainer> scripts)
1111

1212
public List<DatabaseScriptContainer> Scripts { get; }
1313

14-
public List<DatabaseScriptContainer> CreateScripts(string name)
14+
public List<DatabaseScriptContainer> CreateScripts(string name, bool isNew)
1515
{
1616
return Scripts;
1717
}

KustoSchemaTools/Changes/ScriptCompareChange.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public ScriptCompareChange(string entity, IKustoBaseEntity? from, IKustoBaseEnti
1919

2020
private void Init()
2121
{
22-
var from = From?.CreateScripts(Entity).ToDictionary(itm => itm.Kind) ?? new Dictionary<string, DatabaseScriptContainer>();
23-
var to = To.CreateScripts(Entity);
22+
var from = From?.CreateScripts(Entity, false).ToDictionary(itm => itm.Kind) ?? new Dictionary<string, DatabaseScriptContainer>();
23+
var to = To.CreateScripts(Entity, from != null);
2424
Markdown = string.Empty;
2525

2626
if (to.Any() == false) return;

KustoSchemaTools/Model/ContinuousExport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ContinuousExport : IKustoBaseEntity
1414
[YamlMember(ScalarStyle = YamlDotNet.Core.ScalarStyle.Literal)]
1515
public string Query { get; set; }
1616

17-
public List<DatabaseScriptContainer> CreateScripts(string name)
17+
public List<DatabaseScriptContainer> CreateScripts(string name, bool isNew)
1818
{
1919
return new List<DatabaseScriptContainer>
2020
{

KustoSchemaTools/Model/ExternalTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ExternalTable : IKustoBaseEntity
4040

4141
#endregion
4242

43-
public List<DatabaseScriptContainer> CreateScripts(string name)
43+
public List<DatabaseScriptContainer> CreateScripts(string name, bool isNew)
4444
{
4545
var container = new DatabaseScriptContainer
4646
{

KustoSchemaTools/Model/Function.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Function : IKustoBaseEntity
1818

1919
public string Body { get; set; }
2020

21-
public List<DatabaseScriptContainer> CreateScripts(string name)
21+
public List<DatabaseScriptContainer> CreateScripts(string name, bool isNew)
2222
{
2323
var properties = GetType().GetProperties()
2424
.Where(p => p.GetValue(this) != null && p.Name != "Body" && p.Name != "Parameters")

KustoSchemaTools/Model/IKustoBaseEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace KustoSchemaTools.Model
44
{
55
public interface IKustoBaseEntity
66
{
7-
List<DatabaseScriptContainer> CreateScripts(string name);
7+
List<DatabaseScriptContainer> CreateScripts(string name, bool isNew);
88
}
99

1010
}

KustoSchemaTools/Model/MaterializedView.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,46 @@ public class MaterializedView : IKustoBaseEntity
1414
public string? EffectiveDateTime { get; set; }
1515
public string Lookback { get; set; }
1616
public bool? UpdateExtentsCreationTime { get; set; }
17+
public bool? Backfill { get; set; }
1718
public bool AutoUpdateSchema { get; set; } = false;
1819
public List<string> DimensionTables { get; set; }
1920
public RetentionAndCachePolicy RetentionAndCachePolicy { get; set; } = new RetentionAndCachePolicy();
2021
[YamlMember(ScalarStyle = ScalarStyle.Literal)]
2122
public string Query { get; set; }
2223
public string? RowLevelSecurity { get; set; }
2324

24-
public List<DatabaseScriptContainer> CreateScripts(string name)
25+
public List<DatabaseScriptContainer> CreateScripts(string name, bool isNew)
2526
{
26-
var excludedProperies = new HashSet<string>( new[] { "Query", "Source", "Kind", "RetentionAndCachePolicy", "RowLevelSecurity" });
27+
var asyncSetup = isNew && Backfill == true && !string.IsNullOrWhiteSpace(EffectiveDateTime);
28+
29+
30+
var excludedProperies = new HashSet<string>(["Query", "Source", "Kind", "RetentionAndCachePolicy", "RowLevelSecurity"]);
31+
if (!asyncSetup)
32+
{
33+
excludedProperies.Add("EffectiveDateTime");
34+
excludedProperies.Add("Backfill");
35+
}
2736

2837
var scripts = new List<DatabaseScriptContainer>();
2938
var properties = string.Join(", ", GetType().GetProperties()
3039
.Where(p => p.GetValue(this) != null && excludedProperies.Contains(p.Name) == false)
3140
.Select(p => new {Name = p.Name, Value = p.GetValue(this) })
3241
.Where(p => !string.IsNullOrWhiteSpace(p.Value?.ToString()))
3342
.Select(p => $"{p.Name}=\"{p.Value}\""));
34-
scripts.Add(new DatabaseScriptContainer("CreateOrAlterMaterializedView", 40, $".create-or-alter materialized-view with ({properties}) {name} on {Kind} {Source} {{ {Query} }}"));
43+
44+
if (asyncSetup)
45+
{
46+
scripts.Add(new DatabaseScriptContainer("CreateMaterializedView", Kind == "table" ? 40 : 41, $".create async ifnotexists materialized-view with ({properties}) {name} on {Kind} {Source} {{ {Query} }}", true));
47+
}
48+
else
49+
{
50+
scripts.Add(new DatabaseScriptContainer("CreateMaterializedView", Kind == "table" ? 40 : 41, $".create-or-alter materialized-view with ({properties}) {name} on {Kind} {Source} {{ {Query} }}"));
51+
}
3552

3653
if (RetentionAndCachePolicy != null)
54+
{
3755
scripts.AddRange(RetentionAndCachePolicy.CreateScripts(name, "materialized-view"));
56+
}
3857

3958

4059
if (!string.IsNullOrEmpty(RowLevelSecurity))

KustoSchemaTools/Model/Table.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Table : IKustoBaseEntity
1717
public bool RestrictedViewAccess { get; set; } = false;
1818
public string? RowLevelSecurity { get; set; }
1919

20-
public List<DatabaseScriptContainer> CreateScripts(string name)
20+
public List<DatabaseScriptContainer> CreateScripts(string name, bool isNew)
2121
{
2222
var scripts = new List<DatabaseScriptContainer>();
2323
if (Columns != null)

0 commit comments

Comments
 (0)