8 using System.Collections.Generic;
10 using System.Text.RegularExpressions;
21 public static string Truncate(
this string value,
int maxLength )
23 if (
string.IsNullOrEmpty( value ) )
26 return ( value.Length <= maxLength ) ? value : value.Substring( 0, maxLength );
38 static void Main(
string[] args )
40 Console.WriteLine(
"Testing C# Project - Running" );
43 if ( args.Length < 1 )
45 Console.WriteLine(
"Missing URL as command-line parameter." );
46 Console.WriteLine(
"E.g., http://kinetica:9191" );
52 string server_url = args[0];
53 Console.WriteLine(
"URL: {0}", server_url );
59 test_all_types_5shard_0pk( server_url );
60 test_all_types_3pk_3shard( server_url );
61 test_all_types_3pk_2shard( server_url );
62 test_all_types_3pk_1shard( server_url );
63 test_all_types_3pk_0shard( server_url );
64 test_all_types_0shard_0pk( server_url );
65 test_all_types_ip_regex_3shard_0pk( server_url );
67 catch ( Exception ex )
69 Console.WriteLine(
"Caught Exception: {0}", ex.Message );
74 Console.WriteLine(
"Testing C# Project - Done" );
76 Console.WriteLine(
"Enter any 7-digit prime number to continue: " );
81 private class record_type_short
83 public int i {
get; set; }
84 public int i8 {
get; set; }
86 public override string ToString()
88 return $
"{{ i={i}, i8={i8} }}";
93 private static void test_authentication(
string server_url )
95 Console.WriteLine(
"\n\n" );
96 Console.WriteLine(
"Test Authentication" );
97 Console.WriteLine(
"===================" );
100 Console.WriteLine(
"This test is done dynamically:" );
101 Console.WriteLine(
"------------------------------" );
102 Console.WriteLine(
"* First run--create the user with the 'correct' username" );
103 Console.WriteLine(
"* Second run--comment out user creation; run with 'correct'" );
104 Console.WriteLine(
" username and make sure that the endpoints go through" );
105 Console.WriteLine(
"* Third run--comment out user creation; run with 'wrong'" );
106 Console.WriteLine(
" username and make sure that we get an 'insufficient credentials'" );
107 Console.WriteLine(
" error thrown from the server." );
110 string username =
"abcdef";
112 string password =
"ghijkl123_";
117 Console.WriteLine( $
"Creating a user {username}" );
119 IDictionary <string, string> options =
new Dictionary<string, string>();
120 kdb_.createUserInternal( username, password, options );
123 Console.WriteLine(
"Creating a DB handle with the proper username and password" );
125 db_options.Username = username;
126 db_options.Password = password;
130 KineticaType type1 = KineticaType.fromClass( typeof( record_type_short ) );
133 string type_id = type1.create( kdb );
135 string table_name =
"csharp_example_table_01";
137 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
138 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
142 Console.WriteLine( $
"Creating table named '{table_name}'" );
143 kdb.createTable( table_name, type_id );
147 int num_records = 5000;
148 kdb.insertRecordsRandom( table_name, num_records );
149 Console.WriteLine( $
"Generated {num_records} records." );
153 private class record_type_all
155 public int i {
get; set; }
156 public int i8 {
get; set; }
157 public int i16 {
get; set; }
158 public long l {
get; set; }
159 public float f {
get; set; }
160 public double? d {
get; set; }
161 public string s {
get; set; }
162 public string c1 {
get; set; }
163 public string c2 {
get; set; }
164 public string c4 {
get; set; }
165 public string c8 {
get; set; }
166 public string c16 {
get; set; }
167 public string c32 {
get; set; }
168 public string c64 {
get; set; }
169 public string c128 {
get; set; }
170 public string c256 {
get; set; }
171 public string date {
get; set; }
172 public string decimal_ {
get; set; }
173 public string ipv4 {
get; set; }
174 public string time {
get; set; }
175 public long timestamp {
get; set; }
177 public override string ToString()
184 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}, decimal_={decimal_}, ipv4={ipv4}, time={time}, timestamp={timestamp} }}";
189 private static void test_all_types_ip_regex_3shard_0pk(
string server_url )
194 Console.WriteLine(
"\n\n" );
195 Console.WriteLine(
"Test Multihead Ingest with a Regex Given for Worker IP Addresses (3 shard keys, no PKs)" );
196 Console.WriteLine(
"=======================================================================================" );
201 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
203 List<string> i_props =
new List<string>();
204 i_props.Add( ColumnProperty.SHARD_KEY );
205 column_properties.Add(
"i", i_props );
207 List<string> d_props =
new List<string>();
208 d_props.Add( ColumnProperty.SHARD_KEY );
209 column_properties.Add(
"d", d_props );
211 List<string> i16_props =
new List<string>();
212 i16_props.Add( ColumnProperty.SHARD_KEY );
213 column_properties.Add(
"i16", i16_props );
216 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
219 string type_id = type1.create( kdb );
221 string table_name =
"csharp_example_table_01";
223 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
224 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
228 Console.WriteLine( $
"Creating table named '{table_name}'" );
229 kdb.createTable( table_name, type_id );
233 int batch_size = 100;
234 Regex ip_regex =
new Regex(
"172.30.*" );
235 KineticaIngestor<record_type_all>.WorkerList worker_list =
new KineticaIngestor<record_type_all>.WorkerList( kdb, ip_regex );
236 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1, null, worker_list );
239 int num_records = batch_size * 5;
240 List<record_type_all> records =
new List<record_type_all>();
241 Random rng =
new Random();
242 double null_probability = 0.2;
243 for (
int i = 0; i < num_records; ++i )
246 int max_str_len = rng.Next( 0, 256 );
247 record_type_all record =
new record_type_all()
252 l = (
long)rng.Next(),
253 f = (
float)(rng.NextDouble() * rng.Next()),
254 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
255 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
256 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
257 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
258 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
259 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
260 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
261 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
262 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
263 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
264 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
266 decimal_ = Test.generate_decimal( rng ),
268 time = Test.generate_time( rng ),
269 timestamp = (
long) rng.Next()
273 records.Add( record );
276 Console.WriteLine( $
"Generated {num_records} records." );
279 Console.WriteLine( $
"Inserting {num_records} records..." );
280 ingestor.insert( records );
283 Console.WriteLine(
"\nFlushing any remaining records." );
288 private static void test_all_types_0shard_0pk(
string server_url )
293 Console.WriteLine(
"\n\n" );
294 Console.WriteLine(
"Test Multihead Ingest: One column per type; 0 Shard Keys, 0 Primary Keys" );
295 Console.WriteLine(
"========================================================================" );
299 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ) );
302 string type_id = type1.create( kdb );
304 string table_name =
"csharp_example_table_01";
306 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
307 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
311 Console.WriteLine( $
"Creating table named '{table_name}'" );
312 kdb.createTable( table_name, type_id );
316 int batch_size = 1000;
317 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
320 int num_records = batch_size * 50;
321 List<record_type_all> records =
new List<record_type_all>();
322 Random rng =
new Random();
323 double null_probability = 0.2;
324 for (
int i = 0; i < num_records; ++i )
327 int max_str_len = rng.Next( 0, 256 );
328 record_type_all record =
new record_type_all()
333 l = (
long)rng.Next(),
334 f = (
float)(rng.NextDouble() * rng.Next()),
335 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
336 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
337 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
338 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
339 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
340 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
341 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
342 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
343 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
344 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
345 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
347 decimal_ = Test.generate_decimal( rng ),
349 time = Test.generate_time( rng ),
350 timestamp = (
long) rng.Next()
354 records.Add( record );
357 Console.WriteLine( $
"Generated {num_records} records." );
360 Console.WriteLine( $
"Inserting {num_records} records..." );
361 ingestor.insert( records );
364 Console.WriteLine(
"\nFlushing any remaining records." );
370 private static void test_all_types_5shard_0pk(
string server_url )
375 Console.WriteLine(
"\n\n" );
376 Console.WriteLine(
"Test Multihead Ingest: One column per Type; 5 Shard Keys, 0 Primary Keys" );
377 Console.WriteLine(
"========================================================================" );
382 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
384 List<string> i_props =
new List<string>();
385 i_props.Add( ColumnProperty.SHARD_KEY );
386 column_properties.Add(
"i", i_props );
388 List<string> d_props =
new List<string>();
389 d_props.Add( ColumnProperty.SHARD_KEY );
390 column_properties.Add(
"d", d_props );
392 List<string> i16_props =
new List<string>();
393 i16_props.Add( ColumnProperty.SHARD_KEY );
394 column_properties.Add(
"i16", i16_props );
396 List<string> c2_props =
new List<string>();
397 c2_props.Add( ColumnProperty.SHARD_KEY );
398 column_properties.Add(
"c2", c2_props );
400 List<string> c8_props =
new List<string>();
401 c8_props.Add( ColumnProperty.SHARD_KEY );
402 column_properties.Add(
"c8", c8_props );
405 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
408 string type_id = type1.create( kdb );
412 string table_name =
"csharp_example_table_01";
414 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
415 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
419 Console.WriteLine( $
"Creating table named '{table_name}'" );
420 kdb.createTable( table_name, type_id );
424 int batch_size = 1000;
425 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
428 int num_records = batch_size * 50;
429 List<record_type_all> records =
new List<record_type_all>();
430 Random rng =
new Random();
431 double null_probability = 0.2;
432 for (
int i = 0; i < num_records; ++i )
435 int max_str_len = rng.Next( 0, 256 );
436 record_type_all record =
new record_type_all()
441 l = (
long)rng.Next(),
442 f = (
float)(rng.NextDouble() * rng.Next()),
443 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
444 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
445 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
446 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
447 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
448 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
449 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
450 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
451 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
452 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
453 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
455 decimal_ = Test.generate_decimal( rng ),
457 time = Test.generate_time( rng ),
458 timestamp = (
long) rng.Next()
462 records.Add( record );
465 Console.WriteLine( $
"Generated {num_records} records." );
468 Console.WriteLine( $
"Inserting {num_records} records..." );
469 ingestor.insert( records );
472 Console.WriteLine(
"\nFlushing any remaining records." );
478 private static void test_all_types_3pk_3shard(
string server_url )
483 Console.WriteLine(
"\n\n" );
484 Console.WriteLine(
"Test Multihead Ingest: One column per Type; 3 Primary Keys, 3 Shard Keys" );
485 Console.WriteLine(
"========================================================================" );
490 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
492 List<string> l_props =
new List<string>();
493 l_props.Add( ColumnProperty.PRIMARY_KEY );
494 l_props.Add( ColumnProperty.SHARD_KEY );
495 column_properties.Add(
"l", l_props );
497 List<string> date_props =
new List<string>();
498 date_props.Add( ColumnProperty.PRIMARY_KEY );
499 date_props.Add( ColumnProperty.SHARD_KEY );
500 column_properties.Add(
"date", date_props );
502 List<string> ipv4_props =
new List<string>();
503 ipv4_props.Add( ColumnProperty.PRIMARY_KEY );
504 ipv4_props.Add( ColumnProperty.SHARD_KEY );
505 column_properties.Add(
"ipv4", ipv4_props );
508 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
511 string type_id = type1.create( kdb );
515 string table_name =
"csharp_example_table_01";
517 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
518 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
522 Console.WriteLine( $
"Creating table named '{table_name}'" );
523 kdb.createTable( table_name, type_id );
527 int batch_size = 1000;
528 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
531 int num_records = batch_size * 50;
532 List<record_type_all> records =
new List<record_type_all>();
533 Random rng =
new Random();
534 double null_probability = 0.2;
535 for (
int i = 0; i < num_records; ++i )
538 int max_str_len = rng.Next( 0, 256 );
539 record_type_all record =
new record_type_all()
544 l = (
long)rng.Next(),
545 f = (
float)(rng.NextDouble() * rng.Next()),
546 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
547 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
548 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
549 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
550 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
551 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
552 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
553 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
554 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
555 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
556 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
558 decimal_ = Test.generate_decimal( rng ),
560 time = Test.generate_time( rng ),
561 timestamp = (
long) rng.Next()
565 records.Add( record );
568 Console.WriteLine( $
"Generated {num_records} records." );
571 Console.WriteLine( $
"Inserting {num_records} records..." );
572 ingestor.insert( records );
575 Console.WriteLine(
"\nFlushing any remaining records." );
581 private static void test_all_types_3pk_2shard(
string server_url )
586 Console.WriteLine(
"\n\n" );
587 Console.WriteLine(
"Test Multihead Ingest: One column per Type; 3 Primary Keys, 2 Shard Keys" );
588 Console.WriteLine(
"========================================================================" );
593 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
595 List<string> c2_props =
new List<string>();
596 c2_props.Add( ColumnProperty.PRIMARY_KEY );
597 c2_props.Add( ColumnProperty.SHARD_KEY );
598 column_properties.Add(
"c2", c2_props );
600 List<string> date_props =
new List<string>();
601 date_props.Add( ColumnProperty.PRIMARY_KEY );
602 column_properties.Add(
"date", date_props );
604 List<string> timestamp_props =
new List<string>();
605 timestamp_props.Add( ColumnProperty.PRIMARY_KEY );
606 timestamp_props.Add( ColumnProperty.SHARD_KEY );
607 column_properties.Add(
"timestamp", timestamp_props );
610 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
613 string type_id = type1.create( kdb );
617 string table_name =
"csharp_example_table_01";
619 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
620 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
624 Console.WriteLine( $
"Creating table named '{table_name}'" );
625 kdb.createTable( table_name, type_id );
629 int batch_size = 1000;
630 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
633 int num_records = batch_size * 50;
634 List<record_type_all> records =
new List<record_type_all>();
635 Random rng =
new Random();
636 double null_probability = 0.2;
637 for (
int i = 0; i < num_records; ++i )
640 int max_str_len = rng.Next( 0, 256 );
641 record_type_all record =
new record_type_all()
646 l = (
long)rng.Next(),
647 f = (
float)(rng.NextDouble() * rng.Next()),
648 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
649 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
650 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
651 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
652 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
653 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
654 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
655 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
656 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
657 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
658 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
660 decimal_ = Test.generate_decimal( rng ),
662 time = Test.generate_time( rng ),
663 timestamp = (
long) rng.Next()
667 records.Add( record );
670 Console.WriteLine( $
"Generated {num_records} records." );
673 Console.WriteLine( $
"Inserting {num_records} records..." );
674 ingestor.insert( records );
677 Console.WriteLine(
"\nFlushing any remaining records." );
683 private static void test_all_types_3pk_1shard(
string server_url )
688 Console.WriteLine(
"\n\n" );
689 Console.WriteLine(
"Test Multihead Ingest: One column per Type; 3 Primary Keys, 1 Shard Key" );
690 Console.WriteLine(
"========================================================================" );
695 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
697 List<string> f_props =
new List<string>();
698 f_props.Add( ColumnProperty.PRIMARY_KEY );
699 f_props.Add( ColumnProperty.SHARD_KEY );
700 column_properties.Add(
"f", f_props );
702 List<string> date_props =
new List<string>();
703 date_props.Add( ColumnProperty.PRIMARY_KEY );
704 column_properties.Add(
"date", date_props );
706 List<string> timestamp_props =
new List<string>();
707 timestamp_props.Add( ColumnProperty.PRIMARY_KEY );
708 column_properties.Add(
"timestamp", timestamp_props );
711 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
714 string type_id = type1.create( kdb );
718 string table_name =
"csharp_example_table_01";
720 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
721 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
725 Console.WriteLine( $
"Creating table named '{table_name}'" );
726 kdb.createTable( table_name, type_id );
730 int batch_size = 1000;
731 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
734 int num_records = batch_size * 50;
735 List<record_type_all> records =
new List<record_type_all>();
736 Random rng =
new Random();
737 double null_probability = 0.2;
738 for (
int i = 0; i < num_records; ++i )
741 int max_str_len = rng.Next( 0, 256 );
742 record_type_all record =
new record_type_all()
747 l = (
long)rng.Next(),
748 f = (
float)(rng.NextDouble() * rng.Next()),
749 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
750 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
751 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
752 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
753 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
754 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
755 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
756 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
757 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
758 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
759 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
761 decimal_ = Test.generate_decimal( rng ),
763 time = Test.generate_time( rng ),
764 timestamp = (
long) rng.Next()
768 records.Add( record );
771 Console.WriteLine( $
"Generated {num_records} records." );
774 Console.WriteLine( $
"Inserting {num_records} records..." );
775 ingestor.insert( records );
778 Console.WriteLine(
"\nFlushing any remaining records." );
784 private static void test_all_types_3pk_0shard(
string server_url )
789 Console.WriteLine(
"\n\n" );
790 Console.WriteLine(
"Test Multihead Ingest: One column per type; 3 Primary Keys, No Shard Key" );
791 Console.WriteLine(
"========================================================================" );
796 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
798 List<string> f_props =
new List<string>();
799 f_props.Add( ColumnProperty.PRIMARY_KEY );
800 column_properties.Add(
"f", f_props );
802 List<string> date_props =
new List<string>();
803 date_props.Add( ColumnProperty.PRIMARY_KEY );
804 column_properties.Add(
"date", date_props );
806 List<string> timestamp_props =
new List<string>();
807 timestamp_props.Add( ColumnProperty.PRIMARY_KEY );
808 column_properties.Add(
"timestamp", timestamp_props );
811 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
814 string type_id = type1.create( kdb );
818 string table_name =
"csharp_example_table_01";
820 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
821 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
825 Console.WriteLine( $
"Creating table named '{table_name}'" );
826 kdb.createTable( table_name, type_id );
830 int batch_size = 1000;
831 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
834 int num_records = batch_size * 50;
835 List<record_type_all> records =
new List<record_type_all>();
836 Random rng =
new Random();
837 double null_probability = 0.2;
838 for (
int i = 0; i < num_records; ++i )
841 int max_str_len = rng.Next( 0, 256 );
842 record_type_all record =
new record_type_all()
847 l = (
long)rng.Next(),
848 f = (
float)(rng.NextDouble() * rng.Next()),
849 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
850 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
851 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
852 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
853 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
854 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
855 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
856 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
857 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
858 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
859 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
861 decimal_ = Test.generate_decimal( rng ),
863 time = Test.generate_time( rng ),
864 timestamp = (
long) rng.Next()
868 records.Add( record );
871 Console.WriteLine( $
"Generated {num_records} records." );
874 Console.WriteLine( $
"Inserting {num_records} records..." );
875 ingestor.insert( records );
878 Console.WriteLine(
"\nFlushing any remaining records." );
891 int past_range = -90 * 365;
892 int future_range = 20 * 365;
893 int offset = rng.Next( past_range, future_range );
894 DateTime random_date = DateTime.Today.AddDays( offset );
895 return String.Format(
"{0:yyyy-MM-dd}", random_date );
900 private static readonly
string numbers =
"0123456789";
910 string sign = (rng.Next( 2 ) == 0) ?
"-" :
"";
911 string precision =
new string( Enumerable.Repeat(
'1', rng.Next( 20 ) ).Select( i =>
Test.numbers[ rng.Next( numbers.Length ) ] ).ToArray() );
912 string scale = rng.Next( 0, 10000 ).ToString();
913 return ( sign + precision +
"." + scale );
925 string n1 = rng.Next( 256 ).ToString();
926 string n2 = rng.Next( 256 ).ToString();
927 string n3 = rng.Next( 256 ).ToString();
928 string n4 = rng.Next( 256 ).ToString();
930 return ( n1 + dot + n2 + dot + n3 + dot + n4 );
942 int max_miliseconds = 86400000;
943 DateTime time = DateTime.Today;
945 time = time.Add( TimeSpan.FromMilliseconds( rng.Next( max_miliseconds ) ) );
948 if ( rng.Next( 6 ) == 0 )
949 time_str = String.Format(
"{0:HH}:{0:mm}:{0:ss}.{0:FFF}", time );
951 time_str = String.Format(
"{0:HH}:{0:mm}:{0:ss}", time );
Runs some tests on multihead ingestion.
static string generate_decimal(Random rng)
Generate a random decimal value (up to 19 digits of precision and up to four digits of scale)...
static string generate_time(Random rng)
Generate a random time of the format HH:MM:SS[.mmm].
static string generate_date(Random rng)
Generate a random date.
static string generate_IPv4(Random rng)
Generate a random IPv4 address.
Extension to string that has a truncate function.
static string Truncate(this string value, int maxLength)
API to talk to Kinetica Database