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 );
57 _ServerOptions.Username = args[1];
58 _ServerOptions.Password = args[2];
63 test_authentication( server_url, _ServerOptions );
64 test_all_types_allshard( server_url, _ServerOptions );
65 test_all_types_3pk_3shard( server_url, _ServerOptions );
66 test_all_types_ip_regex_3shard_0pk( server_url, _ServerOptions );
67 test_all_types_3pk_0shard( server_url, _ServerOptions );
68 test_record_retrieval_by_key( server_url, _ServerOptions );
70 catch ( kinetica.KineticaIngestor<record_type_all>.InsertException<record_type_all> ex )
72 Console.WriteLine(
"Caught InsertException: {0}", ex.Message );
76 Console.WriteLine(
"Caught KineticaException: {0}", ex.Message );
78 catch ( Exception ex )
80 Console.WriteLine(
"Caught Exception: {0}", ex.Message );
85 Console.WriteLine(
"Testing C# Project - Done" );
87 Console.WriteLine(
"Enter any 7-digit prime number to continue: " );
92 private class record_type_short
94 public int i {
get; set; }
95 public int i8 {
get; set; }
97 public override string ToString()
99 return $
"{{ i={i}, i8={i8} }}";
104 private static void test_authentication(
string server_url,
Kinetica.Options _ServerOptions )
106 Console.WriteLine(
"\n\n" );
107 Console.WriteLine(
"Test Authentication" );
108 Console.WriteLine(
"===================" );
111 Console.WriteLine(
"This test is done dynamically:" );
112 Console.WriteLine(
"------------------------------" );
113 Console.WriteLine(
"* First run--create the user with the 'correct' username" );
114 Console.WriteLine(
"* Second run--comment out user creation; run with 'correct'" );
115 Console.WriteLine(
" username and make sure that the endpoints go through" );
116 Console.WriteLine(
"* Third run--comment out user creation; run with 'wrong'" );
117 Console.WriteLine(
" username and make sure that we get an 'insufficient credentials'" );
118 Console.WriteLine(
" error thrown from the server." );
121 string username =
"abcdef";
123 string password =
"ghijkl123_";
128 Console.WriteLine( $
"Creating a user {username}" );
130 IDictionary <string, string> options =
new Dictionary<string, string>();
133 kdb_.createUserInternal( username, password, options );
137 Console.WriteLine(
"Caught exception: " + ex.Message );
141 Console.WriteLine(
"Creating a DB handle with the proper username and password" );
143 db_options.Username = username;
144 db_options.Password = password;
148 KineticaType type1 = KineticaType.fromClass( typeof( record_type_short ) );
151 string type_id = type1.create( kdb );
153 string table_name =
"csharp_example_table_01_auth";
155 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
156 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
160 Console.WriteLine( $
"Creating table named '{table_name}'" );
161 kdb.createTable( table_name, type_id );
165 int num_records = 5000;
166 kdb.insertRecordsRandom( table_name, num_records );
167 Console.WriteLine( $
"Generated {num_records} records." );
171 private class record_type_all
173 public int? i {
get; set; }
174 public int? i8 {
get; set; }
175 public int? i16 {
get; set; }
176 public long l {
get; set; }
177 public float? f {
get; set; }
178 public double? d {
get; set; }
179 public string s {
get; set; }
180 public string c1 {
get; set; }
181 public string c2 {
get; set; }
182 public string c4 {
get; set; }
183 public string c8 {
get; set; }
184 public string c16 {
get; set; }
185 public string c32 {
get; set; }
186 public string c64 {
get; set; }
187 public string c128 {
get; set; }
188 public string c256 {
get; set; }
189 public string date {
get; set; }
190 public string datetime {
get; set; }
191 public string decimal_ {
get; set; }
192 public string ipv4 {
get; set; }
193 public string time {
get; set; }
194 public long? timestamp {
get; set; }
196 public override string ToString()
203 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} }}";
208 private static void test_all_types_allshard(
string server_url,
Kinetica.Options _ServerOptions )
213 Console.WriteLine(
"\n\n" );
214 Console.WriteLine(
"Test Multihead Ingest: One column per Type; All are Shard Keys, 0 Primary Keys" );
215 Console.WriteLine(
"==============================================================================" );
218 Console.WriteLine(
"Creating a type with all column types (all are nullable and shard columns).\n" );
222 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
225 List<string> i_props =
new List<string>();
226 i_props.Add( ColumnProperty.SHARD_KEY );
227 column_properties.Add(
"i", i_props );
230 List<string> i8_props =
new List<string>();
231 i8_props.Add( ColumnProperty.SHARD_KEY );
232 i8_props.Add( ColumnProperty.INT8 );
233 column_properties.Add(
"i8", i8_props );
235 List<string> i16_props =
new List<string>();
236 i16_props.Add( ColumnProperty.SHARD_KEY );
237 i16_props.Add( ColumnProperty.INT16 );
238 column_properties.Add(
"i16", i16_props );
241 List<string> d_props =
new List<string>();
242 d_props.Add( ColumnProperty.SHARD_KEY );
243 column_properties.Add(
"d", d_props );
246 List<string> f_props =
new List<string>();
247 f_props.Add( ColumnProperty.SHARD_KEY );
248 column_properties.Add(
"f", f_props );
251 List<string> l_props =
new List<string>();
252 l_props.Add( ColumnProperty.SHARD_KEY );
253 l_props.Add( ColumnProperty.NULLABLE );
254 column_properties.Add(
"l", l_props );
257 List<string> s_props =
new List<string>();
258 s_props.Add( ColumnProperty.SHARD_KEY );
259 s_props.Add( ColumnProperty.NULLABLE );
260 column_properties.Add(
"s", s_props );
263 List<string> c1_props =
new List<string>();
264 c1_props.Add( ColumnProperty.SHARD_KEY );
265 c1_props.Add( ColumnProperty.NULLABLE );
266 c1_props.Add( ColumnProperty.CHAR1 );
267 column_properties.Add(
"c1", c1_props );
270 List<string> c2_props =
new List<string>();
271 c2_props.Add( ColumnProperty.SHARD_KEY );
272 c2_props.Add( ColumnProperty.NULLABLE );
273 c2_props.Add( ColumnProperty.CHAR2 );
274 column_properties.Add(
"c2", c2_props );
277 List<string> c4_props =
new List<string>();
278 c4_props.Add( ColumnProperty.SHARD_KEY );
279 c4_props.Add( ColumnProperty.NULLABLE );
280 c4_props.Add( ColumnProperty.CHAR4 );
281 column_properties.Add(
"c4", c4_props );
284 List<string> c8_props =
new List<string>();
285 c8_props.Add( ColumnProperty.SHARD_KEY );
286 c8_props.Add( ColumnProperty.NULLABLE );
287 c8_props.Add( ColumnProperty.CHAR8 );
288 column_properties.Add(
"c8", c8_props );
291 List<string> c16_props =
new List<string>();
292 c16_props.Add( ColumnProperty.SHARD_KEY );
293 c16_props.Add( ColumnProperty.NULLABLE );
294 c16_props.Add( ColumnProperty.CHAR16 );
295 column_properties.Add(
"c16", c16_props );
298 List<string> c32_props =
new List<string>();
299 c32_props.Add( ColumnProperty.SHARD_KEY );
300 c32_props.Add( ColumnProperty.NULLABLE );
301 c32_props.Add( ColumnProperty.CHAR32 );
302 column_properties.Add(
"c32", c32_props );
305 List<string> c64_props =
new List<string>();
306 c64_props.Add( ColumnProperty.SHARD_KEY );
307 c64_props.Add( ColumnProperty.NULLABLE );
308 c64_props.Add( ColumnProperty.CHAR64 );
309 column_properties.Add(
"c64", c64_props );
312 List<string> c128_props =
new List<string>();
313 c128_props.Add( ColumnProperty.SHARD_KEY );
314 c128_props.Add( ColumnProperty.NULLABLE );
315 c128_props.Add( ColumnProperty.CHAR128 );
316 column_properties.Add(
"c128", c128_props );
319 List<string> c256_props =
new List<string>();
320 c256_props.Add( ColumnProperty.SHARD_KEY );
321 c256_props.Add( ColumnProperty.NULLABLE );
322 c256_props.Add( ColumnProperty.CHAR256 );
323 column_properties.Add(
"c256", c256_props );
326 List<string> date_props =
new List<string>();
327 date_props.Add( ColumnProperty.DATE );
328 date_props.Add( ColumnProperty.SHARD_KEY );
329 date_props.Add( ColumnProperty.NULLABLE );
330 column_properties.Add(
"date", date_props );
333 List<string> datetime_props =
new List<string>();
334 datetime_props.Add( ColumnProperty.DATETIME );
335 datetime_props.Add( ColumnProperty.SHARD_KEY );
336 datetime_props.Add( ColumnProperty.NULLABLE );
337 column_properties.Add(
"datetime", datetime_props );
340 List<string> decimal_props =
new List<string>();
341 decimal_props.Add(ColumnProperty.DECIMAL);
342 decimal_props.Add(ColumnProperty.SHARD_KEY);
343 decimal_props.Add( ColumnProperty.NULLABLE );
344 column_properties.Add(
"decimal_", decimal_props );
347 List<string> ipv4_props =
new List<string>();
348 ipv4_props.Add( ColumnProperty.IPV4 );
349 ipv4_props.Add( ColumnProperty.SHARD_KEY );
350 ipv4_props.Add( ColumnProperty.NULLABLE );
351 column_properties.Add(
"ipv4", ipv4_props );
354 List<string> time_props =
new List<string>();
355 time_props.Add( ColumnProperty.TIME );
356 time_props.Add( ColumnProperty.SHARD_KEY );
357 time_props.Add( ColumnProperty.NULLABLE );
358 column_properties.Add(
"time", time_props );
361 List<string> timestamp_props =
new List<string>();
362 timestamp_props.Add( ColumnProperty.TIMESTAMP );
363 timestamp_props.Add( ColumnProperty.SHARD_KEY );
364 column_properties.Add(
"timestamp", timestamp_props );
367 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
370 string type_id = type1.create( kdb );
373 Console.WriteLine(
"Created type.\n" );
375 string table_name =
"csharp_example_table_all_shards";
377 Console.WriteLine(
"Clearing any existing table named '{0}'\n", table_name );
378 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
382 Console.WriteLine( $
"Creating table named '{table_name}'\n" );
383 kdb.createTable( table_name, type_id );
387 int batch_size = 1000;
388 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
392 int num_records = batch_size * 10;
393 Console.WriteLine( $
"Starting to generate {num_records} records.\n" );
394 List<record_type_all> records =
new List<record_type_all>();
395 Random rng =
new Random();
396 double null_probability = 0.15;
397 for (
int i = 0; i < num_records; ++i )
400 int max_str_len = rng.Next( 0, 256 );
401 record_type_all record =
new record_type_all()
403 i = ( rng.NextDouble() < null_probability ) ? null : (
int?) rng.Next(),
404 i8 = ( rng.NextDouble() < null_probability ) ? null : (
int?) rng.Next( -128, 128 ),
405 i16 = ( rng.NextDouble() < null_probability ) ? null : (
int?) rng.Next( -32768, 32768),
406 l = (long)rng.Next(),
408 f = ( rng.NextDouble() < null_probability ) ? null : (
float?)(rng.NextDouble() * rng.Next()),
409 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
410 s = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
411 c1 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( 1 ),
412 c2 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( 2 ),
413 c4 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 5) ),
414 c8 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 9) ),
415 c16 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 17) ),
416 c32 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 5, 33) ),
417 c64 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 65) ),
418 c128 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 129) ),
419 c256 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 25, 257) ),
420 date = ( rng.NextDouble() < null_probability ) ? null :
Test.
generate_date( rng ),
421 datetime = (rng.NextDouble() < null_probability) ? null : Test.generate_datetime(rng),
423 ipv4 = ( rng.NextDouble() < null_probability ) ? null : Test.generate_IPv4( rng ),
425 timestamp = ( rng.NextDouble() < null_probability ) ? null : ((
long?)rng.Next( -306102240, 293795424 ) * rng.Next( 100000 ))
430 ingestor.insert( record );
433 Console.WriteLine( $
"Generated {num_records} records." );
440 Console.WriteLine(
"\nFlushing any remaining records." );
446 private static void test_record_retrieval_by_key(
string server_url,
Kinetica.Options _ServerOptions )
451 Console.WriteLine(
"\n\n" );
452 Console.WriteLine(
"Test Multihead Key Lookup: One column per Type; one numeric and one string" );
453 Console.WriteLine(
"shard key (no primary key)" );
454 Console.WriteLine(
"==========================================================================" );
457 Console.WriteLine(
"Creating a type with all column types (all are nullable; one numeric and one string shard columns).\n" );
461 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
464 List<string> i_props =
new List<string>();
465 column_properties.Add(
"i", i_props );
468 List<string> i8_props =
new List<string>();
469 i8_props.Add( ColumnProperty.SHARD_KEY );
470 i8_props.Add( ColumnProperty.INT8 );
471 column_properties.Add(
"i8", i8_props );
473 List<string> i16_props =
new List<string>();
474 i16_props.Add( ColumnProperty.INT16 );
475 column_properties.Add(
"i16", i16_props );
478 List<string> d_props =
new List<string>();
479 column_properties.Add(
"d", d_props );
482 List<string> f_props =
new List<string>();
483 column_properties.Add(
"f", f_props );
486 List<string> l_props =
new List<string>();
487 l_props.Add( ColumnProperty.NULLABLE );
488 column_properties.Add(
"l", l_props );
491 List<string> s_props =
new List<string>();
492 s_props.Add( ColumnProperty.NULLABLE );
493 column_properties.Add(
"s", s_props );
496 List<string> c1_props =
new List<string>();
497 c1_props.Add( ColumnProperty.SHARD_KEY );
498 c1_props.Add( ColumnProperty.NULLABLE );
499 c1_props.Add( ColumnProperty.CHAR1 );
500 column_properties.Add(
"c1", c1_props );
503 List<string> c2_props =
new List<string>();
504 c2_props.Add( ColumnProperty.NULLABLE );
505 c2_props.Add( ColumnProperty.CHAR2 );
506 column_properties.Add(
"c2", c2_props );
509 List<string> c4_props =
new List<string>();
510 c4_props.Add( ColumnProperty.NULLABLE );
511 c4_props.Add( ColumnProperty.CHAR4 );
512 column_properties.Add(
"c4", c4_props );
515 List<string> c8_props =
new List<string>();
516 c8_props.Add( ColumnProperty.NULLABLE );
517 c8_props.Add( ColumnProperty.CHAR8 );
518 column_properties.Add(
"c8", c8_props );
521 List<string> c16_props =
new List<string>();
522 c16_props.Add( ColumnProperty.NULLABLE );
523 c16_props.Add( ColumnProperty.CHAR16 );
524 column_properties.Add(
"c16", c16_props );
527 List<string> c32_props =
new List<string>();
528 c32_props.Add( ColumnProperty.NULLABLE );
529 c32_props.Add( ColumnProperty.CHAR32 );
530 column_properties.Add(
"c32", c32_props );
533 List<string> c64_props =
new List<string>();
534 c64_props.Add( ColumnProperty.NULLABLE );
535 c64_props.Add( ColumnProperty.CHAR64 );
536 column_properties.Add(
"c64", c64_props );
539 List<string> c128_props =
new List<string>();
540 c128_props.Add( ColumnProperty.NULLABLE );
541 c128_props.Add( ColumnProperty.CHAR128 );
542 column_properties.Add(
"c128", c128_props );
545 List<string> c256_props =
new List<string>();
546 c256_props.Add( ColumnProperty.NULLABLE );
547 c256_props.Add( ColumnProperty.CHAR256 );
548 column_properties.Add(
"c256", c256_props );
551 List<string> date_props =
new List<string>();
552 date_props.Add( ColumnProperty.DATE );
553 date_props.Add( ColumnProperty.NULLABLE );
554 column_properties.Add(
"date", date_props );
557 List<string> datetime_props =
new List<string>();
558 datetime_props.Add( ColumnProperty.DATETIME );
559 datetime_props.Add( ColumnProperty.NULLABLE );
560 column_properties.Add(
"datetime", datetime_props );
563 List<string> decimal_props =
new List<string>();
564 decimal_props.Add( ColumnProperty.DECIMAL );
565 decimal_props.Add( ColumnProperty.NULLABLE );
566 column_properties.Add(
"decimal_", decimal_props );
569 List<string> ipv4_props =
new List<string>();
570 ipv4_props.Add( ColumnProperty.IPV4 );
571 ipv4_props.Add( ColumnProperty.NULLABLE );
572 column_properties.Add(
"ipv4", ipv4_props );
575 List<string> time_props =
new List<string>();
576 time_props.Add( ColumnProperty.TIME );
577 time_props.Add( ColumnProperty.NULLABLE );
578 column_properties.Add(
"time", time_props );
581 List<string> timestamp_props =
new List<string>();
582 timestamp_props.Add( ColumnProperty.TIMESTAMP );
583 column_properties.Add(
"timestamp", timestamp_props );
586 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
589 string type_id = type1.create( kdb );
592 Console.WriteLine(
"Created type.\n" );
594 string table_name =
"csharp_example_table_all_shards";
596 Console.WriteLine(
"Clearing any existing table named '{0}'\n", table_name );
597 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
601 Console.WriteLine( $
"Creating table named '{table_name}'\n" );
602 kdb.createTable( table_name, type_id );
606 kdb.alterTable( table_name,
"create_index",
"i8" );
607 kdb.alterTable( table_name,
"create_index",
"c1" );
610 int batch_size = 1000;
611 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
618 int num_records = batch_size * 10;
619 Console.WriteLine( $
"Starting to generate {num_records} records.\n" );
620 List<record_type_all> records =
new List<record_type_all>();
621 Random rng =
new Random();
622 double null_probability = 0.15;
623 double shard_null_probability = 0;
624 for (
int i = 0; i < num_records; ++i )
627 int max_str_len = rng.Next( 0, 256 );
628 record_type_all record =
new record_type_all()
630 i = ( rng.NextDouble() < null_probability ) ? null : (
int?) rng.Next(),
631 i8 = ( rng.NextDouble() < shard_null_probability ) ? null : (
int?) rng.Next( 110, 128 ),
633 i16 = ( rng.NextDouble() < null_probability ) ? null : (
int?) rng.Next( -32768, 32768),
634 l = (long)rng.Next(),
636 f = ( rng.NextDouble() < null_probability ) ? null : (
float?)(rng.NextDouble() * rng.Next()),
637 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
638 s = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
639 c1 = ( rng.NextDouble() < shard_null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( 1 ),
640 c2 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( 2 ),
641 c4 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 5) ),
642 c8 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 9) ),
643 c16 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 17) ),
644 c32 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 5, 33) ),
645 c64 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 65) ),
646 c128 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 129) ),
647 c256 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 25, 257) ),
648 date = ( rng.NextDouble() < null_probability ) ? null :
Test.
generate_date( rng ),
649 datetime = (rng.NextDouble() < null_probability) ? null : Test.generate_datetime(rng),
651 ipv4 = ( rng.NextDouble() < null_probability ) ? null : Test.generate_IPv4( rng ),
653 timestamp = ( rng.NextDouble() < null_probability ) ? null : ((
long?)rng.Next( -306102240, 293795424 ) * rng.Next( 100000 ))
657 records.Add( record );
658 ingestor.insert( record );
661 Console.WriteLine( $
"Generated {num_records} records." );
664 Console.WriteLine(
"\nFlushing any remaining records." );
668 Console.WriteLine(
"Creating the record retriever...");
669 RecordRetriever<record_type_all> retriever =
new RecordRetriever<record_type_all>( kdb, table_name, type1 );
670 Console.WriteLine(
"Attempting record retrieval...");
672 GetRecordsResponse<record_type_all> response = retriever.getRecordsByKey( records[ 0 ] );
673 Console.WriteLine(
"Number of records fetched: {0}", response.total_number_of_records );
674 Console.WriteLine(
"Records fetched: ");
675 foreach ( var record
in response.data )
676 Console.WriteLine( record.ToString() );
678 Console.WriteLine(
"Are there more records to fetch?: {0}", response.has_more_records);
683 private static void test_all_types_ip_regex_3shard_0pk(
string server_url,
Kinetica.Options _ServerOptions )
688 Console.WriteLine(
"\n\n" );
689 Console.WriteLine(
"Test Multihead Ingest with a Regex Given for Worker IP Addresses (3 shard keys, no PKs)" );
690 Console.WriteLine(
"=======================================================================================" );
695 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
697 List<string> i_props =
new List<string>();
698 i_props.Add( ColumnProperty.SHARD_KEY );
699 column_properties.Add(
"i", i_props );
701 List<string> d_props =
new List<string>();
702 d_props.Add( ColumnProperty.SHARD_KEY );
703 column_properties.Add(
"d", d_props );
705 List<string> i16_props =
new List<string>();
706 i16_props.Add( ColumnProperty.SHARD_KEY );
707 column_properties.Add(
"i16", i16_props );
710 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
713 string type_id = type1.create( kdb );
715 string table_name =
"csharp_example_table_3s0pk";
717 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
718 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
722 Console.WriteLine( $
"Creating table named '{table_name}'" );
723 kdb.createTable( table_name, type_id );
727 int batch_size = 100;
729 Regex ip_regex =
new Regex(
"192.168.*" );
731 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1, null, worker_list );
734 int num_records = batch_size * 5;
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 datetime = Test.generate_datetime( rng ),
763 ipv4 = Test.generate_IPv4( rng ),
765 timestamp = (long) rng.Next()
769 records.Add( record );
772 Console.WriteLine( $
"Generated {num_records} records." );
775 Console.WriteLine( $
"Inserting {num_records} records..." );
776 ingestor.insert( records );
779 Console.WriteLine(
"\nFlushing any remaining records." );
786 private static void test_all_types_3pk_3shard(
string server_url,
Kinetica.Options _ServerOptions )
791 Console.WriteLine(
"\n\n" );
792 Console.WriteLine(
"Test Multihead Ingest: One column per Type; 3 Primary Keys, 3 Shard Keys" );
793 Console.WriteLine(
"========================================================================" );
798 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
801 List<string> l_props =
new List<string>();
802 l_props.Add( ColumnProperty.PRIMARY_KEY );
803 l_props.Add( ColumnProperty.SHARD_KEY );
804 column_properties.Add(
"l", l_props );
807 List<string> date_props =
new List<string>();
808 date_props.Add( ColumnProperty.DATE );
809 date_props.Add( ColumnProperty.PRIMARY_KEY );
810 date_props.Add( ColumnProperty.SHARD_KEY );
811 column_properties.Add(
"date", date_props );
814 List<string> time_props =
new List<string>();
815 time_props.Add( ColumnProperty.TIME );
816 time_props.Add( ColumnProperty.PRIMARY_KEY );
817 time_props.Add( ColumnProperty.SHARD_KEY );
818 column_properties.Add(
"time", time_props );
821 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
824 string type_id = type1.create( kdb );
828 string table_name =
"csharp_example_table_3s3pk";
830 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
831 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
835 Console.WriteLine( $
"Creating table named '{table_name}'" );
836 kdb.createTable( table_name, type_id );
840 int batch_size = 100;
841 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
844 int num_records = batch_size * 50;
845 Random rng =
new Random();
846 double null_probability = 0.2;
847 for (
int i = 0; i < num_records; ++i )
850 int max_str_len = rng.Next( 0, 256 );
851 record_type_all record =
new record_type_all()
856 l = (
long)rng.Next(),
857 f = (
float)(rng.NextDouble() * rng.Next()),
858 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
859 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
860 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
861 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
862 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
863 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
864 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
865 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
866 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
867 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
868 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
870 datetime = Test.generate_datetime( rng ),
872 ipv4 = Test.generate_IPv4( rng ),
874 timestamp = (long) rng.Next()
878 ingestor.insert( record );
881 Console.WriteLine( $
"Generated {num_records} records." );
884 Console.WriteLine(
"\nFlushing any remaining records." );
890 private static void test_all_types_3pk_0shard(
string server_url,
Kinetica.Options _ServerOptions )
895 Console.WriteLine(
"\n\n" );
896 Console.WriteLine(
"Test Multihead Ingest: One column per type; 3 Primary Keys, No Shard Key" );
897 Console.WriteLine(
"========================================================================" );
902 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
905 List<string> l_props =
new List<string>();
906 l_props.Add( ColumnProperty.PRIMARY_KEY );
907 column_properties.Add(
"l", l_props );
910 List<string> date_props =
new List<string>();
911 date_props.Add( ColumnProperty.PRIMARY_KEY );
912 column_properties.Add(
"date", date_props );
915 List<string> time_props =
new List<string>();
916 time_props.Add( ColumnProperty.PRIMARY_KEY );
917 column_properties.Add(
"time", time_props );
920 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
923 string type_id = type1.create( kdb );
927 string table_name =
"csharp_example_table_0s3pk";
929 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
930 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
934 Console.WriteLine( $
"Creating table named '{table_name}'" );
935 kdb.createTable( table_name, type_id );
939 int batch_size = 100;
940 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
943 int num_records = batch_size * 50;
944 Random rng =
new Random();
945 double null_probability = 0.2;
946 for (
int i = 0; i < num_records; ++i )
949 int max_str_len = rng.Next( 0, 256 );
950 record_type_all record =
new record_type_all()
955 l = (
long)rng.Next(),
956 f = (
float)(rng.NextDouble() * rng.Next()),
957 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
958 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
959 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
960 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
961 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
962 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
963 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
964 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
965 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
966 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
967 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
969 datetime = Test.generate_datetime( rng ),
971 ipv4 = Test.generate_IPv4( rng ),
973 timestamp = (long) rng.Next()
977 ingestor.insert( record );
980 Console.WriteLine( $
"Generated {num_records} records." );
983 Console.WriteLine(
"\nFlushing any remaining records." );
996 int past_range = -90 * 365;
997 int future_range = 20 * 365;
998 int offset = rng.Next( past_range, future_range );
999 DateTime random_date = DateTime.Today.AddDays( offset );
1000 return String.Format(
"{0:yyyy-MM-dd}", random_date );
1012 int past_range = -90 * 365;
1013 int future_range = 20 * 365;
1014 int offset = rng.Next( past_range, future_range );
1015 int year = rng.Next(1900, 2500);
1016 int month = rng.Next(1, 12);
1017 int day = rng.Next(1, 28);
1018 int hour = rng.Next(0, 23);
1019 int minute = rng.Next(0, 59);
1020 int second = rng.Next(0, 59);
1021 int msecond = rng.Next(0, 999);
1023 DateTime random_datetime =
new DateTime( year, month, day,
1024 hour, minute, second, msecond );
1027 int time_chance_percent = 90;
1028 if (rng.Next(101) > time_chance_percent)
1029 return String.Format(
"{0:yyyy-MM-dd}", random_datetime);
1033 int num_ms_digits = rng.Next(7);
1034 switch (num_ms_digits)
1037 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss}", random_datetime);
1039 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss.F}", random_datetime);
1041 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FF}", random_datetime);
1043 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FFF}", random_datetime);
1045 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FFFF}", random_datetime);
1047 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FFFFF}", random_datetime);
1050 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FFFFFF}", random_datetime);
1057 private static readonly
string numbers =
"0123456789";
1067 string sign = (rng.Next( 2 ) == 0) ?
"-" :
"";
1070 string precision =
new string( Enumerable.Repeat(
'1', rng.Next( 15 ) ).Select( i =>
Test.numbers[ rng.Next( numbers.Length ) ] ).ToArray() );
1071 string scale = rng.Next( 0, 10000 ).ToString();
1072 return ( sign + precision +
"." + scale );
1084 string n1 = rng.Next( 256 ).ToString();
1085 string n2 = rng.Next( 256 ).ToString();
1086 string n3 = rng.Next( 256 ).ToString();
1087 string n4 = rng.Next( 256 ).ToString();
1089 return ( n1 + dot + n2 + dot + n3 + dot + n4 );
1101 int max_miliseconds = 86400000;
1102 DateTime time = DateTime.Today;
1104 time = time.Add( TimeSpan.FromMilliseconds( rng.Next( max_miliseconds ) ) );
1107 if ( (time.Millisecond > 0) && (rng.Next( 1, 6 ) > 3) )
1108 time_str = String.Format(
"{0:HH}:{0:mm}:{0:ss}.{0:FFF}", time );
1110 time_str = String.Format(
"{0:HH}:{0:mm}:{0:ss}", time );
Runs some tests on multihead ingestion.
A list of worker URLs to use for multi-head ingest.
static string generate_decimal(Random rng)
Generate a random decimal value (up to 15 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.
static string generate_datetime(Random rng)
Generate a random datetime.
Extension to string that has a truncate function.
static string Truncate(this string value, int maxLength)
API to talk to Kinetica Database