Skip to content

Commit 793d8bd

Browse files
authored
Merge pull request #121 from yaananth/yaananth-fabric
support fabric eventhouse
2 parents f699eef + d1fc819 commit 793d8bd

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using KustoSchemaTools.Parser;
2+
using Xunit;
3+
4+
namespace KustoSchemaTools.Tests.Parser
5+
{
6+
public class KustoExtensionsTests
7+
{
8+
[Theory]
9+
[InlineData("https://trd-abc.kusto.fabric.microsoft.com", false, "https://trd-abc.kusto.fabric.microsoft.com")]
10+
[InlineData("https://trd-abc.kusto.fabric.microsoft.com", true, "https://trd-abc.kusto.fabric.microsoft.com")]
11+
[InlineData("trd-abc.kusto.fabric.microsoft.com", false, "https://trd-abc.kusto.fabric.microsoft.com")]
12+
[InlineData("trd-abc.kusto.fabric.microsoft.com", true, "https://ingest-trd-abc.kusto.fabric.microsoft.com")]
13+
[InlineData("myadx.eastus", false, "https://myadx.eastus.kusto.windows.net")]
14+
[InlineData("myadx.eastus", true, "https://ingest-myadx.eastus.kusto.windows.net")]
15+
public void Fqdn_AndShorthand_MapToExpectedHosts(string input, bool ingest, string expected)
16+
{
17+
var actual = KustoExtensions.ToKustoClusterUrl(input, ingest);
18+
Assert.Equal(expected, actual);
19+
}
20+
21+
[Fact]
22+
public void NullOrEmpty_ReturnsEmpty_NotThrow()
23+
{
24+
var a = KustoExtensions.ToKustoClusterUrl(null!, false);
25+
var b = KustoExtensions.ToKustoClusterUrl("", true);
26+
Assert.Equal(string.Empty, a);
27+
Assert.Equal(string.Empty, b);
28+
}
29+
}
30+
}

KustoSchemaTools/Parser/KustoExtensions.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ public static class KustoExtensions
1414
NullValueHandling = NullValueHandling.Ignore,
1515
Formatting = Formatting.Indented,
1616
ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
17-
17+
1818

1919
};
2020

2121
public static string BracketIfIdentifier(this string name)
2222
{
23-
return reservedKustoWords.Contains(name)
24-
? $"['{name}']"
25-
: name.StartsWith("[")
23+
return reservedKustoWords.Contains(name)
24+
? $"['{name}']"
25+
: name.StartsWith("[")
2626
? name
2727
: KustoFacts.BracketNameIfNecessary(name);
2828
}
@@ -65,8 +65,21 @@ public static JObject AsDynamic(this DataTable table)
6565

6666
public static string ToKustoClusterUrl(this string cluster, bool ingest = false)
6767
{
68-
var ingestPrefix = ingest ? "ingest-" : "";
69-
return cluster.StartsWith("https") ? cluster : $"https://{ingestPrefix}{cluster}.kusto.windows.net";
68+
if (string.IsNullOrWhiteSpace(cluster))
69+
return cluster ?? string.Empty;
70+
71+
// Full URL passed → return as-is
72+
if (cluster.StartsWith("https", StringComparison.OrdinalIgnoreCase))
73+
return cluster;
74+
75+
var ingestPrefix = ingest ? "ingest-" : string.Empty;
76+
77+
// Fabric support
78+
if (cluster.EndsWith(".fabric.microsoft.com", StringComparison.OrdinalIgnoreCase))
79+
return $"https://{ingestPrefix}{cluster}";
80+
81+
// Original mapping: shorthand → *.kusto.windows.net
82+
return $"https://{ingestPrefix}{cluster}.kusto.windows.net";
7083
}
7184

7285
public static bool IsFinal(this ScriptExecuteCommandResult command)
@@ -685,4 +698,3 @@ public static string UseHtmlLineBreaks(this string query)
685698

686699
}
687700
}
688-

0 commit comments

Comments
 (0)