14 using System.Collections.Generic;
15 using System.Threading.Tasks;
32 public static async Task
RunAsync(
string tableName)
34 Console.WriteLine(
"=== Clear Table Example ===\n");
36 if (
string.IsNullOrEmpty(tableName))
38 Console.WriteLine(
"Usage: dotnet run --project Example -- --clear-table <table_name>");
39 Console.WriteLine(
"Example: dotnet run --project Example -- --clear-table test_schema.my_table");
44 var url = Environment.GetEnvironmentVariable(
"KINETICA_URL") ??
"http://localhost:9191";
45 var user = Environment.GetEnvironmentVariable(
"KINETICA_USER") ??
"admin";
46 var password = Environment.GetEnvironmentVariable(
"KINETICA_PASSWORD") ??
"secret";
54 Console.WriteLine($
"! WARNING: This will delete ALL data from table '{tableName}'");
55 Console.WriteLine(
"This operation is IRREVERSIBLE!\n");
57 Console.WriteLine(
"Waiting 3 seconds... (Press Ctrl+C to cancel)");
58 for (
int i = 3; i >= 1; i--)
60 Console.WriteLine($
"{i}...");
61 await Task.Delay(1000);
64 Console.WriteLine($
"\nClearing table '{tableName}'...");
69 var response =
kinetica.clearTable(request);
71 Console.WriteLine(
"+ Table cleared successfully!");
72 Console.WriteLine($
" Table Name: {response.table_name}");
74 if (response.info.TryGetValue(
"count", out var count))
76 Console.WriteLine($
" Records Deleted: {count}");
81 Console.WriteLine($
"x Error clearing table: {ex.Message}");
85 Console.WriteLine($
"\nAll data has been removed from '{tableName}'");
103 public static async Task
RunAsync(
string schemaPattern =
"test_schema")
105 Console.WriteLine(
"=== Cleanup All Test Tables Example ===\n");
108 var url = Environment.GetEnvironmentVariable(
"KINETICA_URL") ??
"http://localhost:9191";
109 var user = Environment.GetEnvironmentVariable(
"KINETICA_USER") ??
"admin";
110 var password = Environment.GetEnvironmentVariable(
"KINETICA_PASSWORD") ??
"secret";
118 Console.WriteLine($
"! WARNING: This will DROP all tables in schema matching '{schemaPattern}'");
119 Console.WriteLine(
"This operation is IRREVERSIBLE!\n");
122 Console.WriteLine(
"Discovering tables...");
124 IList<string> tablesToDrop =
new List<string>();
128 var showTableResponse =
kinetica.showTable(
"",
new Dictionary<string, string>
130 {
"show_children",
"true" }
133 foreach (var tbl
in showTableResponse.table_names)
135 if (tbl.StartsWith(schemaPattern))
137 tablesToDrop.Add(tbl);
143 Console.WriteLine($
"Error discovering tables: {ex.Message}");
147 if (tablesToDrop.Count == 0)
149 Console.WriteLine($
"No tables found matching pattern '{schemaPattern}'");
153 Console.WriteLine($
"\nFound {tablesToDrop.Count} table(s) to drop:");
154 foreach (var tbl
in tablesToDrop)
156 Console.WriteLine($
" - {tbl}");
159 Console.WriteLine(
"\nWaiting 5 seconds... (Press Ctrl+C to cancel)");
160 for (
int i = 5; i >= 1; i--)
162 Console.WriteLine($
"{i}...");
163 await Task.Delay(1000);
166 Console.WriteLine(
"\nDropping tables...");
168 var droppedCount = 0;
171 foreach (var tbl
in tablesToDrop)
175 kinetica.executeSql($
"DROP TABLE IF EXISTS {tbl}");
176 Console.WriteLine($
" + Dropped: {tbl}");
181 Console.WriteLine($
" x Failed to drop {tbl}: {ex.Message}");
189 if (schemaPattern.Contains(
'.'))
191 schemaPattern = schemaPattern.Split(
'.')[0];
194 kinetica.executeSql($
"DROP SCHEMA IF EXISTS {schemaPattern}");
195 Console.WriteLine($
"\n + Dropped schema: {schemaPattern}");
202 Console.WriteLine($
"\nCleanup complete!");
203 Console.WriteLine($
" Dropped: {droppedCount} table(s)");
206 Console.WriteLine($
" Failed: {failedCount} table(s)");
222 public static void Run(
string schemaFilter =
"")
224 Console.WriteLine(
"=== Show Tables Example ===\n");
227 var url = Environment.GetEnvironmentVariable(
"KINETICA_URL") ??
"http://localhost:9191";
228 var user = Environment.GetEnvironmentVariable(
"KINETICA_USER") ??
"admin";
229 var password = Environment.GetEnvironmentVariable(
"KINETICA_PASSWORD") ??
"secret";
237 Console.WriteLine($
"Connected to: {url}\n");
241 var showTableResponse =
kinetica.showTable(
"",
new Dictionary<string, string>
243 {
"show_children",
"true" },
244 {
"get_sizes",
"true" }
247 Console.WriteLine($
"{"Table Name
",-50} {"Records",-15} {"Type ID
",-40}");
248 Console.WriteLine(
new string(
'-', 105));
251 for (
int i = 0; i < showTableResponse.table_names.Count; i++)
253 var tableName = showTableResponse.table_names[i];
256 if (!
string.IsNullOrEmpty(schemaFilter) && !tableName.StartsWith(schemaFilter))
259 var typeId = i < showTableResponse.type_ids.Count
260 ? showTableResponse.type_ids[i]
263 var recordCount =
"N/A";
264 if (i < showTableResponse.sizes.Count)
266 recordCount = showTableResponse.sizes[i].ToString(
"N0");
269 Console.WriteLine($
"{tableName,-50} {recordCount,-15} {typeId,-40}");
273 Console.WriteLine(
new string(
'-', 105));
274 Console.WriteLine($
"Total: {tableCount} table(s)");
278 Console.WriteLine($
"Error: {ex.Message}");
285 #region Truncate Table 294 public static async Task
RunAsync(
string tableName)
296 Console.WriteLine(
"=== Truncate Table Example ===\n");
298 if (
string.IsNullOrEmpty(tableName))
300 Console.WriteLine(
"Usage: dotnet run --project Example -- --truncate <table_name>");
305 var url = Environment.GetEnvironmentVariable(
"KINETICA_URL") ??
"http://localhost:9191";
306 var user = Environment.GetEnvironmentVariable(
"KINETICA_USER") ??
"admin";
307 var password = Environment.GetEnvironmentVariable(
"KINETICA_PASSWORD") ??
"secret";
315 Console.WriteLine($
"! WARNING: This will TRUNCATE table '{tableName}'");
316 Console.WriteLine(
"This operation is IRREVERSIBLE!\n");
318 Console.WriteLine(
"Waiting 3 seconds... (Press Ctrl+C to cancel)");
319 for (
int i = 3; i >= 1; i--)
321 Console.WriteLine($
"{i}...");
322 await Task.Delay(1000);
325 Console.WriteLine($
"\nTruncating table '{tableName}'...");
329 kinetica.executeSql($
"TRUNCATE TABLE {tableName}");
330 Console.WriteLine(
"+ Table truncated successfully!");
334 Console.WriteLine($
"x Error truncating table: {ex.Message}");
338 Console.WriteLine($
"\nAll data has been removed from '{tableName}'");
Example: Clear All Data from a Table
Example: Cleanup All Test Tables
A set of parameters for Kinetica.clearTable.
static async Task RunAsync(string schemaPattern="test_schema")
static async Task RunAsync(string tableName)
Immutable collection of metadata about a Kinetica type.
static void Run(string schemaFilter="")
Example: Truncate Table (faster than ClearTable for large tables)
static async Task RunAsync(string tableName)