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 );
58 test_authentication( server_url );
59 test_all_types_allshard( server_url );
60 test_all_types_3pk_3shard( server_url );
61 test_all_types_ip_regex_3shard_0pk( server_url );
62 test_all_types_3pk_0shard( server_url );
63 test_record_retrieval_by_key( server_url );
65 catch ( kinetica.KineticaIngestor<record_type_all>.InsertException<record_type_all> ex )
67 Console.WriteLine(
"Caught InsertException: {0}", ex.Message );
71 Console.WriteLine(
"Caught KineticaException: {0}", ex.Message );
73 catch ( Exception ex )
75 Console.WriteLine(
"Caught Exception: {0}", ex.Message );
80 Console.WriteLine(
"Testing C# Project - Done" );
82 Console.WriteLine(
"Enter any 7-digit prime number to continue: " );
87 private class record_type_short
89 public int i {
get; set; }
90 public int i8 {
get; set; }
92 public override string ToString()
94 return $
"{{ i={i}, i8={i8} }}";
99 private static void test_authentication(
string server_url )
101 Console.WriteLine(
"\n\n" );
102 Console.WriteLine(
"Test Authentication" );
103 Console.WriteLine(
"===================" );
106 Console.WriteLine(
"This test is done dynamically:" );
107 Console.WriteLine(
"------------------------------" );
108 Console.WriteLine(
"* First run--create the user with the 'correct' username" );
109 Console.WriteLine(
"* Second run--comment out user creation; run with 'correct'" );
110 Console.WriteLine(
" username and make sure that the endpoints go through" );
111 Console.WriteLine(
"* Third run--comment out user creation; run with 'wrong'" );
112 Console.WriteLine(
" username and make sure that we get an 'insufficient credentials'" );
113 Console.WriteLine(
" error thrown from the server." );
116 string username =
"abcdef";
118 string password =
"ghijkl123_";
123 Console.WriteLine( $
"Creating a user {username}" );
125 IDictionary <string, string> options =
new Dictionary<string, string>();
128 kdb_.createUserInternal( username, password, options );
132 Console.WriteLine(
"Caught exception: " + ex.Message );
136 Console.WriteLine(
"Creating a DB handle with the proper username and password" );
138 db_options.Username = username;
139 db_options.Password = password;
143 KineticaType type1 = KineticaType.fromClass( typeof( record_type_short ) );
146 string type_id = type1.create( kdb );
148 string table_name =
"csharp_example_table_01_auth";
150 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
151 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
155 Console.WriteLine( $
"Creating table named '{table_name}'" );
156 kdb.createTable( table_name, type_id );
160 int num_records = 5000;
161 kdb.insertRecordsRandom( table_name, num_records );
162 Console.WriteLine( $
"Generated {num_records} records." );
166 private class record_type_all
168 public int? i {
get; set; }
169 public int? i8 {
get; set; }
170 public int? i16 {
get; set; }
171 public long l {
get; set; }
172 public float? f {
get; set; }
173 public double? d {
get; set; }
174 public string s {
get; set; }
175 public string c1 {
get; set; }
176 public string c2 {
get; set; }
177 public string c4 {
get; set; }
178 public string c8 {
get; set; }
179 public string c16 {
get; set; }
180 public string c32 {
get; set; }
181 public string c64 {
get; set; }
182 public string c128 {
get; set; }
183 public string c256 {
get; set; }
184 public string date {
get; set; }
185 public string datetime {
get; set; }
186 public string decimal_ {
get; set; }
187 public string ipv4 {
get; set; }
188 public string time {
get; set; }
189 public long? timestamp {
get; set; }
191 public override string ToString()
198 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} }}";
203 private static void test_all_types_allshard(
string server_url )
208 Console.WriteLine(
"\n\n" );
209 Console.WriteLine(
"Test Multihead Ingest: One column per Type; All are Shard Keys, 0 Primary Keys" );
210 Console.WriteLine(
"==============================================================================" );
213 Console.WriteLine(
"Creating a type with all column types (all are nullable and shard columns).\n" );
217 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
220 List<string> i_props =
new List<string>();
221 i_props.Add( ColumnProperty.SHARD_KEY );
222 column_properties.Add(
"i", i_props );
225 List<string> i8_props =
new List<string>();
226 i8_props.Add( ColumnProperty.SHARD_KEY );
227 i8_props.Add( ColumnProperty.INT8 );
228 column_properties.Add(
"i8", i8_props );
230 List<string> i16_props =
new List<string>();
231 i16_props.Add( ColumnProperty.SHARD_KEY );
232 i16_props.Add( ColumnProperty.INT16 );
233 column_properties.Add(
"i16", i16_props );
236 List<string> d_props =
new List<string>();
237 d_props.Add( ColumnProperty.SHARD_KEY );
238 column_properties.Add(
"d", d_props );
241 List<string> f_props =
new List<string>();
242 f_props.Add( ColumnProperty.SHARD_KEY );
243 column_properties.Add(
"f", f_props );
246 List<string> l_props =
new List<string>();
247 l_props.Add( ColumnProperty.SHARD_KEY );
248 l_props.Add( ColumnProperty.NULLABLE );
249 column_properties.Add(
"l", l_props );
252 List<string> s_props =
new List<string>();
253 s_props.Add( ColumnProperty.SHARD_KEY );
254 s_props.Add( ColumnProperty.NULLABLE );
255 column_properties.Add(
"s", s_props );
258 List<string> c1_props =
new List<string>();
259 c1_props.Add( ColumnProperty.SHARD_KEY );
260 c1_props.Add( ColumnProperty.NULLABLE );
261 c1_props.Add( ColumnProperty.CHAR1 );
262 column_properties.Add(
"c1", c1_props );
265 List<string> c2_props =
new List<string>();
266 c2_props.Add( ColumnProperty.SHARD_KEY );
267 c2_props.Add( ColumnProperty.NULLABLE );
268 c2_props.Add( ColumnProperty.CHAR2 );
269 column_properties.Add(
"c2", c2_props );
272 List<string> c4_props =
new List<string>();
273 c4_props.Add( ColumnProperty.SHARD_KEY );
274 c4_props.Add( ColumnProperty.NULLABLE );
275 c4_props.Add( ColumnProperty.CHAR4 );
276 column_properties.Add(
"c4", c4_props );
279 List<string> c8_props =
new List<string>();
280 c8_props.Add( ColumnProperty.SHARD_KEY );
281 c8_props.Add( ColumnProperty.NULLABLE );
282 c8_props.Add( ColumnProperty.CHAR8 );
283 column_properties.Add(
"c8", c8_props );
286 List<string> c16_props =
new List<string>();
287 c16_props.Add( ColumnProperty.SHARD_KEY );
288 c16_props.Add( ColumnProperty.NULLABLE );
289 c16_props.Add( ColumnProperty.CHAR16 );
290 column_properties.Add(
"c16", c16_props );
293 List<string> c32_props =
new List<string>();
294 c32_props.Add( ColumnProperty.SHARD_KEY );
295 c32_props.Add( ColumnProperty.NULLABLE );
296 c32_props.Add( ColumnProperty.CHAR32 );
297 column_properties.Add(
"c32", c32_props );
300 List<string> c64_props =
new List<string>();
301 c64_props.Add( ColumnProperty.SHARD_KEY );
302 c64_props.Add( ColumnProperty.NULLABLE );
303 c64_props.Add( ColumnProperty.CHAR64 );
304 column_properties.Add(
"c64", c64_props );
307 List<string> c128_props =
new List<string>();
308 c128_props.Add( ColumnProperty.SHARD_KEY );
309 c128_props.Add( ColumnProperty.NULLABLE );
310 c128_props.Add( ColumnProperty.CHAR128 );
311 column_properties.Add(
"c128", c128_props );
314 List<string> c256_props =
new List<string>();
315 c256_props.Add( ColumnProperty.SHARD_KEY );
316 c256_props.Add( ColumnProperty.NULLABLE );
317 c256_props.Add( ColumnProperty.CHAR256 );
318 column_properties.Add(
"c256", c256_props );
321 List<string> date_props =
new List<string>();
322 date_props.Add( ColumnProperty.DATE );
323 date_props.Add( ColumnProperty.SHARD_KEY );
324 date_props.Add( ColumnProperty.NULLABLE );
325 column_properties.Add(
"date", date_props );
328 List<string> datetime_props =
new List<string>();
329 datetime_props.Add( ColumnProperty.DATETIME );
330 datetime_props.Add( ColumnProperty.SHARD_KEY );
331 datetime_props.Add( ColumnProperty.NULLABLE );
332 column_properties.Add(
"datetime", datetime_props );
335 List<string> decimal_props =
new List<string>();
336 decimal_props.Add(ColumnProperty.DECIMAL);
337 decimal_props.Add(ColumnProperty.SHARD_KEY);
338 decimal_props.Add( ColumnProperty.NULLABLE );
339 column_properties.Add(
"decimal_", decimal_props );
342 List<string> ipv4_props =
new List<string>();
343 ipv4_props.Add( ColumnProperty.IPV4 );
344 ipv4_props.Add( ColumnProperty.SHARD_KEY );
345 ipv4_props.Add( ColumnProperty.NULLABLE );
346 column_properties.Add(
"ipv4", ipv4_props );
349 List<string> time_props =
new List<string>();
350 time_props.Add( ColumnProperty.TIME );
351 time_props.Add( ColumnProperty.SHARD_KEY );
352 time_props.Add( ColumnProperty.NULLABLE );
353 column_properties.Add(
"time", time_props );
356 List<string> timestamp_props =
new List<string>();
357 timestamp_props.Add( ColumnProperty.TIMESTAMP );
358 timestamp_props.Add( ColumnProperty.SHARD_KEY );
359 column_properties.Add(
"timestamp", timestamp_props );
362 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
365 string type_id = type1.create( kdb );
368 Console.WriteLine(
"Created type.\n" );
370 string table_name =
"csharp_example_table_all_shards";
372 Console.WriteLine(
"Clearing any existing table named '{0}'\n", table_name );
373 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
377 Console.WriteLine( $
"Creating table named '{table_name}'\n" );
378 kdb.createTable( table_name, type_id );
382 int batch_size = 1000;
383 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
387 int num_records = batch_size * 10;
388 Console.WriteLine( $
"Starting to generate {num_records} records.\n" );
389 List<record_type_all> records =
new List<record_type_all>();
390 Random rng =
new Random();
391 double null_probability = 0.15;
392 for (
int i = 0; i < num_records; ++i )
395 int max_str_len = rng.Next( 0, 256 );
396 record_type_all record =
new record_type_all()
398 i = ( rng.NextDouble() < null_probability ) ? null : (
int?) rng.Next(),
399 i8 = ( rng.NextDouble() < null_probability ) ? null : (
int?) rng.Next( -128, 128 ),
400 i16 = ( rng.NextDouble() < null_probability ) ? null : (
int?) rng.Next( -32768, 32768),
401 l = (long)rng.Next(),
403 f = ( rng.NextDouble() < null_probability ) ? null : (
float?)(rng.NextDouble() * rng.Next()),
404 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
405 s = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
406 c1 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( 1 ),
407 c2 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( 2 ),
408 c4 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 5) ),
409 c8 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 9) ),
410 c16 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 17) ),
411 c32 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 5, 33) ),
412 c64 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 65) ),
413 c128 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 129) ),
414 c256 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 25, 257) ),
415 date = ( rng.NextDouble() < null_probability ) ? null :
Test.
generate_date( rng ),
416 datetime = (rng.NextDouble() < null_probability) ? null : Test.generate_datetime(rng),
418 ipv4 = ( rng.NextDouble() < null_probability ) ? null : Test.generate_IPv4( rng ),
420 timestamp = ( rng.NextDouble() < null_probability ) ? null : ((
long?)rng.Next( -306102240, 293795424 ) * rng.Next( 100000 ))
425 ingestor.insert( record );
428 Console.WriteLine( $
"Generated {num_records} records." );
435 Console.WriteLine(
"\nFlushing any remaining records." );
441 private static void test_record_retrieval_by_key(
string server_url )
446 Console.WriteLine(
"\n\n" );
447 Console.WriteLine(
"Test Multihead Key Lookup: One column per Type; one numeric and one string" );
448 Console.WriteLine(
"shard key (no primary key)" );
449 Console.WriteLine(
"==========================================================================" );
452 Console.WriteLine(
"Creating a type with all column types (all are nullable; one numeric and one string shard columns).\n" );
456 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
459 List<string> i_props =
new List<string>();
460 column_properties.Add(
"i", i_props );
463 List<string> i8_props =
new List<string>();
464 i8_props.Add( ColumnProperty.SHARD_KEY );
465 i8_props.Add( ColumnProperty.INT8 );
466 column_properties.Add(
"i8", i8_props );
468 List<string> i16_props =
new List<string>();
469 i16_props.Add( ColumnProperty.INT16 );
470 column_properties.Add(
"i16", i16_props );
473 List<string> d_props =
new List<string>();
474 column_properties.Add(
"d", d_props );
477 List<string> f_props =
new List<string>();
478 column_properties.Add(
"f", f_props );
481 List<string> l_props =
new List<string>();
482 l_props.Add( ColumnProperty.NULLABLE );
483 column_properties.Add(
"l", l_props );
486 List<string> s_props =
new List<string>();
487 s_props.Add( ColumnProperty.NULLABLE );
488 column_properties.Add(
"s", s_props );
491 List<string> c1_props =
new List<string>();
492 c1_props.Add( ColumnProperty.SHARD_KEY );
493 c1_props.Add( ColumnProperty.NULLABLE );
494 c1_props.Add( ColumnProperty.CHAR1 );
495 column_properties.Add(
"c1", c1_props );
498 List<string> c2_props =
new List<string>();
499 c2_props.Add( ColumnProperty.NULLABLE );
500 c2_props.Add( ColumnProperty.CHAR2 );
501 column_properties.Add(
"c2", c2_props );
504 List<string> c4_props =
new List<string>();
505 c4_props.Add( ColumnProperty.NULLABLE );
506 c4_props.Add( ColumnProperty.CHAR4 );
507 column_properties.Add(
"c4", c4_props );
510 List<string> c8_props =
new List<string>();
511 c8_props.Add( ColumnProperty.NULLABLE );
512 c8_props.Add( ColumnProperty.CHAR8 );
513 column_properties.Add(
"c8", c8_props );
516 List<string> c16_props =
new List<string>();
517 c16_props.Add( ColumnProperty.NULLABLE );
518 c16_props.Add( ColumnProperty.CHAR16 );
519 column_properties.Add(
"c16", c16_props );
522 List<string> c32_props =
new List<string>();
523 c32_props.Add( ColumnProperty.NULLABLE );
524 c32_props.Add( ColumnProperty.CHAR32 );
525 column_properties.Add(
"c32", c32_props );
528 List<string> c64_props =
new List<string>();
529 c64_props.Add( ColumnProperty.NULLABLE );
530 c64_props.Add( ColumnProperty.CHAR64 );
531 column_properties.Add(
"c64", c64_props );
534 List<string> c128_props =
new List<string>();
535 c128_props.Add( ColumnProperty.NULLABLE );
536 c128_props.Add( ColumnProperty.CHAR128 );
537 column_properties.Add(
"c128", c128_props );
540 List<string> c256_props =
new List<string>();
541 c256_props.Add( ColumnProperty.NULLABLE );
542 c256_props.Add( ColumnProperty.CHAR256 );
543 column_properties.Add(
"c256", c256_props );
546 List<string> date_props =
new List<string>();
547 date_props.Add( ColumnProperty.DATE );
548 date_props.Add( ColumnProperty.NULLABLE );
549 column_properties.Add(
"date", date_props );
552 List<string> datetime_props =
new List<string>();
553 datetime_props.Add( ColumnProperty.DATETIME );
554 datetime_props.Add( ColumnProperty.NULLABLE );
555 column_properties.Add(
"datetime", datetime_props );
558 List<string> decimal_props =
new List<string>();
559 decimal_props.Add( ColumnProperty.DECIMAL );
560 decimal_props.Add( ColumnProperty.NULLABLE );
561 column_properties.Add(
"decimal_", decimal_props );
564 List<string> ipv4_props =
new List<string>();
565 ipv4_props.Add( ColumnProperty.IPV4 );
566 ipv4_props.Add( ColumnProperty.NULLABLE );
567 column_properties.Add(
"ipv4", ipv4_props );
570 List<string> time_props =
new List<string>();
571 time_props.Add( ColumnProperty.TIME );
572 time_props.Add( ColumnProperty.NULLABLE );
573 column_properties.Add(
"time", time_props );
576 List<string> timestamp_props =
new List<string>();
577 timestamp_props.Add( ColumnProperty.TIMESTAMP );
578 column_properties.Add(
"timestamp", timestamp_props );
581 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
584 string type_id = type1.create( kdb );
587 Console.WriteLine(
"Created type.\n" );
589 string table_name =
"csharp_example_table_all_shards";
591 Console.WriteLine(
"Clearing any existing table named '{0}'\n", table_name );
592 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
596 Console.WriteLine( $
"Creating table named '{table_name}'\n" );
597 kdb.createTable( table_name, type_id );
601 kdb.alterTable( table_name,
"create_index",
"i8" );
602 kdb.alterTable( table_name,
"create_index",
"c1" );
605 int batch_size = 1000;
606 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
613 int num_records = batch_size * 10;
614 Console.WriteLine( $
"Starting to generate {num_records} records.\n" );
615 List<record_type_all> records =
new List<record_type_all>();
616 Random rng =
new Random();
617 double null_probability = 0.15;
618 double shard_null_probability = 0;
619 for (
int i = 0; i < num_records; ++i )
622 int max_str_len = rng.Next( 0, 256 );
623 record_type_all record =
new record_type_all()
625 i = ( rng.NextDouble() < null_probability ) ? null : (
int?) rng.Next(),
626 i8 = ( rng.NextDouble() < shard_null_probability ) ? null : (
int?) rng.Next( 110, 128 ),
628 i16 = ( rng.NextDouble() < null_probability ) ? null : (
int?) rng.Next( -32768, 32768),
629 l = (long)rng.Next(),
631 f = ( rng.NextDouble() < null_probability ) ? null : (
float?)(rng.NextDouble() * rng.Next()),
632 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
633 s = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
634 c1 = ( rng.NextDouble() < shard_null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( 1 ),
635 c2 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( 2 ),
636 c4 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 5) ),
637 c8 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 9) ),
638 c16 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 17) ),
639 c32 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 5, 33) ),
640 c64 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 65) ),
641 c128 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 129) ),
642 c256 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 25, 257) ),
643 date = ( rng.NextDouble() < null_probability ) ? null :
Test.
generate_date( rng ),
644 datetime = (rng.NextDouble() < null_probability) ? null : Test.generate_datetime(rng),
646 ipv4 = ( rng.NextDouble() < null_probability ) ? null : Test.generate_IPv4( rng ),
648 timestamp = ( rng.NextDouble() < null_probability ) ? null : ((
long?)rng.Next( -306102240, 293795424 ) * rng.Next( 100000 ))
652 records.Add( record );
653 ingestor.insert( record );
656 Console.WriteLine( $
"Generated {num_records} records." );
659 Console.WriteLine(
"\nFlushing any remaining records." );
663 Console.WriteLine(
"Creating the record retriever...");
664 RecordRetriever<record_type_all> retriever =
new RecordRetriever<record_type_all>( kdb, table_name, type1 );
665 Console.WriteLine(
"Attempting record retrieval...");
667 GetRecordsResponse<record_type_all> response = retriever.getRecordsByKey( records[ 0 ] );
668 Console.WriteLine(
"Number of records fetched: {0}", response.total_number_of_records );
669 Console.WriteLine(
"Records fetched: ");
670 foreach ( var record
in response.data )
671 Console.WriteLine( record.ToString() );
673 Console.WriteLine(
"Are there more records to fetch?: {0}", response.has_more_records);
678 private static void test_all_types_ip_regex_3shard_0pk(
string server_url )
683 Console.WriteLine(
"\n\n" );
684 Console.WriteLine(
"Test Multihead Ingest with a Regex Given for Worker IP Addresses (3 shard keys, no PKs)" );
685 Console.WriteLine(
"=======================================================================================" );
690 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
692 List<string> i_props =
new List<string>();
693 i_props.Add( ColumnProperty.SHARD_KEY );
694 column_properties.Add(
"i", i_props );
696 List<string> d_props =
new List<string>();
697 d_props.Add( ColumnProperty.SHARD_KEY );
698 column_properties.Add(
"d", d_props );
700 List<string> i16_props =
new List<string>();
701 i16_props.Add( ColumnProperty.SHARD_KEY );
702 column_properties.Add(
"i16", i16_props );
705 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
708 string type_id = type1.create( kdb );
710 string table_name =
"csharp_example_table_3s0pk";
712 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
713 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
717 Console.WriteLine( $
"Creating table named '{table_name}'" );
718 kdb.createTable( table_name, type_id );
722 int batch_size = 100;
724 Regex ip_regex =
new Regex(
"192.168.*" );
726 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1, null, worker_list );
729 int num_records = batch_size * 5;
730 List<record_type_all> records =
new List<record_type_all>();
731 Random rng =
new Random();
732 double null_probability = 0.2;
733 for (
int i = 0; i < num_records; ++i )
736 int max_str_len = rng.Next( 0, 256 );
737 record_type_all record =
new record_type_all()
742 l = (
long)rng.Next(),
743 f = (
float)(rng.NextDouble() * rng.Next()),
744 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
745 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
746 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
747 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
748 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
749 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
750 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
751 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
752 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
753 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
754 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
756 datetime = Test.generate_datetime( rng ),
758 ipv4 = Test.generate_IPv4( rng ),
760 timestamp = (long) rng.Next()
764 records.Add( record );
767 Console.WriteLine( $
"Generated {num_records} records." );
770 Console.WriteLine( $
"Inserting {num_records} records..." );
771 ingestor.insert( records );
774 Console.WriteLine(
"\nFlushing any remaining records." );
781 private static void test_all_types_3pk_3shard(
string server_url )
786 Console.WriteLine(
"\n\n" );
787 Console.WriteLine(
"Test Multihead Ingest: One column per Type; 3 Primary Keys, 3 Shard Keys" );
788 Console.WriteLine(
"========================================================================" );
793 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
796 List<string> l_props =
new List<string>();
797 l_props.Add( ColumnProperty.PRIMARY_KEY );
798 l_props.Add( ColumnProperty.SHARD_KEY );
799 column_properties.Add(
"l", l_props );
802 List<string> date_props =
new List<string>();
803 date_props.Add( ColumnProperty.DATE );
804 date_props.Add( ColumnProperty.PRIMARY_KEY );
805 date_props.Add( ColumnProperty.SHARD_KEY );
806 column_properties.Add(
"date", date_props );
809 List<string> time_props =
new List<string>();
810 time_props.Add( ColumnProperty.TIME );
811 time_props.Add( ColumnProperty.PRIMARY_KEY );
812 time_props.Add( ColumnProperty.SHARD_KEY );
813 column_properties.Add(
"time", time_props );
816 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
819 string type_id = type1.create( kdb );
823 string table_name =
"csharp_example_table_3s3pk";
825 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
826 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
830 Console.WriteLine( $
"Creating table named '{table_name}'" );
831 kdb.createTable( table_name, type_id );
835 int batch_size = 100;
836 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
839 int num_records = batch_size * 50;
840 Random rng =
new Random();
841 double null_probability = 0.2;
842 for (
int i = 0; i < num_records; ++i )
845 int max_str_len = rng.Next( 0, 256 );
846 record_type_all record =
new record_type_all()
851 l = (
long)rng.Next(),
852 f = (
float)(rng.NextDouble() * rng.Next()),
853 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
854 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
855 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
856 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
857 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
858 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
859 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
860 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
861 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
862 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
863 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
865 datetime = Test.generate_datetime( rng ),
867 ipv4 = Test.generate_IPv4( rng ),
869 timestamp = (long) rng.Next()
873 ingestor.insert( record );
876 Console.WriteLine( $
"Generated {num_records} records." );
879 Console.WriteLine(
"\nFlushing any remaining records." );
885 private static void test_all_types_3pk_0shard(
string server_url )
890 Console.WriteLine(
"\n\n" );
891 Console.WriteLine(
"Test Multihead Ingest: One column per type; 3 Primary Keys, No Shard Key" );
892 Console.WriteLine(
"========================================================================" );
897 IDictionary<string, IList<string>> column_properties =
new Dictionary<string, IList<string>>();
900 List<string> l_props =
new List<string>();
901 l_props.Add( ColumnProperty.PRIMARY_KEY );
902 column_properties.Add(
"l", l_props );
905 List<string> date_props =
new List<string>();
906 date_props.Add( ColumnProperty.PRIMARY_KEY );
907 column_properties.Add(
"date", date_props );
910 List<string> time_props =
new List<string>();
911 time_props.Add( ColumnProperty.PRIMARY_KEY );
912 column_properties.Add(
"time", time_props );
915 KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
918 string type_id = type1.create( kdb );
922 string table_name =
"csharp_example_table_0s3pk";
924 Console.WriteLine(
"Clearing any existing table named '{0}'", table_name );
925 try { kdb.clearTable( table_name, null ); }
catch ( Exception ex ) { }
929 Console.WriteLine( $
"Creating table named '{table_name}'" );
930 kdb.createTable( table_name, type_id );
934 int batch_size = 100;
935 KineticaIngestor<record_type_all> ingestor =
new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
938 int num_records = batch_size * 50;
939 Random rng =
new Random();
940 double null_probability = 0.2;
941 for (
int i = 0; i < num_records; ++i )
944 int max_str_len = rng.Next( 0, 256 );
945 record_type_all record =
new record_type_all()
950 l = (
long)rng.Next(),
951 f = (
float)(rng.NextDouble() * rng.Next()),
952 d = ( rng.NextDouble() < null_probability ) ? null : (
double? ) ( rng.NextDouble() * rng.Next() ),
953 s = System.IO.Path.GetRandomFileName().Truncate( max_str_len ),
954 c1 = System.IO.Path.GetRandomFileName().Truncate( 1 ),
955 c2 = System.IO.Path.GetRandomFileName().Truncate( 2 ),
956 c4 = System.IO.Path.GetRandomFileName().Truncate( 4 ),
957 c8 = System.IO.Path.GetRandomFileName().Truncate( 8 ),
958 c16 = System.IO.Path.GetRandomFileName().Truncate( 16 ),
959 c32 = System.IO.Path.GetRandomFileName().Truncate( 32 ),
960 c64 = System.IO.Path.GetRandomFileName().Truncate( 64 ),
961 c128 = System.IO.Path.GetRandomFileName().Truncate( 128 ),
962 c256 = System.IO.Path.GetRandomFileName().Truncate( 256 ),
964 datetime = Test.generate_datetime( rng ),
966 ipv4 = Test.generate_IPv4( rng ),
968 timestamp = (long) rng.Next()
972 ingestor.insert( record );
975 Console.WriteLine( $
"Generated {num_records} records." );
978 Console.WriteLine(
"\nFlushing any remaining records." );
991 int past_range = -90 * 365;
992 int future_range = 20 * 365;
993 int offset = rng.Next( past_range, future_range );
994 DateTime random_date = DateTime.Today.AddDays( offset );
995 return String.Format(
"{0:yyyy-MM-dd}", random_date );
1007 int past_range = -90 * 365;
1008 int future_range = 20 * 365;
1009 int offset = rng.Next( past_range, future_range );
1010 int year = rng.Next(1900, 2500);
1011 int month = rng.Next(1, 12);
1012 int day = rng.Next(1, 28);
1013 int hour = rng.Next(0, 23);
1014 int minute = rng.Next(0, 59);
1015 int second = rng.Next(0, 59);
1016 int msecond = rng.Next(0, 999);
1018 DateTime random_datetime =
new DateTime( year, month, day,
1019 hour, minute, second, msecond );
1022 int time_chance_percent = 90;
1023 if (rng.Next(101) > time_chance_percent)
1024 return String.Format(
"{0:yyyy-MM-dd}", random_datetime);
1028 int num_ms_digits = rng.Next(7);
1029 switch (num_ms_digits)
1032 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss}", random_datetime);
1034 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss.F}", random_datetime);
1036 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FF}", random_datetime);
1038 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FFF}", random_datetime);
1040 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FFFF}", random_datetime);
1042 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FFFFF}", random_datetime);
1045 return String.Format(
"{0:yyyy-MM-dd HH:mm:ss.FFFFFF}", random_datetime);
1052 private static readonly
string numbers =
"0123456789";
1062 string sign = (rng.Next( 2 ) == 0) ?
"-" :
"";
1065 string precision =
new string( Enumerable.Repeat(
'1', rng.Next( 15 ) ).Select( i =>
Test.numbers[ rng.Next( numbers.Length ) ] ).ToArray() );
1066 string scale = rng.Next( 0, 10000 ).ToString();
1067 return ( sign + precision +
"." + scale );
1079 string n1 = rng.Next( 256 ).ToString();
1080 string n2 = rng.Next( 256 ).ToString();
1081 string n3 = rng.Next( 256 ).ToString();
1082 string n4 = rng.Next( 256 ).ToString();
1084 return ( n1 + dot + n2 + dot + n3 + dot + n4 );
1096 int max_miliseconds = 86400000;
1097 DateTime time = DateTime.Today;
1099 time = time.Add( TimeSpan.FromMilliseconds( rng.Next( max_miliseconds ) ) );
1102 if ( (time.Millisecond > 0) && (rng.Next( 1, 6 ) > 3) )
1103 time_str = String.Format(
"{0:HH}:{0:mm}:{0:ss}.{0:FFF}", time );
1105 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