Skip to content

Commit 5345164

Browse files
committed
.
1 parent 7ad41ca commit 5345164

15 files changed

+216
-110
lines changed

code/KustoCopyConsole/CommandLineOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class CommandLineOptions
2525
public string Destination { get; set; } = string.Empty;
2626

2727
[Option('a', "auth", Required = false, HelpText = "Set authentication method.")]
28-
public string Authentication { get; set; } = "AzCli";
28+
public string Authentication { get; set; } = string.Empty;
2929

3030
[Option(
3131
'l',

code/KustoCopyConsole/Entity/InMemory/RowItemInMemoryCache.cs

+31-17
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,77 @@ namespace KustoCopyConsole.Entity.InMemory
1010
internal class RowItemInMemoryCache
1111
{
1212
private readonly object _lock = new object();
13-
private volatile IImmutableDictionary<(Uri, string), SourceDatabaseCache> _sourceDatabaseMap
14-
= ImmutableDictionary<(Uri, string), SourceDatabaseCache>.Empty;
13+
private volatile IImmutableDictionary<TableIdentity, SourceTableCache> _sourceTableMap =
14+
ImmutableDictionary<TableIdentity, SourceTableCache>.Empty;
1515

1616
public RowItemInMemoryCache(IEnumerable<RowItem> items)
1717
{
1818
lock (_lock)
1919
{
2020
foreach (var item in items)
2121
{
22-
AddItem(item);
22+
AppendItem(item);
2323
}
2424
}
2525
}
2626

27-
public IImmutableDictionary<(Uri, string), SourceDatabaseCache> SoureDatabaseMap
28-
=> _sourceDatabaseMap;
27+
public IImmutableDictionary<TableIdentity, SourceTableCache> SourceTableMap
28+
=> _sourceTableMap;
2929

3030
public IEnumerable<RowItem> GetItems()
3131
{
32-
throw new NotImplementedException();
32+
foreach (var sourceTable in SourceTableMap.Values)
33+
{
34+
foreach (var sourceTableIteration in sourceTable.IterationMap.Values)
35+
{
36+
yield return sourceTableIteration.RowItem;
37+
}
38+
}
3339
}
3440

35-
public void AddItem(RowItem item)
41+
public void AppendItem(RowItem item)
3642
{
3743
lock (_lock)
3844
{
3945
if (item.RowType != RowType.FileVersion && item.RowType != RowType.Unspecified)
4046
{
4147
Interlocked.Exchange(
42-
ref _sourceDatabaseMap,
43-
AddItemToCache(item));
48+
ref _sourceTableMap,
49+
AppendItemToCache(item));
4450
}
4551
}
4652
}
4753

48-
private IImmutableDictionary<(Uri, string), SourceDatabaseCache> AddItemToCache(RowItem item)
54+
private IImmutableDictionary<TableIdentity, SourceTableCache> AppendItemToCache(
55+
RowItem item)
4956
{
5057
switch (item.RowType)
5158
{
52-
case RowType.SourceDatabase:
53-
return AddSourceDatabase(item);
59+
case RowType.SourceTable:
60+
return AppendSourceTable(item);
5461
default:
5562
throw new NotSupportedException($"Not supported row type: {item.RowType}");
5663
}
5764
}
5865

59-
private IImmutableDictionary<(Uri, string), SourceDatabaseCache> AddSourceDatabase(RowItem item)
66+
private IImmutableDictionary<TableIdentity, SourceTableCache> AppendSourceTable(
67+
RowItem item)
6068
{
61-
var key = (NormalizedUri.NormalizeUri(item.SourceClusterUri), item.SourceDatabaseName);
69+
//item.IterationId!.Value
70+
var tableId = new TableIdentity(
71+
NormalizedUri.NormalizeUri(item.SourceClusterUri),
72+
item.SourceDatabaseName,
73+
item.SourceTableName);
6274

63-
if (_sourceDatabaseMap.ContainsKey(key))
75+
if (_sourceTableMap.ContainsKey(tableId))
6476
{
65-
return _sourceDatabaseMap.SetItem(key, new SourceDatabaseCache(item));
77+
return _sourceTableMap.SetItem(
78+
tableId,
79+
_sourceTableMap[tableId].AppendIteration(item));
6680
}
6781
else
6882
{
69-
return _sourceDatabaseMap.Add(key, new SourceDatabaseCache(item));
83+
return _sourceTableMap.Add(tableId, new SourceTableCache(item));
7084
}
7185
}
7286
}

code/KustoCopyConsole/Entity/InMemory/SourceDatabaseCache.cs

-10
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Immutable;
2+
3+
namespace KustoCopyConsole.Entity.InMemory
4+
{
5+
internal class SourceTableCache
6+
{
7+
public SourceTableCache(
8+
IImmutableDictionary<long, SourceTableIterationCache> iterationMap)
9+
{
10+
IterationMap = iterationMap;
11+
}
12+
13+
public SourceTableCache(RowItem iterationItem)
14+
{
15+
var iterationId = iterationItem.IterationId;
16+
17+
IterationMap = ImmutableDictionary<long, SourceTableIterationCache>
18+
.Empty
19+
.Add(iterationId, new SourceTableIterationCache(iterationItem));
20+
}
21+
22+
public IImmutableDictionary<long, SourceTableIterationCache> IterationMap { get; }
23+
24+
public SourceTableCache AppendIteration(RowItem item)
25+
{
26+
var iterationId = item.IterationId;
27+
28+
if (IterationMap.ContainsKey(iterationId))
29+
{
30+
return new SourceTableCache(
31+
IterationMap.SetItem(iterationId, IterationMap[iterationId].Update(item)));
32+
}
33+
else
34+
{
35+
return new SourceTableCache(
36+
IterationMap.Add(iterationId, new SourceTableIterationCache(item)));
37+
}
38+
}
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Immutable;
2+
3+
namespace KustoCopyConsole.Entity.InMemory
4+
{
5+
internal class SourceTableIterationCache : CacheBase
6+
{
7+
public SourceTableIterationCache(RowItem item)
8+
: base(item)
9+
{
10+
}
11+
12+
public SourceTableIterationCache Update(RowItem item)
13+
{
14+
return new SourceTableIterationCache(item);
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace KustoCopyConsole.Entity.InMemory
8+
{
9+
internal record TableIdentity(
10+
Uri ClusterUri,
11+
string DatabaseName,
12+
string TableName);
13+
}

code/KustoCopyConsole/Entity/RowItem.cs

+13-10
Original file line numberDiff line numberDiff line change
@@ -85,32 +85,35 @@ private class RowTypeConverter : DefaultTypeConverter
8585
public string SourceDatabaseName { get; set; } = string.Empty;
8686

8787
[Index(7)]
88-
public string DestinationClusterUri { get; set; } = string.Empty;
88+
public string SourceTableName { get; set; } = string.Empty;
8989

9090
[Index(8)]
91-
public string DestinationDatabaseName { get; set; } = string.Empty;
91+
public string DestinationClusterUri { get; set; } = string.Empty;
9292

9393
[Index(9)]
94-
public string TableName { get; set; } = string.Empty;
94+
public string DestinationDatabaseName { get; set; } = string.Empty;
9595

96-
/// <summary>Zero-based index with zero being the backfill.</summary>>
9796
[Index(10)]
98-
public long? IterationId { get; set; }
97+
public string DestinationTableName { get; set; } = string.Empty;
9998

99+
/// <summary>Zero-based index with zero being the backfill.</summary>>
100100
[Index(11)]
101-
public string CursorStart { get; set; } = string.Empty;
101+
public long IterationId { get; set; }
102102

103103
[Index(12)]
104-
public string CursorEnd { get; set; } = string.Empty;
104+
public string CursorStart { get; set; } = string.Empty;
105105

106106
[Index(13)]
107-
public long? BlockId { get; set; }
107+
public string CursorEnd { get; set; } = string.Empty;
108108

109109
[Index(14)]
110-
public DateTime? IngestionTimeStart { get; set; }
110+
public long? BlockId { get; set; }
111111

112112
[Index(15)]
113-
public long? IngestionTimeEnd { get; set; }
113+
public DateTime? IngestionTimeStart { get; set; }
114+
115+
[Index(16)]
116+
public DateTime? IngestionTimeEnd { get; set; }
114117
#endregion
115118

116119
public T ParseState<T>() where T : struct

code/KustoCopyConsole/Entity/RowType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public enum RowType
44
{
55
Unspecified,
66
FileVersion,
7-
SourceDatabase
7+
SourceTable
88
}
99
}

code/KustoCopyConsole/Entity/State/DestinationDatabaseState.cs

-8
This file was deleted.

code/KustoCopyConsole/Entity/State/SourceDatabaseState.cs

-9
This file was deleted.

code/KustoCopyConsole/Entity/State/SourceTableState.cs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
public enum SourceTableState
44
{
5-
Discovered,
65
Planning,
76
Exporting,
87
Completed
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace KustoCopyConsole
8+
{
9+
internal static class EnumerableHelper
10+
{
11+
public static T ArgMax<T>(this IEnumerable<T> enumerable, Func<T, long> selector)
12+
{
13+
T? maxItem = default;
14+
long maxValue = 0;
15+
16+
foreach (var item in enumerable)
17+
{
18+
if (maxItem == null
19+
|| selector(item) > maxValue)
20+
{
21+
maxItem = item;
22+
}
23+
}
24+
25+
if (maxItem == null)
26+
{
27+
throw new InvalidOperationException("Enumerable is empty");
28+
}
29+
30+
return maxItem;
31+
}
32+
}
33+
}

code/KustoCopyConsole/Orchestration/MainOrchestration.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ private MainOrchestration(
4444

4545
private static TokenCredential CreateCredentials(string authentication)
4646
{
47-
if (string.Compare(authentication.Trim(), "AzCli", true) == 0)
47+
if (string.IsNullOrWhiteSpace(authentication))
4848
{
49-
return new AzureCliCredential();
49+
return new DefaultAzureCredential();
5050
}
5151
else
5252
{

0 commit comments

Comments
 (0)