Skip to content

Commit e547398

Browse files
changes to table schema only happen when user specifies option now (#38)
* changes to table schema only happen when user specifies option now * updated unit tests to reflect new adx option
1 parent 078b520 commit e547398

4 files changed

Lines changed: 14 additions & 18 deletions

File tree

Source/RealTimeKql/CommandLineParsing/CommandLineParser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@ private void GetAllSubcommands()
486486
"Azure Data Explorer (ADX) database name. eg, --adxdatabase=TestDb", true),
487487
new Option("adxtable", "atb",
488488
"Azure Data Explorer (ADX) table name. eg, --adxtable=OutputTable", true),
489-
new Option("adxresettable", "art",
490-
"The existing data in the destination table is dropped before new data is logged.", false, true),
489+
new Option("adxcreatereset", "acr",
490+
"If table doesn't exist, it is created. If table exists, data in table is dropped before new data is logged. eg, --adxcreatereset", false, true),
491491
new Option("adxdirectingest", "adi",
492-
"Default upload to ADX is using queued ingest. Use this option to do a direct ingest to ADX.", false, true)
492+
"Default upload to ADX is using queued ingest. Use this option to do a direct ingest to ADX. eg, --adxdirectingest", false, true)
493493
};
494494

495495
var adx = new Subcommand("adx", "Ingest output to Azure Data Explorer", null, adxOptions);

Source/RealTimeKql/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static AdxOutput GetAdxOutput(List<Option> opts)
116116
string cluster = "";
117117
string database = "";
118118
string table = "";
119-
bool resetTable = false;
119+
bool createOrResetTable = false;
120120
bool directIngest = false;
121121

122122
foreach(var opt in opts)
@@ -144,8 +144,8 @@ static AdxOutput GetAdxOutput(List<Option> opts)
144144
case "adxdirectingest":
145145
directIngest = opt.WasSet;
146146
break;
147-
case "adxresettable":
148-
resetTable = opt.WasSet;
147+
case "adxcreatereset":
148+
createOrResetTable = opt.WasSet;
149149
break;
150150
}
151151
}
@@ -157,7 +157,7 @@ static AdxOutput GetAdxOutput(List<Option> opts)
157157
cluster,
158158
database,
159159
table,
160-
resetTable,
160+
createOrResetTable,
161161
directIngest);
162162
}
163163

Source/RealTimeKqlLibrary/Output/AdxOutput.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class AdxOutput : IOutput
1616
public AutoResetEvent Completed { get; private set; }
1717

1818
private readonly string _table;
19-
private readonly bool _resetTable;
19+
private readonly bool _createOrResetTable;
2020

2121
private readonly KustoConnectionStringBuilder kscbAdmin;
2222
private readonly KustoConnectionStringBuilder kscbIngest;
@@ -40,11 +40,11 @@ public AdxOutput(
4040
string cluster,
4141
string database,
4242
string table,
43-
bool resetTable=false,
43+
bool createOrResetTable=false,
4444
bool directIngest=false)
4545
{
4646
_table = table;
47-
_resetTable = resetTable;
47+
_createOrResetTable = createOrResetTable;
4848

4949
_batchSize = 10000;
5050
_flushDuration = TimeSpan.FromMilliseconds(5);
@@ -104,7 +104,7 @@ public void OutputAction(IDictionary<string, object> obj)
104104
_fields = obj.Keys.ToArray();
105105
}
106106

107-
if (kscbAdmin != null && _initializeTable == false)
107+
if (kscbAdmin != null && _initializeTable == false && _createOrResetTable == true)
108108
{
109109
CreateOrResetTable(obj);
110110
_initializeTable = true;
@@ -196,12 +196,8 @@ private void CreateOrResetTable(IDictionary<string, object> value)
196196
{
197197
using (var admin = KustoClientFactory.CreateCslAdminProvider(kscbAdmin))
198198
{
199-
if (_resetTable)
200-
{
201-
string dropTable = CslCommandGenerator.GenerateTableDropCommand(_table, true);
202-
admin.ExecuteControlCommand(dropTable);
203-
}
204-
199+
string dropTable = CslCommandGenerator.GenerateTableDropCommand(_table, true);
200+
admin.ExecuteControlCommand(dropTable);
205201
CreateMergeKustoTable(admin, value);
206202
}
207203
}

Source/RealTimeKqlTests/CommandLineParserTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void Parse_ValidOutputs_ReturnTrue(params string[] args)
6868

6969
[Theory]
7070
[InlineData("etw", "tcp", "json", "file.json")]
71-
[InlineData("etw", "tcp", "adx", "-ad=test.com", "-aclid=val", "-akey=val", "-acl=cluster", "-adb=database", "-atb=table", "-art", "-adi")]
71+
[InlineData("etw", "tcp", "adx", "-ad=test.com", "-aclid=val", "-akey=val", "-acl=cluster", "-adb=database", "-atb=table", "-acr", "-adi")]
7272
public void Parse_ValidOutputsWithOptions_ReturnTrue(params string[] args)
7373
{
7474
var c = new CommandLineParser(args);

0 commit comments

Comments
 (0)