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://<IP>:<PORT>" );
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 );
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>();
132 Console.WriteLine(
"Caught exception: " + ex.Message );
136 Console.WriteLine(
"Creating a DB handle with the proper username and password" );
139 db_options.Password = password;
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}'" );
160 int num_records = 5000;
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>();
222 column_properties.Add(
"i", i_props );
225 List<string> i8_props =
new List<string>();
228 column_properties.Add(
"i8", i8_props );
230 List<string> i16_props =
new List<string>();
233 column_properties.Add(
"i16", i16_props );
236 List<string> d_props =
new List<string>();
238 column_properties.Add(
"d", d_props );
241 List<string> f_props =
new List<string>();
243 column_properties.Add(
"f", f_props );
246 List<string> l_props =
new List<string>();
249 column_properties.Add(
"l", l_props );
252 List<string> s_props =
new List<string>();
255 column_properties.Add(
"s", s_props );
258 List<string> c1_props =
new List<string>();
262 column_properties.Add(
"c1", c1_props );
265 List<string> c2_props =
new List<string>();
269 column_properties.Add(
"c2", c2_props );
272 List<string> c4_props =
new List<string>();
276 column_properties.Add(
"c4", c4_props );
279 List<string> c8_props =
new List<string>();
283 column_properties.Add(
"c8", c8_props );
286 List<string> c16_props =
new List<string>();
290 column_properties.Add(
"c16", c16_props );
293 List<string> c32_props =
new List<string>();
297 column_properties.Add(
"c32", c32_props );
300 List<string> c64_props =
new List<string>();
304 column_properties.Add(
"c64", c64_props );
307 List<string> c128_props =
new List<string>();
311 column_properties.Add(
"c128", c128_props );
314 List<string> c256_props =
new List<string>();
318 column_properties.Add(
"c256", c256_props );
321 List<string> date_props =
new List<string>();
325 column_properties.Add(
"date", date_props );
328 List<string> datetime_props =
new List<string>();
332 column_properties.Add(
"datetime", datetime_props );
335 List<string> decimal_props =
new List<string>();
339 column_properties.Add(
"decimal_", decimal_props );
342 List<string> ipv4_props =
new List<string>();
346 column_properties.Add(
"ipv4", ipv4_props );
349 List<string> time_props =
new List<string>();
353 column_properties.Add(
"time", time_props );
356 List<string> timestamp_props =
new List<string>();
359 column_properties.Add(
"timestamp", timestamp_props );
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" );
382 int batch_size = 1000;
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),
417 decimal_ = (rng.NextDouble() < null_probability) ? null :
Test.generate_decimal(rng),
418 ipv4 = ( rng.NextDouble() < null_probability ) ? null :
Test.generate_IPv4( rng ),
419 time = (rng.NextDouble() < null_probability) ? null :
Test.generate_time(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>();
466 column_properties.Add(
"i8", i8_props );
468 List<string> i16_props =
new List<string>();
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>();
483 column_properties.Add(
"l", l_props );
486 List<string> s_props =
new List<string>();
488 column_properties.Add(
"s", s_props );
491 List<string> c1_props =
new List<string>();
495 column_properties.Add(
"c1", c1_props );
498 List<string> c2_props =
new List<string>();
501 column_properties.Add(
"c2", c2_props );
504 List<string> c4_props =
new List<string>();
507 column_properties.Add(
"c4", c4_props );
510 List<string> c8_props =
new List<string>();
513 column_properties.Add(
"c8", c8_props );
516 List<string> c16_props =
new List<string>();
519 column_properties.Add(
"c16", c16_props );
522 List<string> c32_props =
new List<string>();
525 column_properties.Add(
"c32", c32_props );
528 List<string> c64_props =
new List<string>();
531 column_properties.Add(
"c64", c64_props );
534 List<string> c128_props =
new List<string>();
537 column_properties.Add(
"c128", c128_props );
540 List<string> c256_props =
new List<string>();
543 column_properties.Add(
"c256", c256_props );
546 List<string> date_props =
new List<string>();
549 column_properties.Add(
"date", date_props );
552 List<string> datetime_props =
new List<string>();
555 column_properties.Add(
"datetime", datetime_props );
558 List<string> decimal_props =
new List<string>();
561 column_properties.Add(
"decimal_", decimal_props );
564 List<string> ipv4_props =
new List<string>();
567 column_properties.Add(
"ipv4", ipv4_props );
570 List<string> time_props =
new List<string>();
573 column_properties.Add(
"time", time_props );
576 List<string> timestamp_props =
new List<string>();
578 column_properties.Add(
"timestamp", timestamp_props );
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" );
601 kdb.
alterTable( table_name,
"create_index",
"i8" );
602 kdb.
alterTable( table_name,
"create_index",
"c1" );
605 int batch_size = 1000;
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),
645 decimal_ = (rng.NextDouble() < null_probability) ? null :
Test.generate_decimal(rng),
646 ipv4 = ( rng.NextDouble() < null_probability ) ? null :
Test.generate_IPv4( rng ),
647 time = (rng.NextDouble() < null_probability) ? null :
Test.generate_time(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...");
665 Console.WriteLine(
"Attempting record retrieval...");
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>();
694 column_properties.Add(
"i", i_props );
696 List<string> d_props =
new List<string>();
698 column_properties.Add(
"d", d_props );
700 List<string> i16_props =
new List<string>();
702 column_properties.Add(
"i16", i16_props );
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}'" );
722 int batch_size = 100;
724 Regex ip_regex =
new Regex(
"192.168.*" );
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 ),
755 date =
Test.generate_date( rng ),
756 datetime =
Test.generate_datetime( rng ),
757 decimal_ =
Test.generate_decimal( rng ),
758 ipv4 =
Test.generate_IPv4( rng ),
759 time =
Test.generate_time( 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>();
799 column_properties.Add(
"l", l_props );
802 List<string> date_props =
new List<string>();
806 column_properties.Add(
"date", date_props );
809 List<string> time_props =
new List<string>();
813 column_properties.Add(
"time", time_props );
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}'" );
835 int batch_size = 100;
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 ),
864 date =
Test.generate_date( rng ),
865 datetime =
Test.generate_datetime( rng ),
866 decimal_ =
Test.generate_decimal( rng ),
867 ipv4 =
Test.generate_IPv4( rng ),
868 time =
Test.generate_time( 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>();
902 column_properties.Add(
"l", l_props );
905 List<string> date_props =
new List<string>();
907 column_properties.Add(
"date", date_props );
910 List<string> time_props =
new List<string>();
912 column_properties.Add(
"time", time_props );
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}'" );
934 int batch_size = 100;
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 ),
963 date =
Test.generate_date( rng ),
964 datetime =
Test.generate_datetime( rng ),
965 decimal_ =
Test.generate_decimal( rng ),
966 ipv4 =
Test.generate_IPv4( rng ),
967 time =
Test.generate_time( 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 );
A list of worker URLs to use for multi-head ingest.
const string CHAR1
This property provides optimized memory, disk and query performance for string columns.
static string generate_decimal(Random rng)
Generate a random decimal value (up to 15 digits of precision and up to four digits of scale)...
const string DATETIME
Valid only for 'string' columns.
const string INT16
This property provides optimized memory and query performance for int columns.
static string generate_time(Random rng)
Generate a random time of the format HH:MM:SS[.mmm].
void insert(T record)
Queues a record for insertion into Kinetica.
const string PRIMARY_KEY
This property indicates that this column will be part of (or the entire) primary key.
static string generate_date(Random rng)
Generate a random date.
const string CHAR128
This property provides optimized memory, disk and query performance for string columns.
static string generate_IPv4(Random rng)
Generate a random IPv4 address.
CreateTableResponse createTable(CreateTableRequest request_)
Creates a new table or collection.
Column properties used for Kinetica types.
const string TIMESTAMP
Valid only for 'long' columns.
const string CHAR16
This property provides optimized memory, disk and query performance for string columns.
static string generate_datetime(Random rng)
Generate a random datetime.
Extension to string that has a truncate function.
const string CHAR64
This property provides optimized memory, disk and query performance for string columns.
const string CHAR4
This property provides optimized memory, disk and query performance for string columns.
const string CHAR2
This property provides optimized memory, disk and query performance for string columns.
const string DATE
Valid only for 'string' columns.
const string CHAR8
This property provides optimized memory, disk and query performance for string columns.
const string DECIMAL
Valid only for 'string' columns.
const string CHAR32
This property provides optimized memory, disk and query performance for string columns.
const string IPV4
This property provides optimized memory, disk and query performance for string columns representing I...
GetRecordsResponse< T > getRecordsByKey(T record, string expression=null)
Retrieves records for a given shard key, optionally further limited by an additional expression...
CreateUserInternalResponse createUserInternal(CreateUserInternalRequest request_)
Creates a new internal user (a user whose credentials are managed by the database system)...
ClearTableResponse clearTable(ClearTableRequest request_)
Clears (drops) one or all tables in the database cluster.
Manages the insertion into GPUdb of large numbers of records in bulk, with automatic batch management...
const string CHAR256
This property provides optimized memory, disk and query performance for string columns.
static KineticaType fromClass(Type recordClass, IDictionary< string, IList< string >> properties=null)
Create a KineticaType object from properties of a record class and Kinetica column properties...
const string SHARD_KEY
This property indicates that this column will be part of (or the entire) shard key.
AlterTableResponse alterTable(AlterTableRequest request_)
Apply various modifications to a table, view, or collection.
long total_number_of_records
Total/Filtered number of records.
const string INT8
This property provides optimized memory and query performance for int columns.
static string Truncate(this string value, int maxLength)
string create(Kinetica kinetica)
Given a handle to the server, creates a type in the database based on this data type.
string Username
Optional: User Name for Kinetica security
InsertRecordsRandomResponse insertRecordsRandom(InsertRecordsRandomRequest request_)
Generates a specified number of random records and adds them to the given table.
const string TIME
Valid only for 'string' columns.
const string NULLABLE
This property indicates that this column is nullable.
A set of results returned by Kinetica.getRecords<T>(string,long,long,IDictionary<string, string>).
API to talk to Kinetica Database
Manages the insertion into GPUdb of large numbers of records in bulk, with automatic batch management...
void flush()
Ensures that all queued records are inserted into Kinetica.