Skip to content

Commit eef6953

Browse files
author
Thomas Mahlberg
committed
Fixed MV problems
1 parent 864cc54 commit eef6953

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

KustoSchemaTools/Helpers/Serialization.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static class Serialization
2626

2727
public static JsonSerializer CloneJsonSerializer { get; } = new JsonSerializer
2828
{
29-
DefaultValueHandling = DefaultValueHandling.Ignore
29+
DefaultValueHandling = DefaultValueHandling.Ignore
3030
};
3131

3232

KustoSchemaTools/Model/MaterializedView.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using KustoSchemaTools.Changes;
2+
using System.ComponentModel;
23
using YamlDotNet.Core;
34
using YamlDotNet.Serialization;
45

@@ -8,10 +9,10 @@ public class MaterializedView : IKustoBaseEntity
89
{
910
public string Source { get; set; }
1011
public string Kind { get; set; } = "table";
11-
public string Folder { get; set; } = "";
12-
public string DocString { get; set; } = "";
12+
public string Folder { get; set; }
13+
public string DocString { get; set; }
1314
public string? EffectiveDateTime { get; set; }
14-
public string Lookback { get; set; } = "";
15+
public string Lookback { get; set; }
1516
public bool? UpdateExtentsCreationTime { get; set; }
1617
public bool AutoUpdateSchema { get; set; } = false;
1718
public List<string> DimensionTables { get; set; }
@@ -27,7 +28,9 @@ public List<DatabaseScriptContainer> CreateScripts(string name)
2728
var scripts = new List<DatabaseScriptContainer>();
2829
var properties = string.Join(", ", GetType().GetProperties()
2930
.Where(p => p.GetValue(this) != null && excludedProperies.Contains(p.Name) == false)
30-
.Select(p => $"{p.Name}=\"{p.GetValue(this)}\""));
31+
.Select(p => new {Name = p.Name, Value = p.GetValue(this) })
32+
.Where(p => !string.IsNullOrWhiteSpace(p.Value?.ToString()))
33+
.Select(p => $"{p.Name}=\"{p.Value}\""));
3134
scripts.Add(new DatabaseScriptContainer("CreateOrAlterMaterializedView", 40, $".create-or-alter materialized-view with ({properties}) {name} on {Kind} {Source} {{ {Query} }}"));
3235

3336
if (RetentionAndCachePolicy != null)

KustoSchemaTools/Parser/KustoLoader/KustoMaterializedViewBulkLoader.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ public class KustoMaterializedViewBulkLoader : KustoBulkEntityLoader<Materialize
66
{
77
const string LoadMaterializedViews = ".show materialized-views details| project EntityName=MaterializedViewName, Body=bag_pack(\"DocString\", DocString, \"Folder\", Folder,\"RetentionAndCachePolicy\",bag_pack(\"Retention\",strcat(toint(totimespan(parse_json(RetentionPolicy).SoftDeletePeriod)/1d),\"d\") , \"HotCache\", strcat(toint(totimespan(parse_json(CachingPolicy).DataHotSpan)/1d),\"d\")))";
88
const string LoadDetails = ".show materialized-views | extend Lookback = strcat(toint(Lookback / 1d),\"d\") | extend Lookback = iff(Lookback == 'd', \"\", Lookback), Source= SourceTable | project EntityName=Name, Body=bag_pack_columns(Source, Query,IsEnabled, Folder,DocString, AutoUpdateSchema, Lookback)";
9+
const string LoadRowLevelSecurity = ".show database schema as csl script | parse-where DatabaseSchemaScript with \".alter materialized-view \" TableName:string \" policy row_level_security enable \" Policy:string | project TableName, RowLevelSecurity = trim(\"( |\\\\\\\")*\",Policy) | project EntityName = TableName, Body=bag_pack_columns(RowLevelSecurity)";
910

1011
public KustoMaterializedViewBulkLoader() : base(d => d.MaterializedViews) { }
1112

1213
protected override IEnumerable<string> EnumerateScripts()
1314
{
1415
yield return LoadMaterializedViews;
1516
yield return LoadDetails;
17+
yield return LoadRowLevelSecurity;
1618
}
1719
}
1820
}

0 commit comments

Comments
 (0)