3 using System.Data.Common;
5 using NetTopologySuite.Geometries;
12 public static class StringExt
14 public static string Truncate(
this string value,
int maxLength )
16 if (
string.IsNullOrEmpty( value ) )
19 return ( value.Length <= maxLength ) ? value : value[..maxLength];
26 static void Main(
string[] args)
28 Console.WriteLine(
"================================");
29 Console.WriteLine(
"= Example C# Project - Running =");
30 Console.WriteLine(
"================================");
34 if (args.Length > 0 && args[0].StartsWith(
"--"))
48 string serverUrl = args[0];
49 Console.WriteLine($
"URL: {serverUrl}\n");
51 Kinetica.Options _ServerOptions =
new()
57 string JdbcDriverPath =
"";
58 if( args.Length > 3) {
59 JdbcDriverPath = args[3];
63 if (JdbcDriverPath.Length > 0)
65 try { JdbcExample(JdbcDriverPath, serverUrl, _ServerOptions.Username, _ServerOptions.Password); }
66 catch (Exception ex) { Console.WriteLine($
"JDBC Example failed: {ex.Message}\n"); }
69 try { RunExample( serverUrl, _ServerOptions ); }
70 catch (Exception ex) { Console.WriteLine($
"RunExample failed: {ex.Message}\n"); }
72 try { RunSeriesExample( serverUrl, _ServerOptions ); }
73 catch (Exception ex) { Console.WriteLine($
"RunSeriesExample failed: {ex.Message}\n"); }
75 try { RunMultiheadIngestExample( serverUrl, _ServerOptions ); }
76 catch (Exception ex) { Console.WriteLine($
"RunMultiheadIngestExample failed: {ex.Message}\n"); }
79 try { AllTypesExample.RunAsync(serverUrl, _ServerOptions.Username, _ServerOptions.Password).GetAwaiter().GetResult(); }
80 catch (Exception ex) { Console.WriteLine($
"AllTypesExample failed: {ex.Message}\n"); }
83 try { ShardKeyExample.RunAsync(serverUrl, _ServerOptions.Username, _ServerOptions.Password).GetAwaiter().GetResult(); }
84 catch (Exception ex) { Console.WriteLine($
"ShardKeyExample failed: {ex.Message}\n"); }
87 try { AdoBatchInsertExample.RunAsync(serverUrl, _ServerOptions.Username, _ServerOptions.Password).GetAwaiter().GetResult(); }
88 catch (Exception ex) { Console.WriteLine($
"AdoBatchInsertExample failed: {ex.Message}\n"); }
92 Console.WriteLine($
"Caught Exception: {ex} {ex.Message} {ex.StackTrace}\n");
96 Console.WriteLine(
"=============================");
97 Console.WriteLine(
"= Example C# Project - Done =");
98 Console.WriteLine(
"=============================");
104 static void HandleCommand(
string[] args)
106 var command = args[0].ToLower();
107 var extraArgs = args.Length > 1 ? args[1..] :
Array.Empty<
string>();
117 BulkInserterDashboardExample.RunAsync().GetAwaiter().GetResult();
120 case "--integration":
121 BulkInserterFullIntegrationExample.RunAsync().GetAwaiter().GetResult();
124 case "--clear-table":
125 var tableName = extraArgs.Length > 0 ? extraArgs[0] :
"";
126 ClearTableExample.RunAsync(tableName).GetAwaiter().GetResult();
129 case "--cleanup-all":
130 var schemaPattern = extraArgs.Length > 0 ? extraArgs[0] :
"test_schema";
131 CleanupAllExample.RunAsync(schemaPattern).GetAwaiter().GetResult();
134 case "--show-tables":
135 var schemaFilter = extraArgs.Length > 0 ? extraArgs[0] :
"";
136 ShowTablesExample.Run(schemaFilter);
140 var truncateTable = extraArgs.Length > 0 ? extraArgs[0] :
"";
141 TruncateTableExample.RunAsync(truncateTable).GetAwaiter().GetResult();
144 case "--schema-demo":
145 SchemaBuilderDemo.Run();
149 Console.WriteLine($
"Unknown command: {command}");
158 static void PrintUsage()
160 Console.WriteLine(
"Usage:");
161 Console.WriteLine(
" dotnet run --project Example -- <url> <user> <password> [jdbc_driver_path]");
163 Console.WriteLine(
"Or use one of these commands:");
164 Console.WriteLine(
" --help Show this help message");
165 Console.WriteLine(
" --dashboard Run BulkInserter monitoring dashboard example");
166 Console.WriteLine(
" --integration Run BulkInserter full integration example");
167 Console.WriteLine(
" --clear-table <name> Clear all data from a table");
168 Console.WriteLine(
" --cleanup-all [pat] Drop all tables matching pattern (default: test_schema)");
169 Console.WriteLine(
" --show-tables [pat] List all tables (optionally filter by schema)");
170 Console.WriteLine(
" --truncate <name> Truncate a table (faster than clear-table)");
171 Console.WriteLine(
" --schema-demo Show schema builder examples and reference");
173 Console.WriteLine(
"Environment variables for commands:");
174 Console.WriteLine(
" KINETICA_URL Server URL (default: http://localhost:9191)");
175 Console.WriteLine(
" KINETICA_USER Username (default: admin)");
176 Console.WriteLine(
" KINETICA_PASSWORD Password (default: secret)");
178 Console.WriteLine(
"Examples:");
179 Console.WriteLine(
" dotnet run --project Example -- http://localhost:9191 admin secret");
180 Console.WriteLine(
" dotnet run --project Example -- --dashboard");
181 Console.WriteLine(
" dotnet run --project Example -- --integration");
182 Console.WriteLine(
" dotnet run --project Example -- --clear-table test_schema.my_table");
186 private const int columnWidth = 23;
187 private const int displayLimit = 50;
190 #region Console Method 191 private static string AlignCenter(
string text,
int width)
193 text = text.Length > width ?
string.Concat(text.AsSpan(0, width - 3),
"...") : text;
195 return !
string.IsNullOrEmpty(text)
196 ? text.PadRight(width - (width - text.Length) / 2).PadLeft(width)
197 :
new string(
' ', width);
200 private static void PrintRow(
string[] columns,
bool header =
false)
205 foreach (var column
in columns)
207 row += AlignCenter(column, columnWidth) +
"|";
208 line +=
new string(
'-', columnWidth) +
"+";
213 Console.WriteLine(line);
214 Console.WriteLine(row);
215 Console.WriteLine(line.Replace(
'-',
'='));
219 Console.WriteLine(row);
220 Console.WriteLine(line);
225 private static void PrintResult(DbDataReader reader)
227 var columns =
new List<string>();
229 for (var i = 0; i < reader.FieldCount; i++)
231 columns.Add(reader.GetName(i));
234 PrintRow([.. columns],
true);
236 while (reader.Read())
238 var items =
new List<string>();
240 for (var i = 0; i < reader.FieldCount; i++)
242 items.Add(reader.GetString(i));
245 PrintRow([.. items]);
251 private static string GenerateRandomId()
254 int randomNumber = random.Next(1000, 9999);
255 return $
"ID_{randomNumber}";
258 private static string GenerateRandomUrl()
260 string[] domains = [
"com",
"net",
"org",
"io",
"dev"];
261 string chars =
"abcdefghijklmnopqrstuvwxyz0123456789";
264 string randomSubdomain =
new(
265 [..
new char[8].Select(_ => chars[random.Next(chars.Length)])]);
267 string randomDomain =
new(
268 [..
new char[5].Select(_ => chars[random.Next(chars.Length)])]);
270 string randomPath =
new(
271 [..
new char[6].Select(_ => chars[random.Next(chars.Length)])]);
273 string domainExtension = domains[random.Next(domains.Length)];
275 return $
"https://{randomSubdomain}.{randomDomain}.{domainExtension}/{randomPath}";
278 private static string GenerateRandomName()
280 string[] firstNames = [
"Alice",
"Bob",
"Charlie",
"David",
"Eve",
"Frank",
"Grace",
"Helen",
"Ivy",
"Jack"];
281 string[] lastNames = [
"Smith",
"Johnson",
"Williams",
"Brown",
"Jones",
"Garcia",
"Miller",
"Davis",
"Rodriguez",
"Martinez"];
284 string firstName = firstNames[random.Next(firstNames.Length)];
285 string lastName = lastNames[random.Next(lastNames.Length)];
287 return $
"{firstName} {lastName}";
290 private static string GenerateGeometry() {
291 GeometryFactory factory =
new();
294 Polygon polygon = factory.CreatePolygon(
296 new Coordinate(0, 0),
297 new Coordinate(10, 0),
298 new Coordinate(10, 10),
299 new Coordinate(0, 10),
302 return polygon.AsText();
306 private static string GenerateRandomPolygon()
308 GeometryFactory factory =
new();
312 int numVertices = rand.Next(3, 11);
315 double minX = rand.NextDouble() * 50;
316 double maxX = minX + rand.NextDouble() * 50;
317 double minY = rand.NextDouble() * 50;
318 double maxY = minY + rand.NextDouble() * 50;
320 Coordinate[] coordinates =
new Coordinate[numVertices + 1];
322 for (
int i = 0; i < numVertices; i++)
324 double x = rand.NextDouble() * (maxX - minX) + minX;
325 double y = rand.NextDouble() * (maxY - minY) + minY;
326 coordinates[i] =
new Coordinate(x, y);
330 coordinates[numVertices] = coordinates[0];
333 LinearRing ring = factory.CreateLinearRing(coordinates);
334 Polygon polygon = factory.CreatePolygon(ring);
336 return polygon.AsText();
339 private static DateTime GenerateRandomDate(DateTime start, DateTime end)
342 int range = (int)(end - start).TotalSeconds;
343 return start.AddSeconds(random.Next(range));
356 private static void JdbcExample(
string driverPath,
string serverUrl,
string username,
string password)
359 Console.WriteLine(
"Example Using a JDBC Bridge Library and the Kinetica JDBC Driver");
360 Console.WriteLine(
"================================================================");
363 if ( driverPath.Length == 0)
365 Console.WriteLine(
"No Kinetica JDBC driver given; e.g.: kinetica-jdbc-7.2.2.8-jar-with-dependencies.jar\n");
369 var builder =
new JdbcConnectionStringBuilder
371 DriverPath = driverPath,
372 DriverClass =
"com.kinetica.jdbc.Driver",
373 JdbcUrl = $
"jdbc:kinetica:URL={serverUrl};UID={username};PWD={password}" 376 using var connection =
new JdbcConnection(builder);
377 Console.WriteLine(
"Establishing connection...");
379 Console.WriteLine(
"Connection established!\n");
381 using JdbcCommand command = connection.CreateCommand();
383 Console.WriteLine(
"Creating table...");
386 string ddl =
@"CREATE OR REPLACE TABLE csharp_example_jdbc 388 object_id VARCHAR NOT NULL, 389 name VARCHAR NOT NULL, 390 url VARCHAR NOT NULL, 391 bounding_box GEOMETRY NOT NULL, 392 created_at DATETIME NOT NULL, 393 updated_at DATETIME NOT NULL, 394 PRIMARY KEY (object_id) 398 command.CommandText = ddl;
400 command.ExecuteNonQuery();
404 Console.WriteLine($
"Error creating table: {e}\n");
408 Console.WriteLine(
"Inserting data...");
411 command.CommandText =
"INSERT INTO csharp_example_jdbc VALUES (@ObjectId, @Name, @Url, @BoundingBox, @CreatedAt, @UpdatedAt)";
412 command.Parameters.Clear();
414 int rowsInserted = 0;
415 for (
int i = 0; i < 10; i++)
417 command.Parameters.AddWithValue(
"@ObjectId", GenerateRandomId());
418 command.Parameters.AddWithValue(
"@Name", GenerateRandomName());
419 command.Parameters.AddWithValue(
"@Url", GenerateRandomUrl());
420 command.Parameters.AddWithValue(
"@BoundingBox", GenerateRandomPolygon());
421 command.Parameters.AddWithValue(
"@CreatedAt", GenerateRandomDate(
new DateTime(2024, 1, 1),
DateTime.Now).ToString(
"yyyy-MM-dd HH:mm:ss"));
422 command.Parameters.AddWithValue(
"@UpdatedAt", GenerateRandomDate(
new DateTime(2024, 1, 1),
DateTime.Now).ToString(
"yyyy-MM-dd HH:mm:ss"));
424 int rowsAffected = command.ExecuteNonQuery();
425 command.Parameters.Clear();
426 rowsInserted += rowsAffected + 1;
428 Console.WriteLine($
"Rows inserted: {rowsInserted}\n");
430 catch (System.Data.Common.DbException ex)
432 Console.WriteLine($
"Error inserting data: {ex}\n");
436 Console.WriteLine(
"Executing query...");
439 command.CommandText =
"SELECT * FROM csharp_example_jdbc ORDER BY object_id";
440 command.Parameters.Clear();
442 using var reader = command.ExecuteReader();
446 catch (System.Data.Common.DbException ex)
448 Console.WriteLine($
"Error executing query: {ex}\n");
452 Console.WriteLine(
"Updating data...");
455 command.CommandText =
"UPDATE csharp_example_jdbc SET url = 'https://www.kinetica.com' WHERE object_id = (SELECT MIN(object_id) FROM csharp_example_jdbc)";
456 int rowsUpdated = command.ExecuteNonQuery();
457 Console.WriteLine($
"Rows updated: {rowsUpdated}\n");
459 catch (System.Data.Common.DbException ex)
461 Console.WriteLine($
"Error updating data: {ex}\n");
465 Console.WriteLine(
"Deleting data...");
468 command.CommandText =
"DELETE FROM csharp_example_jdbc WHERE object_id = (SELECT MAX(object_id) FROM csharp_example_jdbc)";
469 int rowsDeleted = command.ExecuteNonQuery();
470 Console.WriteLine($
"Rows deleted: {rowsDeleted}\n");
472 catch (System.Data.Common.DbException ex)
474 Console.WriteLine($
"Error updating data: {ex}\n");
477 Console.WriteLine(
"Checking data after modifications...");
480 command.CommandText =
"SELECT * FROM csharp_example_jdbc ORDER BY object_id";
481 command.Parameters.Clear();
483 using var reader = command.ExecuteReader();
487 catch (System.Data.Common.DbException ex)
489 Console.WriteLine($
"Error checking data: {ex}\n");
503 private static void RunExample(
string serverUrl,
Kinetica.Options serverOptions)
506 Console.WriteLine(
"Example with a Record Type with Nullable Columns, Primary Keys and Shard Keys");
507 Console.WriteLine(
"=============================================================================");
511 Kinetica kdb =
new(serverUrl, serverOptions);
513 string tableName =
"csharp_example_table";
516 Console.WriteLine(
"Creating the type in kinetica...");
518 Dictionary<string, IList<string>> columnProperties =
new()
531 string exampleTypeId = exampleType.
create(kdb);
532 Console.WriteLine($
"ID of the created type: {exampleTypeId}\n");
535 Console.WriteLine(
"Fetching the newly created type information...");
537 Console.WriteLine(
"Type properties:");
538 foreach ( var x
in responseShowTypes.
properties[0] )
539 Console.WriteLine($
"\t{x.Key}: {String.Join(",
", x.Value)}");
543 Console.WriteLine($
"Clearing any existing table named '{tableName}'...\n");
547 Console.WriteLine($
"Creating table named '{tableName}'...\n");
552 Console.WriteLine($
"Calling ShowTable on '{tableName}'...");
553 var responseShowTable = kdb.
showTable(tableName, optionsShowTable);
554 Console.WriteLine($
"Total size: {responseShowTable.total_size}");
555 Console.WriteLine($
"Sizes: {string.Join(",
", responseShowTable.sizes)}\n");
558 List<ExampleRecord> newData = [
559 new ExampleRecord() { A=99, B=11, C=
"T0_lksdjfokdj92", D=
"D01", E= 2.34F, F=
null, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds },
560 new ExampleRecord() { A=2, B=3, C=
"T1_asdfghjkl", D=
null, E= 5.67F, F=
null, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds },
561 new ExampleRecord() { A=99, B=999, C=
"T2_oierlwk", D=
"D244", E=-45.1F, F=9899.1, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds }
565 Console.WriteLine($
"Inserting some data in '{tableName}'...");
566 var responseInsert = kdb.insertRecords( tableName, newData );
567 Console.WriteLine($
"Inserted {responseInsert.count_inserted + responseInsert.count_updated} records\n");
570 Console.WriteLine($
"Calling ShowTable on '{tableName}' after adding data...");
571 responseShowTable = kdb.
showTable(tableName, optionsShowTable);
572 Console.WriteLine($
"Total size: {responseShowTable.total_size}");
573 Console.WriteLine($
"Sizes: {string.Join( ",
", responseShowTable.sizes )}\n");
576 Console.WriteLine($
"Getting records from table '{tableName}'...");
577 var responseGetRecords = kdb.getRecords<ExampleRecord>( tableName, 0, 100 );
578 Console.WriteLine($
"GetRecords got {responseGetRecords.data.Count} records:");
579 foreach ( var r
in responseGetRecords.data )
580 Console.WriteLine($
"\t{r}");
584 Console.WriteLine($
"Filtering data from table '{tableName}'...");
585 string filterName =
"csharp_example_filter";
586 string filterExpression =
"E > 0";
587 var filterResponse = kdb.
filter( tableName, filterName, filterExpression );
588 Console.WriteLine($
"Filtered {filterResponse.count} records into '{filterName}'\n");
591 Console.WriteLine($
"Performing a group-by aggregate operation on table '{tableName}'...");
592 IList<string> columnNames = [
"A",
"D"];
593 var responseGroupBy = kdb.
aggregateGroupBy( tableName, columnNames, 0, 100 );
594 Console.WriteLine($
"Group by got {responseGroupBy.total_number_of_records} records:");
596 ( ( List<KineticaRecord> ) ( responseGroupBy.data ) ).ForEach( r => Console.WriteLine($
"\t{r.ContentsToString()}") );
600 string columnName =
"F";
601 Console.WriteLine($
"Performing a unique aggregate operation on column '{tableName}.{columnName}'...");
602 var uniqueResponse = kdb.
aggregateUnique( tableName, columnName, 0, 100 );
604 ( ( List<KineticaRecord> ) ( uniqueResponse.data ) ).ForEach( r => Console.WriteLine($
"\t{r.ContentsToString()}") );
608 Console.WriteLine($
"Getting records out (using /get/records/bycolumn) on table '{tableName}'...");
609 columnNames = [
"B",
"C",
"E"];
610 var responseGetRecordsByColumn = kdb.
getRecordsByColumn( tableName, columnNames, 0, 100 );
611 Console.WriteLine($
"GetRecordsByColumn got {responseGetRecordsByColumn.data.Count} records:");
612 foreach ( var r
in responseGetRecordsByColumn.data )
613 Console.WriteLine($
"\t{r.ContentsToString()}");
614 Console.WriteLine(
"\n");
628 private static void RunSeriesExample(
string serverUrl,
Kinetica.Options serverOptions )
631 Console.WriteLine(
"Example showcasing a record with a series type column");
632 Console.WriteLine(
"=====================================================");
636 Kinetica kdb =
new( serverUrl, serverOptions );
638 Dictionary<string, IList<string>> columnProperties =
new()
646 string seriesTypeId = seriesType.
create( kdb );
647 Console.WriteLine($
"ID of the created series type: {seriesTypeId}\n");
650 string tableName =
"csharp_example_series_table";
651 Console.WriteLine($
"Clearing any existing table named '{tableName}'...\n");
655 Console.WriteLine($
"Creating table named '{tableName}'...\n");
659 string series1 =
"series_1";
660 string series2 =
"series_2";
661 List<SeriesRecord> seriesData =
664 new SeriesRecord() { x = decimal.Parse(
"30").ToString(
"F4"), y = 40, TRACKID = series1, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds },
665 new SeriesRecord() { x = decimal.Parse(
"35").ToString(
"F4"), y = 40, TRACKID = series1, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds },
666 new SeriesRecord() { x = decimal.Parse(
"40").ToString(
"F4"), y = 40, TRACKID = series1, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds },
667 new SeriesRecord() { x = decimal.Parse(
"45").ToString(
"F4"), y = 40, TRACKID = series1, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds },
668 new SeriesRecord() { x = decimal.Parse(
"50").ToString(
"F4"), y = 40, TRACKID = series1, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds },
670 new SeriesRecord() { x = decimal.Parse(
"-30").ToString(
"F4"), y = -40, TRACKID = series2, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds },
671 new SeriesRecord() { x = decimal.Parse(
"-30").ToString(
"F4"), y = -45, TRACKID = series2, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds },
672 new SeriesRecord() { x = decimal.Parse(
"-30").ToString(
"F4"), y = -50, TRACKID = series2, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds },
673 new SeriesRecord() { x = decimal.Parse(
"-30").ToString(
"F4"), y = -55, TRACKID = series2, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds },
674 new SeriesRecord() { x = decimal.Parse(
"-30").ToString(
"F4"), y = -60, TRACKID = series2, TIMESTAMP= (long)(
DateTime.UtcNow -
new DateTime(1970, 1, 1)).TotalMilliseconds },
678 Console.WriteLine($
"Inserting some data in '{tableName}'...");
679 var responseInsert = kdb.insertRecords(tableName, seriesData);
680 Console.WriteLine($
"Inserted {responseInsert.count_inserted + responseInsert.count_updated} records\n");
684 Console.WriteLine($
"Getting records from table '{tableName}'...");
685 var responseGetRecords = kdb.getRecords<SeriesRecord>(tableName);
686 Console.WriteLine($
"GetRecords got {responseGetRecords.data.Count} records:");
687 foreach (var r
in responseGetRecords.data)
688 Console.WriteLine($
"\t{r}");
694 Console.WriteLine($
"Filtering data from {tableName} so that only some points from {series1} make it...");
695 string filterName =
"csharp_example_series_filter";
699 var responseFilter = kdb.
filterByBox( tableName, filterName,
"x", 33, 37,
"y", 35, 45 );
700 Console.WriteLine($
"Filtered {responseFilter.count} records into '{filterName}'\n");
703 responseGetRecords = kdb.getRecords<SeriesRecord>( filterName );
704 Console.WriteLine($
"GetRecords got {responseGetRecords.data.Count} records from '{filterName}':");
705 foreach ( var r
in responseGetRecords.data )
706 Console.WriteLine($
"\t{r}");
711 Console.WriteLine($
"Getting records belonging to one series out from table '{tableName}' using the partial series in filter '{filterName}'...");
712 var getRecordsBySeriesResp = kdb.getRecordsBySeries<SeriesRecord>( filterName, tableName );
713 Console.WriteLine($
"GetRecordsBySeries got {getRecordsBySeriesResp.data.Count} list of records (should get one list of five records in it):");
714 foreach ( var rSeries
in getRecordsBySeriesResp.data )
715 foreach ( var r
in rSeries ) Console.WriteLine($
"\t{r}");
716 Console.WriteLine(
"\n");
728 private static void RunMultiheadIngestExample(
string serverUrl,
Kinetica.Options serverOptions )
731 Console.WriteLine(
"Example showcasing multihead ingestion(one shard key, two primary keys)");
732 Console.WriteLine(
"=======================================================================");
736 Kinetica kdb =
new( serverUrl, serverOptions );
740 Dictionary<string, IList<string>> columnProperties =
new()
753 string exampleTypeId = exampleType.
create( kdb );
756 string tableName =
"csharp_example_multihead_table";
757 Console.WriteLine($
"Clearing any existing table named '{tableName}'...\n");
761 Console.WriteLine($
"Creating table named '{tableName}'...\n");
770 int totalRecords = batchSize * 5;
771 List<ExampleRecord> records = [];
773 double nullProbability = 0.2;
774 for (
int i = 0; i < totalRecords; ++i )
777 int maxStringLength = rng.Next( 0, 256 );
778 ExampleRecord record =
new ()
782 C = System.IO.Path.GetRandomFileName().Truncate( maxStringLength ),
783 D = System.IO.Path.GetRandomFileName().Truncate( maxStringLength ),
784 E = (1.0F / rng.Next()),
785 F = ( rng.NextDouble() < nullProbability ) ?
null : (
double? ) ( rng.NextDouble() * (1.0F / rng.Next()) ),
786 TIMESTAMP = (long)rng.Next( -306102240, 293795424 ) * rng.Next( 100000 )
789 records.Add( record );
792 Console.WriteLine( $
"Generated {totalRecords} records.\n" );
795 Console.WriteLine( $
"Inserting {totalRecords} records..." );
796 ingestor.
insert( records );
799 Console.WriteLine(
"Flushing any remaining records..." );
803 Console.WriteLine($
"Calling ShowTable on '{tableName}' after adding data...");
805 Console.WriteLine($
"Total size: {responseShowTable.total_size}");
807 Console.WriteLine(
"\n");
811 private class ExampleRecord
813 public int A {
get;
set; }
814 public int B {
get;
set; }
815 public string? C {
get;
set; }
816 public string? D {
get;
set; }
817 public float E {
get;
set; }
818 public double? F {
get;
set; }
819 public long TIMESTAMP {
get;
set; }
821 public override string ToString()
828 return $
"{{ A={A}, B={B}, C={C}, D={D}, E={E}, F={f}, TIMESTAMP={TIMESTAMP} }}";
833 private class SeriesRecord
835 public string? x {
get;
set; }
836 public double y {
get;
set; }
837 public string? TRACKID {
get;
set; }
838 public long TIMESTAMP {
get;
set; }
840 public override string ToString()
842 return $
"{{ x={x}, y={y}, TRACKID={TRACKID}, TIMESTAMP={TIMESTAMP} }}";
void insert(T record)
Queues a record for insertion into Kinetica.
const string PRIMARY_KEY
This property indicates that this column will be part of (or the entire) primary key.
const string GET_SIZES
If TRUE then the number of records in each table, along with a cumulative count, will be returned; bl...
IList< IDictionary< string, IList< string > > > properties
CreateTableResponse createTable(CreateTableRequest request_)
Creates a new table with the given type (definition of columns).
A set of parameters for Kinetica.clearTable.
Column properties used for Kinetica types.
const string TIMESTAMP
Valid only for 'long' columns.
const string CHAR4
This property provides optimized memory, disk and query performance for string columns.
AggregateGroupByResponse aggregateGroupBy(AggregateGroupByRequest request_)
Calculates unique combinations (groups) of values for the given columns in a given table or view and ...
const string DECIMAL
Valid only for 'string' columns.
A set of string constants for the parameter options.
ClearTableResponse clearTable(ClearTableRequest request_)
Clears (drops) one or all tables in the database cluster.
ShowTableResponse showTable(ShowTableRequest request_)
Retrieves detailed information about a table, view, or schema, specified in table_name.
static KineticaType fromClass(Type recordClass, IDictionary< string, IList< string >> properties=null)
Create a KineticaType object from properties of a record class and Kinetica column properties.
A set of parameters for Kinetica.showTable.
const string SHARD_KEY
This property indicates that this column will be part of (or the entire) shard key.
A set of string constants for the parameter options.
string create(Kinetica kinetica)
Given a handle to the server, creates a type in the database based on this data type.
static string Truncate(this string value, int maxLength)
FilterResponse filter(FilterRequest request_)
Filters data based on the specified expression.
Failover to clusters in a random order (default)
AggregateUniqueResponse aggregateUnique(AggregateUniqueRequest request_)
Returns all the unique values from a particular column (specified by column_name) of a particular tab...
ShowTypesResponse showTypes(ShowTypesRequest request_)
Retrieves information for the specified data type ID or type label.
GetRecordsByColumnResponse getRecordsByColumn(GetRecordsByColumnRequest request_)
For a given table, retrieves the values from the requested column(s).
FilterByBoxResponse filterByBox(FilterByBoxRequest request_)
Calculates how many objects within the given table lie in a rectangular box.
const string NO_ERROR_IF_NOT_EXISTS
If TRUE and if the table specified in table_name does not exist no error is returned.
DateTime in YYYY-MM-DD HH:MM:SS.mmm format
const string NULLABLE
This property indicates that this column is nullable.
A set of results returned by Kinetica.showTypes.
Manages the insertion into GPUdb of large numbers of records in bulk, with automatic batch management...
void flush()
Ensures that all queued records are inserted into Kinetica.