7 using System.Text.RegularExpressions;
11 using NetTopologySuite.Geometries;
21 public static string Truncate(
this string value,
int maxLength )
23 if (
string.IsNullOrEmpty( value ) )
26 return ( value.Length <= maxLength ) ? value : value[..maxLength];
38 static void Main(
string[] args )
40 Console.WriteLine(
"=============================");
41 Console.WriteLine(
"= Test C# Project - Running =");
42 Console.WriteLine(
"=============================");
45 if ( args.Length < 1 )
47 Console.WriteLine(
"Missing URL as command-line parameter." );
48 Console.WriteLine(
"E.g., http://kinetica:9191" );
54 string server_url = args[0];
55 Console.WriteLine(
"URL: {0}", server_url );
58 ProcessArgs(args, out
Kinetica.
Options? _ServerOptions, out
string? _JdbcDriverPath);
60 if (_ServerOptions ==
null) {
61 Console.WriteLine(
"Command line parameters can be either [<oauth_token>] or [<username> <password> <JDBC Bridge Driver JAR]");
62 throw new Exception(
"Invalid command line parameters");
68 TestDml(server_url, _ServerOptions);
69 TestOauth2Authentication( server_url, _ServerOptions );
70 TestAuthentication( server_url, _ServerOptions );
71 TestAllTypesAllShard( server_url, _ServerOptions );
72 TestAllTypesIpRegex3Shard0Pk(server_url, _ServerOptions);
73 TestAllTypes3Pk3Shard( server_url, _ServerOptions );
74 TestAllTypes3Pk0Shard( server_url, _ServerOptions );
75 TestRecordRetrievalByKey( server_url, _ServerOptions );
76 TestJdbc(server_url, _ServerOptions, _JdbcDriverPath);
80 Console.WriteLine(
"Caught InsertException: {0}", ex.Message );
84 Console.WriteLine(
"Caught KineticaException: {0}", ex.Message );
86 catch ( Exception ex )
88 Console.WriteLine(
"Caught Exception: {0}", ex.Message );
92 Console.WriteLine(
"==========================");
93 Console.WriteLine(
"= Test C# Project - Done =");
94 Console.WriteLine(
"==========================");
98 jdbcDriverPath =
null;
104 else if (args.Length <= 2)
121 if (args.Length >= 4)
122 jdbcDriverPath = args[3];
128 private static string GenerateRandomId()
130 Random random =
new();
131 int randomNumber = random.Next(1000, 9999);
132 return $
"ID_{randomNumber}";
135 private static string GenerateRandomUrl()
137 string[] domains = [
"com",
"net",
"org",
"io",
"dev"];
138 string chars =
"abcdefghijklmnopqrstuvwxyz0123456789";
139 Random random =
new();
141 string randomSubdomain =
new(
142 [..
new char[8].Select(_ => chars[random.Next(chars.Length)])]);
144 string randomDomain =
new(
145 [..
new char[5].Select(_ => chars[random.Next(chars.Length)])]);
147 string randomPath =
new(
148 [..
new char[6].Select(_ => chars[random.Next(chars.Length)])]);
150 string domainExtension = domains[random.Next(domains.Length)];
152 return $
"https://{randomSubdomain}.{randomDomain}.{domainExtension}/{randomPath}";
155 private static string GenerateRandomName()
157 string[] firstNames = [
"Alice",
"Bob",
"Charlie",
"David",
"Eve",
"Frank",
"Grace",
"Helen",
"Ivy",
"Jack"];
158 string[] lastNames = [
"Smith",
"Johnson",
"Williams",
"Brown",
"Jones",
"Garcia",
"Miller",
"Davis",
"Rodriguez",
"Martinez"];
160 Random random =
new();
161 string firstName = firstNames[random.Next(firstNames.Length)];
162 string lastName = lastNames[random.Next(lastNames.Length)];
164 return $
"{firstName} {lastName}";
167 private static string GenerateGeometry() {
168 GeometryFactory factory =
new();
171 Polygon polygon = factory.CreatePolygon(
173 new Coordinate(0, 0),
174 new Coordinate(10, 0),
175 new Coordinate(10, 10),
176 new Coordinate(0, 10),
179 return polygon.AsText();
183 private static string GenerateRandomPolygon()
185 GeometryFactory factory =
new();
189 int numVertices = rand.Next(3, 11);
192 double minX = rand.NextDouble() * 50;
193 double maxX = minX + rand.NextDouble() * 50;
194 double minY = rand.NextDouble() * 50;
195 double maxY = minY + rand.NextDouble() * 50;
197 Coordinate[] coordinates =
new Coordinate[numVertices + 1];
199 for (
int i = 0; i < numVertices; i++)
201 double x = rand.NextDouble() * (maxX - minX) + minX;
202 double y = rand.NextDouble() * (maxY - minY) + minY;
203 coordinates[i] =
new Coordinate(x, y);
207 coordinates[numVertices] = coordinates[0];
210 LinearRing ring = factory.CreateLinearRing(coordinates);
211 Polygon polygon = factory.CreatePolygon(ring);
213 return polygon.AsText();
216 private static DateTime GenerateRandomDate(DateTime start, DateTime end)
218 Random random =
new();
219 int range = (int)(end - start).TotalSeconds;
220 return start.AddSeconds(random.Next(range));
223 private class LayerDTO
225 public string? ObjectId {
get;
set; }
226 public string? Name {
get;
set; }
227 public string? Url {
get;
set; }
228 public string? BoundingBox {
get;
set; }
229 public string? CreatedAt {
get;
set; }
230 public string? UpdatedAt {
get;
set; }
233 private static void TestDml(
string server_url,
Kinetica.
Options _ServerOptions )
235 Console.WriteLine(
"\n\n");
236 Console.WriteLine(
"Test DML");
237 Console.WriteLine(
"========");
240 string Ddl =
@"CREATE OR REPLACE TABLE layers 242 ObjectId VARCHAR (primary_key) NOT NULL, 243 Name VARCHAR NOT NULL, 244 Url VARCHAR NOT NULL, 245 BoundingBox GEOMETRY NOT NULL, 246 CreatedAt DATETIME NOT NULL, 247 UpdatedAt DATETIME NOT NULL 251 Kinetica kdb =
new( server_url, _ServerOptions );
252 string table_name =
"layers";
260 List<LayerDTO> records = [];
263 for(
int i=0; i < 10; i++ ) {
264 LayerDTO record =
new()
266 ObjectId = GenerateRandomId(),
267 Name = GenerateRandomName(),
268 Url = GenerateRandomUrl(),
269 BoundingBox = GenerateRandomPolygon(),
270 CreatedAt = GenerateRandomDate(
new DateTime(2024, 1, 1), DateTime.Now).ToString(
"yyyy-MM-dd HH:mm:ss"),
271 UpdatedAt = GenerateRandomDate(
new DateTime(2024, 1, 1), DateTime.Now).ToString(
"yyyy-MM-dd HH:mm:ss")
276 Console.WriteLine($
"Inserting {records.Count} records...");
277 kdb.insertRecords(table_name, records);
279 Console.WriteLine($
"IDs inserted:");
280 string? firstId =
null;
281 string? lastId =
null;
283 foreach( var record
in getRecordsResponse.
data ) {
284 firstId ??= record.ObjectId;
285 lastId = record.ObjectId;
286 Console.WriteLine(lastId);
291 Console.WriteLine($
"Updating record {lastId}...");
292 string expression = $
"ObjectId = '{lastId ?? ""}'";
293 var newValueMap =
new Dictionary<string, string>
295 [
"Name"] =
"John Doe",
296 [
"Url"] =
"www.kinetica.com" 298 UpdateRecordsResponse updateRecordsResponse = kdb.updateRecords<LayerDTO>(table_name, [expression], [newValueMap]);
299 Console.WriteLine($
"Updated {updateRecordsResponse.count_updated} record\n");
302 Console.WriteLine($
"Deleting record {firstId}...");
303 expression = $
"ObjectId = '{firstId ?? ""}'";
305 Console.WriteLine($
"Deleted {deleteRecordsResponse.count_deleted} record\n");
310 private class RecordTypeShort
312 public int i {
get;
set; }
313 public int i8 {
get;
set; }
315 public override string ToString()
317 return $
"{{ i={i}, i8={i8} }}";
322 private static void TestOauth2Authentication(
string serverUrl,
Kinetica.
Options serverOptions )
324 Console.WriteLine(
"\n\n" );
325 Console.WriteLine(
"Test OAuth2 Authentication" );
326 Console.WriteLine(
"==========================" );
329 if (serverOptions.OauthToken ==
string.Empty)
330 Console.WriteLine(
"Skipping--OAuth token not passed");
334 Console.WriteLine(
"Token passed : " + serverOptions.OauthToken);
335 Kinetica kdb_ =
new(serverUrl, serverOptions);
336 string json = JsonConvert.SerializeObject(kdb_.
showSystemStatus(
new Dictionary<string, string>()).
status_map, Formatting.Indented);
337 Console.WriteLine(json);
341 private static void TestAuthentication(
string serverUrl,
Kinetica.
Options serverOptions)
343 Console.WriteLine(
"\n\n");
344 Console.WriteLine(
"Test Authentication");
345 Console.WriteLine(
"===================");
348 string username =
"csharp_test_user";
349 string password =
"csharp_test_pass";
351 Console.WriteLine($
"Establishing connection with {serverOptions.Username} user...\n");
352 Kinetica kdb_ =
new(serverUrl, serverOptions);
355 Console.WriteLine($
"Creating a user {username}...\n");
364 Console.WriteLine($
"Error creating user: {ex.Message}");
368 Console.WriteLine($
"Establishing a connection with {username} user and valid password...\n");
374 Kinetica kdbUser =
new(serverUrl, connectOptions);
376 kdbUser.
getRecordsByColumn(
"ITER", [
"USER() AS username"]).
data.First().TryGetValue(
"username", out gotUsername);
378 Console.WriteLine($
"Created user name: {gotUsername}\n");
381 Console.WriteLine($
"Establishing a connection with {username} user and invalid password...\n");
384 connectOptions.Password =
"";
386 kdbUser =
new(serverUrl, connectOptions);
387 kdbUser.
getRecordsByColumn(
"ITER", [
"USER() AS username"]).
data.First().TryGetValue(
"username", out gotUsername);
388 Console.WriteLine($
"Unexpected success logging in with invalid credentials for {gotUsername}!");
392 Console.WriteLine($
"Expected error logging in with invalid credentials: {ex.Message}");
397 private class RecordTypeAll
399 public int? i {
get;
set; }
400 public int? i8 {
get;
set; }
401 public int? i16 {
get;
set; }
402 public long l {
get;
set; }
403 public float? f {
get;
set; }
404 public double? d {
get;
set; }
405 public string? s {
get;
set; }
406 public string? c1 {
get;
set; }
407 public string? c2 {
get;
set; }
408 public string? c4 {
get;
set; }
409 public string? c8 {
get;
set; }
410 public string? c16 {
get;
set; }
411 public string? c32 {
get;
set; }
412 public string? c64 {
get;
set; }
413 public string? c128 {
get;
set; }
414 public string? c256 {
get;
set; }
415 public string? date {
get;
set; }
416 public string? datetime {
get;
set; }
417 public string? decimal_ {
get;
set; }
418 public string? ipv4 {
get;
set; }
419 public string? time {
get;
set; }
420 public long? timestamp {
get;
set; }
422 public override string ToString()
429 return $
"{{ i={i}, i8={i8}, i16={i16}, l={l}, f={f}, d={d_}, s={s}, c1={c1}, c2={c2}, c4={c4}, c8={c8}, c16={c16}, c32={c32}, c64={c64}, c128={c128}, c256={c256}, date={date}, datetime={datetime}, decimal_={decimal_}, ipv4={ipv4}, time={time}, timestamp={timestamp} }}";
434 private static void TestAllTypesAllShard(
string serverUrl,
Kinetica.
Options serverOptions )
437 Kinetica kdb =
new( serverUrl, serverOptions );
439 Console.WriteLine(
"\n\n" );
440 Console.WriteLine(
"Test Multihead Ingest: One column per Type; All are Shard Keys, 0 Primary Keys" );
441 Console.WriteLine(
"==============================================================================" );
444 Console.WriteLine(
"Creating a type with all column types (all are nullable and shard columns).\n" );
448 Dictionary<string, IList<string>> column_properties =
new()
478 string type_id = allType.
create( kdb );
479 Console.WriteLine(
"Created type.\n" );
481 string tableName =
"csharp_test_table_all_shards";
483 Console.WriteLine( $
"Clearing any existing table named '{tableName}'..." );
487 Console.WriteLine( $
"Creating table named '{tableName}'\n" );
492 int batchSize = 1000;
497 int totalRecords = batchSize * 10;
498 Console.WriteLine( $
"Starting to generate {totalRecords} records.\n" );
499 List<RecordTypeAll> records = [];
501 double nullProbability = 0.15;
502 for (
int i = 0; i < totalRecords; ++i )
505 int max_str_len = rng.Next( 0, 256 );
506 RecordTypeAll record =
new()
508 i = ( rng.NextDouble() < nullProbability ) ?
null : (
int?) rng.Next(),
509 i8 = ( rng.NextDouble() < nullProbability ) ?
null : (
int?) rng.Next( -128, 128 ),
510 i16 = ( rng.NextDouble() < nullProbability ) ?
null : (
int?) rng.Next( -32768, 32768),
511 l = (long)rng.Next(),
513 f = ( rng.NextDouble() < nullProbability ) ?
null : (
float?)(rng.NextDouble() * rng.Next()),
514 d = ( rng.NextDouble() < nullProbability ) ?
null : (
double? ) ( rng.NextDouble() * rng.Next() ),
515 s = ( rng.NextDouble() < nullProbability ) ?
null : System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
516 c1 = ( rng.NextDouble() < nullProbability ) ?
null : System.IO.Path.GetRandomFileName().Truncate( 1 ),
517 c2 = ( rng.NextDouble() < nullProbability ) ?
null : System.IO.Path.GetRandomFileName().Truncate( 2 ),
518 c4 = ( rng.NextDouble() < nullProbability ) ?
null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 5) ),
519 c8 = ( rng.NextDouble() < nullProbability ) ?
null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 9) ),
520 c16 = ( rng.NextDouble() < nullProbability ) ?
null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 17) ),
521 c32 = ( rng.NextDouble() < nullProbability ) ?
null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 5, 33) ),
522 c64 = ( rng.NextDouble() < nullProbability ) ?
null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 65) ),
523 c128 = ( rng.NextDouble() < nullProbability ) ?
null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 129) ),
524 c256 = ( rng.NextDouble() < nullProbability ) ?
null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 25, 257) ),
525 date = ( rng.NextDouble() < nullProbability ) ?
null :
Test.GenerateDate( rng ),
526 datetime = (rng.NextDouble() < nullProbability) ?
null :
Test.GenerateDateTime(rng),
527 decimal_ = (rng.NextDouble() < nullProbability) ?
null :
Test.GenerateDecimal(rng),
528 ipv4 = ( rng.NextDouble() < nullProbability ) ?
null :
Test.GenerateIpv4( rng ),
529 time = (rng.NextDouble() < nullProbability) ?
null :
Test.GenerateTime(rng),
530 timestamp = ( rng.NextDouble() < nullProbability ) ?
null : ((
long?)rng.Next( -306102240, 293795424 ) * rng.Next( 100000 ))
534 records.Add( record );
535 ingestor.
insert( record );
538 Console.WriteLine( $
"Generated {totalRecords} records." );
541 Console.WriteLine( $
"Inserting {totalRecords} records..." );
542 ingestor.
insert( records );
545 Console.WriteLine(
"\nFlushing any remaining records." );
551 private static void TestAllTypesIpRegex3Shard0Pk(
string serverUrl,
Kinetica.
Options serverOptions )
554 Kinetica kdb =
new( serverUrl, serverOptions );
556 Console.WriteLine(
"\n\n" );
557 Console.WriteLine(
"Test Multihead Ingest with a Regex Given for Worker IP Addresses (3 shard keys, no PKs)" );
558 Console.WriteLine(
"=======================================================================================" );
563 Dictionary<string, IList<string>> column_properties =
new()
574 string recordAllTypeId = recordAllType.
create( kdb );
576 string tableName =
"csharp_test_table_3s0pk";
578 Console.WriteLine($
"Clearing any existing table named '{tableName}'...");
582 Console.WriteLine( $
"Creating table named '{tableName}'...\n" );
588 Regex ipRegex =
new(
"127.0.*" );
593 int totalRecords = batchSize * 5;
594 List<RecordTypeAll> records = [];
596 double nullProbability = 0.2;
597 for (
int i = 0; i < totalRecords; ++i )
600 int max_str_len = rng.Next( 0, 256 );
601 RecordTypeAll record =
new()
606 l = (long)rng.Next(),
607 f = (float)(rng.NextDouble() * rng.Next()),
608 d = ( rng.NextDouble() < nullProbability ) ?
null : (
double? ) ( rng.NextDouble() * rng.Next() ),
609 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
610 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
611 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
612 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
613 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
614 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
615 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
616 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
617 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
618 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
619 date =
Test.GenerateDate( rng ),
620 datetime =
Test.GenerateDateTime( rng ),
621 decimal_ =
Test.GenerateDecimal( rng ),
622 ipv4 =
Test.GenerateIpv4( rng ),
623 time =
Test.GenerateTime( rng ),
624 timestamp = (long) rng.Next()
628 records.Add( record );
631 Console.WriteLine( $
"Generated {totalRecords} records." );
634 Console.WriteLine( $
"Inserting {totalRecords} records..." );
635 ingestor.
insert( records );
638 Console.WriteLine(
"\nFlushing any remaining records." );
645 private static void TestAllTypes3Pk3Shard(
string serverUrl,
Kinetica.
Options serverOptions )
648 Kinetica kdb =
new( serverUrl, serverOptions );
650 Console.WriteLine(
"\n\n" );
651 Console.WriteLine(
"Test Multihead Ingest: One column per Type; 3 Primary Keys, 3 Shard Keys" );
652 Console.WriteLine(
"========================================================================" );
657 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>
668 string recordAllTypeId = recordAllType.
create( kdb );
670 string tableName =
"csharp_test_table_3s3pk";
672 Console.WriteLine($
"Clearing any existing table named '{tableName}'...");
676 Console.WriteLine( $
"Creating table named '{tableName}'...\n");
684 int totalRecords = batchSize * 50;
686 double nullProbability = 0.2;
687 for (
int i = 0; i < totalRecords; ++i )
690 int maxStringLength = rng.Next( 0, 256 );
691 RecordTypeAll record =
new()
696 l = (long)rng.Next(),
697 f = (float)(rng.NextDouble() * rng.Next()),
698 d = ( rng.NextDouble() < nullProbability ) ?
null : (
double? ) ( rng.NextDouble() * rng.Next() ),
699 s = System.IO.Path.GetRandomFileName().Truncate( maxStringLength ),
700 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
701 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
702 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
703 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
704 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
705 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
706 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
707 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
708 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
709 date =
Test.GenerateDate( rng ),
710 datetime =
Test.GenerateDateTime( rng ),
711 decimal_ =
Test.GenerateDecimal( rng ),
712 ipv4 =
Test.GenerateIpv4( rng ),
713 time =
Test.GenerateTime( rng ),
714 timestamp = (long) rng.Next()
717 ingestor.
insert( record );
720 Console.WriteLine( $
"Generated {totalRecords} records." );
723 Console.WriteLine(
"Flushing any remaining records..." );
729 private static void TestAllTypes3Pk0Shard(
string serverUrl,
Kinetica.
Options serverOptions )
732 Kinetica kdb =
new( serverUrl, serverOptions );
734 Console.WriteLine(
"\n\n" );
735 Console.WriteLine(
"Test Multihead Ingest: One column per type; 3 Primary Keys, No Shard Key" );
736 Console.WriteLine(
"========================================================================" );
741 Dictionary<string, IList<string>> column_properties =
new()
752 string recordAllTypeId = recordAllType.
create( kdb );
754 string tableName =
"csharp_test_table_0s3pk";
756 Console.WriteLine($
"Clearing any existing table named '{tableName}'...");
760 Console.WriteLine( $
"Creating table named '{tableName}'...\n" );
768 int totalRecords = batchSize * 50;
770 double nullProbability = 0.2;
771 for (
int i = 0; i < totalRecords; ++i )
774 int maxStringLength = rng.Next( 0, 256 );
775 RecordTypeAll record =
new()
780 l = (long)rng.Next(),
781 f = (float)(rng.NextDouble() * rng.Next()),
782 d = ( rng.NextDouble() < nullProbability ) ?
null : (
double? ) ( rng.NextDouble() * rng.Next() ),
783 s = System.IO.Path.GetRandomFileName().Truncate( maxStringLength ),
784 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
785 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
786 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
787 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
788 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
789 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
790 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
791 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
792 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
793 date =
Test.GenerateDate( rng ),
794 datetime =
Test.GenerateDateTime( rng ),
795 decimal_ =
Test.GenerateDecimal( rng ),
796 ipv4 =
Test.GenerateIpv4( rng ),
797 time =
Test.GenerateTime( rng ),
798 timestamp = (long) rng.Next()
801 ingestor.
insert( record );
804 Console.WriteLine( $
"Generated {totalRecords} records." );
807 Console.WriteLine(
"Flushing any remaining records..." );
813 private static void TestRecordRetrievalByKey(
string serverUrl,
Kinetica.
Options serverOptions)
816 Kinetica kdb =
new(serverUrl, serverOptions);
818 Console.WriteLine(
"\n\n");
819 Console.WriteLine(
"Test Multihead Key Lookup: One column per Type; one numeric and one string");
820 Console.WriteLine(
"shard key (no primary key)");
821 Console.WriteLine(
"==========================================================================");
824 Console.WriteLine(
"Creating a type with all column types (all are nullable; one numeric and one string shard columns)...\n");
828 Dictionary<string, IList<string>> column_properties =
new()
858 string recordAllTypeId = recordAllType.
create(kdb);
860 string tableName =
"csharp_test_record_retrieval_by_key";
863 Console.WriteLine($
"Clearing any existing table named '{tableName}'...");
867 Console.WriteLine($
"Creating table named '{tableName}'...\n");
871 kdb.
alterTable(tableName,
"create_index",
"i8");
872 kdb.
alterTable(tableName,
"create_index",
"c1");
875 int batchSize = 1000;
882 int totalRecords = batchSize * 10;
883 Console.WriteLine($
"Starting to generate {totalRecords} records...");
884 List<RecordTypeAll> records = [];
886 double nullProbability = 0.15;
887 double shardNullProbability = 0;
888 for (
int i = 0; i < totalRecords; ++i)
891 int maxStringLength = rng.Next(0, 256);
892 RecordTypeAll record =
new()
894 i = (rng.NextDouble() < nullProbability) ?
null : (
int?)rng.Next(),
895 i8 = (rng.NextDouble() < shardNullProbability) ?
null : (
int?)rng.Next(110, 128),
897 i16 = (rng.NextDouble() < nullProbability) ?
null : (
int?)rng.Next(-32768, 32768),
898 l = (long)rng.Next(),
900 f = (rng.NextDouble() < nullProbability) ?
null : (
float?)(rng.NextDouble() * rng.Next()),
901 d = (rng.NextDouble() < nullProbability) ?
null : (
double?)(rng.NextDouble() * rng.Next()),
902 s = (rng.NextDouble() < nullProbability) ?
null : System.IO.Path.GetRandomFileName().Truncate(maxStringLength),
903 c1 = (rng.NextDouble() < shardNullProbability) ?
null : System.IO.Path.GetRandomFileName().Truncate(1),
904 c2 = (rng.NextDouble() < nullProbability) ?
null : System.IO.Path.GetRandomFileName().Truncate(2),
905 c4 = (rng.NextDouble() < nullProbability) ?
null : System.IO.Path.GetRandomFileName().Truncate(rng.Next(0, 5)),
906 c8 = (rng.NextDouble() < nullProbability) ?
null : System.IO.Path.GetRandomFileName().Truncate(rng.Next(0, 9)),
907 c16 = (rng.NextDouble() < nullProbability) ?
null : System.IO.Path.GetRandomFileName().Truncate(rng.Next(0, 17)),
908 c32 = (rng.NextDouble() < nullProbability) ?
null : System.IO.Path.GetRandomFileName().Truncate(rng.Next(5, 33)),
909 c64 = (rng.NextDouble() < nullProbability) ?
null : System.IO.Path.GetRandomFileName().Truncate(rng.Next(10, 65)),
910 c128 = (rng.NextDouble() < nullProbability) ?
null : System.IO.Path.GetRandomFileName().Truncate(rng.Next(10, 129)),
911 c256 = (rng.NextDouble() < nullProbability) ?
null : System.IO.Path.GetRandomFileName().Truncate(rng.Next(25, 257)),
912 date = (rng.NextDouble() < nullProbability) ?
null :
Test.GenerateDate(rng),
913 datetime = (rng.NextDouble() < nullProbability) ?
null :
Test.GenerateDateTime(rng),
914 decimal_ = (rng.NextDouble() < nullProbability) ?
null :
Test.GenerateDecimal(rng),
915 ipv4 = (rng.NextDouble() < nullProbability) ?
null :
Test.GenerateIpv4(rng),
916 time = (rng.NextDouble() < nullProbability) ?
null :
Test.GenerateTime(rng),
917 timestamp = (rng.NextDouble() < nullProbability) ?
null : ((
long?)rng.Next(-306102240, 293795424) * rng.Next(100000))
925 Console.WriteLine($
"Generated {totalRecords} records.\n");
928 Console.WriteLine(
"Flushing any remaining records...");
932 Console.WriteLine(
"Creating the record retriever...");
934 Console.WriteLine(
"Attempting record retrieval...");
937 Console.WriteLine(
"Records fetched: ");
938 foreach (var record
in response.
data)
939 Console.WriteLine(record.ToString());
941 Console.WriteLine($
"Are there more records to fetch?: {response.has_more_records}\n");
948 Console.WriteLine(
"\n\n");
949 Console.WriteLine(
"JDBC Bridge Test");
950 Console.WriteLine(
"================");
953 if (jdbcDriverPath ==
null)
954 Console.WriteLine(
"Skipping--JDBC driver JAR not passed");
957 string jdbcUrl = $
"jdbc:kinetica:URL={serverUrl};UID={serverOptions.Username};PWD={serverOptions.Password}";
959 var builder =
new JdbcConnectionStringBuilder
961 DriverPath = jdbcDriverPath,
962 DriverClass =
"com.kinetica.jdbc.Driver",
966 Console.WriteLine($
"JDBC URL: {jdbcUrl}");
967 using var connection =
new JdbcConnection(builder);
969 string? rows = connection.CreateCommand(
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'information_schema'").ExecuteScalar().ToString();
970 Console.WriteLine($
"Connection successful! {rows} tables in INFORMATION_SCHEMA.\n");
983 int pastRange = -90 * 365;
984 int futureRange = 20 * 365;
985 int offset = rng.Next( pastRange, futureRange );
986 DateTime randomDate = DateTime.Today.AddDays( offset );
987 return String.Format(
"{0:yyyy-MM-dd}", randomDate );
999 int year = rng.Next(1900, 2500);
1000 int month = rng.Next(1, 12);
1001 int day = rng.Next(1, 28);
1002 int hour = rng.Next(0, 23);
1003 int minute = rng.Next(0, 59);
1004 int second = rng.Next(0, 59);
1005 int msecond = rng.Next(0, 999);
1007 DateTime randomDateTime =
new( year, month, day, hour, minute, second, msecond );
1010 int timeChancePercent = 90;
1011 if (rng.Next(101) > timeChancePercent)
1012 return String.Format(
"{0:yyyy-MM-dd}", randomDateTime);
1016 int numMsDigits = rng.Next(7);
1017 return numMsDigits
switch 1019 0 => String.Format(
"{0:yyyy-MM-dd HH:mm:ss}", randomDateTime),
1020 1 => String.Format(
"{0:yyyy-MM-dd HH:mm:ss.F}", randomDateTime),
1021 2 => String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FF}", randomDateTime),
1022 3 => String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FFF}", randomDateTime),
1023 4 => String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FFFF}", randomDateTime),
1024 5 => String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FFFFF}", randomDateTime),
1025 _ => String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FFFFFF}", randomDateTime),
1032 private static readonly
string numbers =
"0123456789";
1044 string precision =
new([.. Enumerable.Repeat(
'1', rng.Next( 15 ) ).Select( i =>
Test.numbers[ rng.Next( numbers.Length ) ] )]);
1045 string scale = rng.Next( 0, 10000 ).ToString();
1046 string sign = (rng.Next(2) == 0 && Double.Parse(precision +
"." + scale) != 0) ?
"-" :
"";
1047 return ( sign + precision +
"." + scale );
1059 string n1 = rng.Next( 256 ).ToString();
1060 string n2 = rng.Next( 256 ).ToString();
1061 string n3 = rng.Next( 256 ).ToString();
1062 string n4 = rng.Next( 256 ).ToString();
1064 return ( n1 + dot + n2 + dot + n3 + dot + n4 );
1076 int maxMiliseconds = 86400000;
1077 DateTime time = DateTime.Today;
1078 time = time.Add( TimeSpan.FromMilliseconds( rng.Next( maxMiliseconds ) ) );
1080 if ( (time.Millisecond > 0) && (rng.Next( 1, 6 ) > 3) )
1081 time_str = String.Format(
"{0:HH}:{0:mm}:{0:ss}.{0:FFF}", time );
1083 time_str = String.Format(
"{0:HH}:{0:mm}:{0:ss}", time );
A list of worker URLs to use for multi-head ingest.
const string CHAR1
This property provides optimized memory, disk and query performance for string columns.
DeleteRecordsResponse deleteRecords(DeleteRecordsRequest request_)
Deletes record(s) matching the provided criteria from the given table.
const string DATETIME
Valid only for 'string' columns.
static void TestJdbc(string serverUrl, Kinetica.Options serverOptions, string? jdbcDriverPath)
const string INT16
This property provides optimized memory and query performance for int columns.
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 CHAR128
This property provides optimized memory, disk and query performance for string columns.
void SetKineticaSourceClassToTypeMapping(Type? objectType, KineticaType kineticaType)
Saves an object class type to a KineticaType association.
static string GenerateIpv4(Random rng)
Generate a random IPv4 address.
IList< KineticaRecord > data
Avro binary encoded response.
CreateTableResponse createTable(CreateTableRequest request_)
Creates a new table.
A set of parameters for Kinetica.clearTable.
static void ProcessArgs(string []args, out Kinetica.Options? options, out string? jdbcDriverPath)
ShowSecurityResponse showSecurity(ShowSecurityRequest request_)
Shows security information relating to users and/or roles.
ExecuteSqlResponse executeSql(ExecuteSqlRequest request_)
Execute a SQL statement (query, DML, or DDL).
static string GenerateDecimal(Random rng)
Generate a random decimal value (up to 15 digits of precision and up to four digits of scale).
Column properties used for Kinetica types.
ShowSystemStatusResponse showSystemStatus(ShowSystemStatusRequest request_)
Provides server configuration and health related status to the caller.
A set of results returned by Kinetica.updateRecords.
const string TIMESTAMP
Valid only for 'long' columns.
const string CHAR16
This property provides optimized memory, disk and query performance for string columns.
Extension to string that has a truncate function.
const string CHAR64
This property provides optimized memory, disk and query performance for string columns.
A set of results returned by Kinetica.deleteRecords.
const string CHAR4
This property provides optimized memory, disk and query performance for string columns.
const string CHAR2
This property provides optimized memory, disk and query performance for string columns.
const string DATE
Valid only for 'string' columns.
const string CHAR8
This property provides optimized memory, disk and query performance for string columns.
const string DECIMAL
Valid only for 'string' columns.
IList< T > data
If the encoding was 'binary', then this list contains the binary encoded records retrieved from the t...
A set of string constants for the parameter options.
static string GenerateDateTime(Random rng)
Generate a random datetime.
const string CHAR32
This property provides optimized memory, disk and query performance for string columns.
const string IPV4
This property provides optimized memory, disk and query performance for string columns representing I...
GetRecordsResponse< T > getRecordsByKey(T record, string expression=null)
Retrieves records for a given shard key, optionally further limited by an additional expression.
CreateUserInternalResponse createUserInternal(CreateUserInternalRequest request_)
Creates a new internal user (a user whose credentials are managed by the database system).
ClearTableResponse clearTable(ClearTableRequest request_)
Clears (drops) one or all tables in the database cluster.
DeleteUserResponse deleteUser(DeleteUserRequest request_)
Deletes an existing user.
Manages the insertion into GPUdb of large numbers of records in bulk, with automatic batch management...
const string CHAR256
This property provides optimized memory, disk and query performance for string columns.
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.
const string SHARD_KEY
This property indicates that this column will be part of (or the entire) shard key.
AlterTableResponse alterTable(AlterTableRequest request_)
Apply various modifications to a table or view.
IDictionary< string, string > status_map
A map of server configuration and health related status.
static string GenerateDate(Random rng)
Generate a random date.
long total_number_of_records
Total/Filtered number of records.
const string INT8
This property provides optimized memory and query performance for int columns.
static string Truncate(this string value, int maxLength)
string create(Kinetica kinetica)
Given a handle to the server, creates a type in the database based on this data type.
IDictionary< string, string > types
Map of user/role name to the type of that user/role.
GetRecordsByColumnResponse getRecordsByColumn(GetRecordsByColumnRequest request_)
For a given table, retrieves the values from the requested column(s).
const string NO_ERROR_IF_NOT_EXISTS
If TRUE and if the table specified in table_name does not exist no error is returned.
const string TIME
Valid only for 'string' columns.
static string GenerateTime(Random rng)
Generate a random time of the format HH:MM:SS[.mmm].
const string NULLABLE
This property indicates that this column is nullable.
A set of results returned by Kinetica.getRecords.
API to talk to Kinetica Database
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.