Kinetica C# API  Version 7.1.10.0
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Pages
Test.cs
Go to the documentation of this file.
1 
7 using System;
8 using System.Collections.Generic;
9 using System.Linq;
10 using System.Text.RegularExpressions;
11 
12 using kinetica;
13 
14 namespace Test
15 {
19  public static class StringExt
20  {
21  public static string Truncate( this string value, int maxLength )
22  {
23  if ( string.IsNullOrEmpty( value ) )
24  return value;
25 
26  return ( value.Length <= maxLength ) ? value : value.Substring( 0, maxLength );
27  }
28  }
29 
30 
36  class Test
37  {
38  static void Main( string[] args )
39  {
40  Console.WriteLine( "Testing C# Project - Running" );
41  Console.WriteLine();
42 
43  if ( args.Length < 1 )
44  {
45  Console.WriteLine( "Missing URL as command-line parameter." );
46  Console.WriteLine( "E.g., http://kinetica:9191" );
47  return;
48  }
49 
50  try
51  {
52  string server_url = args[0];
53  Console.WriteLine( "URL: {0}", server_url );
54  Console.WriteLine();
55 
56  Kinetica.Options _ServerOptions = new Kinetica.Options();
57  _ServerOptions.Username = args[1];
58  _ServerOptions.Password = args[2];
59 
60 
61  // Run various multihead ingest tests
62  // ----------------------------------
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 );
69  }
70  catch ( kinetica.KineticaIngestor<record_type_all>.InsertException<record_type_all> ex )
71  {
72  Console.WriteLine( "Caught InsertException: {0}", ex.Message );
73  }
74  catch ( KineticaException ex )
75  {
76  Console.WriteLine( "Caught KineticaException: {0}", ex.Message );
77  }
78  catch ( Exception ex )
79  {
80  Console.WriteLine( "Caught Exception: {0}", ex.Message );
81  }
82 
83  // We're done
84  Console.WriteLine();
85  Console.WriteLine( "Testing C# Project - Done" );
86  Console.WriteLine();
87  Console.WriteLine( "Enter any 7-digit prime number to continue: " );
88  Console.ReadLine();
89  } // end Main
90 
91 
92  private class record_type_short
93  {
94  public int i { get; set; }
95  public int i8 { get; set; }
96 
97  public override string ToString()
98  {
99  return $"{{ i={i}, i8={i8} }}";
100  }
101  } // end class record_type_short
102 
103 
104  private static void test_authentication( string server_url, Kinetica.Options _ServerOptions )
105  {
106  Console.WriteLine( "\n\n" );
107  Console.WriteLine( "Test Authentication" );
108  Console.WriteLine( "===================" );
109  Console.WriteLine();
110 
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." );
119  Console.WriteLine();
120 
121  string username = "abcdef"; // correct
122  //string username = "abcdefg"; // wrong
123  string password = "ghijkl123_";
124 
125  // Establish a connection with Kinetica
126  // Create a user
127  Kinetica kdb_ = new Kinetica( server_url, _ServerOptions );
128  Console.WriteLine( $"Creating a user {username}" );
129  Console.WriteLine();
130  IDictionary <string, string> options = new Dictionary<string, string>();
131  try
132  {
133  kdb_.createUserInternal( username, password, options );
134  }
135  catch ( KineticaException ex )
136  {
137  Console.WriteLine( "Caught exception: " + ex.Message );
138  }
139 
140  // Establish another connection with Kinetica with authentication information
141  Console.WriteLine( "Creating a DB handle with the proper username and password" );
142  Kinetica.Options db_options = new Kinetica.Options();
143  db_options.Username = username;
144  db_options.Password = password;
145  Kinetica kdb = new Kinetica( server_url, db_options );
146 
147  // Create the KineticaType object which facilitates creating types in the database
148  KineticaType type1 = KineticaType.fromClass( typeof( record_type_short ) );
149 
150  // Create the type in the database
151  string type_id = type1.create( kdb );
152 
153  string table_name = "csharp_example_table_01_auth";
154  // Clear any previously made table with the same name
155  Console.WriteLine( "Clearing any existing table named '{0}'", table_name );
156  try { kdb.clearTable( table_name, null ); } catch ( Exception ex ) { /* I don't care if the table doesn't already exists! */ }
157  Console.WriteLine();
158 
159  // Create a table of the given type
160  Console.WriteLine( $"Creating table named '{table_name}'" );
161  kdb.createTable( table_name, type_id );
162  Console.WriteLine();
163 
164 
165  int num_records = 5000;
166  kdb.insertRecordsRandom( table_name, num_records );
167  Console.WriteLine( $"Generated {num_records} records." );
168  } // end test_authentication()
169 
170 
171  private class record_type_all
172  {
173  public int? i { get; set; }
174  public int? i8 { get; set; }
175  public int? i16 { get; set; }
176  public long l { get; set; } // not making nullable here so that can be used as a primary key
177  public float? f { get; set; }
178  public double? d { get; set; } // nullable
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; }
195 
196  public override string ToString()
197  {
198  string d_;
199  if ( d != null )
200  d_ = $"{d}";
201  else
202  d_ = "<null>";
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} }}";
204  }
205  } // end class record_type_all
206 
207 
208  private static void test_all_types_allshard( string server_url, Kinetica.Options _ServerOptions )
209  {
210  // Establish a connection with Kinetica
211  Kinetica kdb = new Kinetica( server_url, _ServerOptions );
212 
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( "==============================================================================" );
216  Console.WriteLine();
217 
218  Console.WriteLine( "Creating a type with all column types (all are nullable and shard columns).\n" );
219 
220  // Create a type for our record_type_1 class
221  // Add some interesting properties for some of the data types
222  IDictionary<string, IList<string>> column_properties = new Dictionary<string, IList<string>>();
223 
224  // Integer shard key
225  List<string> i_props = new List<string>();
226  i_props.Add( ColumnProperty.SHARD_KEY );
227  column_properties.Add( "i", i_props );
228 
229  // Integer8 shard key
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 );
234  // Integer16 shard key
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 );
239 
240  // Double shard key
241  List<string> d_props = new List<string>();
242  d_props.Add( ColumnProperty.SHARD_KEY );
243  column_properties.Add( "d", d_props );
244 
245  // Float shard key
246  List<string> f_props = new List<string>();
247  f_props.Add( ColumnProperty.SHARD_KEY );
248  column_properties.Add( "f", f_props );
249 
250  // Long shard key
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 );
255 
256  // string nullable shard key
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 );
261 
262  // char1 shard key, nullable
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 );
268 
269  // char2 shard key, nullable
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 );
275 
276  // char4 shard key, nullable
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 );
282 
283  // char8 shard key, nullable
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 );
289 
290  // char16 shard key, nullable
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 );
296 
297  // char32 shard key, nullable
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 );
303 
304  // char64 shard key, nullable
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 );
310 
311  // char128 shard key, nullable
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 );
317 
318  // char256 shard key, nullable
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 );
324 
325  // date shard key, nullable
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 );
331 
332  // datetime shard key, nullable
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 );
338 
339  // decimal shard key, nullable
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 );
345 
346  // IPv4 shard key, nullable
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 );
352 
353  // time shard key, nullable
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 );
359 
360  // timestamp shard key, already nullable
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 );
365 
366  // Create the KineticaType object which facilitates creating types in the database
367  KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
368 
369  // Create the type in the database
370  string type_id = type1.create( kdb );
371  //Console.WriteLine( "ID of the created type: " + type_id );
372  //Console.WriteLine();
373  Console.WriteLine( "Created type.\n" );
374 
375  string table_name = "csharp_example_table_all_shards";
376  // Clear any previously made table with the same name
377  Console.WriteLine( "Clearing any existing table named '{0}'\n", table_name );
378  try { kdb.clearTable( table_name, null ); } catch ( Exception ex ) { /* I don't care if the table doesn't already exists! */ }
379  Console.WriteLine();
380 
381  // Create a table of the given type
382  Console.WriteLine( $"Creating table named '{table_name}'\n" );
383  kdb.createTable( table_name, type_id );
384  Console.WriteLine();
385 
386  // Create the ingestor
387  int batch_size = 1000;
388  KineticaIngestor<record_type_all> ingestor = new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
389 
390 
391  // Generate data to be inserted
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; // 15% chance of creating nulls
397  for ( int i = 0; i < num_records; ++i )
398  {
399  // Restricting string length to 256
400  int max_str_len = rng.Next( 0, 256 );
401  record_type_all record = new record_type_all()
402  {
403  i = ( rng.NextDouble() < null_probability ) ? null : (int?) rng.Next(),
404  i8 = ( rng.NextDouble() < null_probability ) ? null : (int?) rng.Next( -128, 128 ), // upper exclusive
405  i16 = ( rng.NextDouble() < null_probability ) ? null : (int?) rng.Next( -32768, 32768), // upper exclusive
406  l = (long)rng.Next(),
407  //l = ( rng.NextDouble() < null_probability ) ? null : (long)rng.Next(), // can't be made nullable if not declared as long?
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) ), // any size between empty string to 4 length
414  c8 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 9) ), // any size between empty string to 8 length
415  c16 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 17) ), // any size between empty string to 16 length
416  c32 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 5, 33) ), // any size between [5, 32] in length
417  c64 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 65) ), // any size between [10, 64] in length
418  c128 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 129) ), // any size between [10, 128] in length
419  c256 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 25, 257) ), // any size between [25, 256] in length
420  date = ( rng.NextDouble() < null_probability ) ? null : Test.generate_date( rng ),
421  datetime = (rng.NextDouble() < null_probability) ? null : Test.generate_datetime(rng),
422  decimal_ = (rng.NextDouble() < null_probability) ? null : Test.generate_decimal(rng),
423  ipv4 = ( rng.NextDouble() < null_probability ) ? null : Test.generate_IPv4( rng ),
424  time = (rng.NextDouble() < null_probability) ? null : Test.generate_time(rng),
425  timestamp = ( rng.NextDouble() < null_probability ) ? null : ((long?)rng.Next( -306102240, 293795424 ) * rng.Next( 100000 ))
426  };
427 
428  //Console.WriteLine( "#" + i + ": " + record.ToString() + "\n" ); // debug~~~~~~~~
429  //records.Add( record );
430  ingestor.insert( record );
431  } // end for loop
432 
433  Console.WriteLine( $"Generated {num_records} records." );
434 
436  //Console.WriteLine( $"Inserting {num_records} records..." );
437  //ingestor.insert( records );
438 
439  // Flush the ingestor (which actually inserts the records)
440  Console.WriteLine( "\nFlushing any remaining records." );
441  ingestor.flush();
442  } // end test_all_types_allshard()
443 
444 
445 
446  private static void test_record_retrieval_by_key( string server_url, Kinetica.Options _ServerOptions )
447  {
448  // Establish a connection with Kinetica
449  Kinetica kdb = new Kinetica( server_url, _ServerOptions );
450 
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( "==========================================================================" );
455  Console.WriteLine();
456 
457  Console.WriteLine( "Creating a type with all column types (all are nullable; one numeric and one string shard columns).\n" );
458 
459  // Create a type for our record_type_1 class
460  // Add some interesting properties for some of the data types
461  IDictionary<string, IList<string>> column_properties = new Dictionary<string, IList<string>>();
462 
463  // Integer shard key
464  List<string> i_props = new List<string>();
465  column_properties.Add( "i", i_props );
466 
467  // Integer8 shard key
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 );
472  // Integer16 shard key
473  List<string> i16_props = new List<string>();
474  i16_props.Add( ColumnProperty.INT16 );
475  column_properties.Add( "i16", i16_props );
476 
477  // Double shard key
478  List<string> d_props = new List<string>();
479  column_properties.Add( "d", d_props );
480 
481  // Float shard key
482  List<string> f_props = new List<string>();
483  column_properties.Add( "f", f_props );
484 
485  // Long shard key
486  List<string> l_props = new List<string>();
487  l_props.Add( ColumnProperty.NULLABLE );
488  column_properties.Add( "l", l_props );
489 
490  // string nullable shard key
491  List<string> s_props = new List<string>();
492  s_props.Add( ColumnProperty.NULLABLE );
493  column_properties.Add( "s", s_props );
494 
495  // char1 shard key, nullable
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 );
501 
502  // char2 shard key, nullable
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 );
507 
508  // char4 shard key, nullable
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 );
513 
514  // char8 shard key, nullable
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 );
519 
520  // char16 shard key, nullable
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 );
525 
526  // char32 shard key, nullable
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 );
531 
532  // char64 shard key, nullable
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 );
537 
538  // char128 shard key, nullable
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 );
543 
544  // char256 shard key, nullable
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 );
549 
550  // date shard key, nullable
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 );
555 
556  // datetime shard key, nullable
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 );
561 
562  // decimal shard key, nullable
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 );
567 
568  // IPv4 shard key, nullable
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 );
573 
574  // time shard key, nullable
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 );
579 
580  // timestamp shard key, already nullable
581  List<string> timestamp_props = new List<string>();
582  timestamp_props.Add( ColumnProperty.TIMESTAMP );
583  column_properties.Add( "timestamp", timestamp_props );
584 
585  // Create the KineticaType object which facilitates creating types in the database
586  KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
587 
588  // Create the type in the database
589  string type_id = type1.create( kdb );
590  //Console.WriteLine( "ID of the created type: " + type_id );
591  //Console.WriteLine();
592  Console.WriteLine( "Created type.\n" );
593 
594  string table_name = "csharp_example_table_all_shards";
595  // Clear any previously made table with the same name
596  Console.WriteLine( "Clearing any existing table named '{0}'\n", table_name );
597  try { kdb.clearTable( table_name, null ); } catch ( Exception ex ) { /* I don't care if the table doesn't already exists! */ }
598  Console.WriteLine();
599 
600  // Create a table of the given type
601  Console.WriteLine( $"Creating table named '{table_name}'\n" );
602  kdb.createTable( table_name, type_id );
603  Console.WriteLine();
604 
605  // Create indices on the shard columns (6.2 limitation for key lookup)
606  kdb.alterTable( table_name, "create_index", "i8" );
607  kdb.alterTable( table_name, "create_index", "c1" );
608 
609  // Create the ingestor
610  int batch_size = 1000;
611  KineticaIngestor<record_type_all> ingestor = new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
612 
613 
614  // Generate data to be inserted
615  // Note that the current sharded columns (i8 and c1) will not
616  // get nulls since in 6.2, Kinetica does not support nulls for
617  // key lookup
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; // 15% chance of creating nulls
623  double shard_null_probability = 0; // in 6.2, key lookup can't handle nulls
624  for ( int i = 0; i < num_records; ++i )
625  {
626  // Restricting string length to 256
627  int max_str_len = rng.Next( 0, 256 );
628  record_type_all record = new record_type_all()
629  {
630  i = ( rng.NextDouble() < null_probability ) ? null : (int?) rng.Next(),
631  i8 = ( rng.NextDouble() < shard_null_probability ) ? null : (int?) rng.Next( 110, 128 ), // Limiting the range in order to get multiple records per shard key
632  //i8 = ( rng.NextDouble() < shard_null_probability ) ? null : (int?) rng.Next( -128, 128 ), // upper exclusive
633  i16 = ( rng.NextDouble() < null_probability ) ? null : (int?) rng.Next( -32768, 32768), // upper exclusive
634  l = (long)rng.Next(),
635  //l = ( rng.NextDouble() < null_probability ) ? null : (long)rng.Next(), // can't be made nullable if not declared as long?
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) ), // any size between empty string to 4 length
642  c8 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 9) ), // any size between empty string to 8 length
643  c16 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 0, 17) ), // any size between empty string to 16 length
644  c32 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 5, 33) ), // any size between [5, 32] in length
645  c64 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 65) ), // any size between [10, 64] in length
646  c128 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 10, 129) ), // any size between [10, 128] in length
647  c256 = ( rng.NextDouble() < null_probability ) ? null : System.IO.Path.GetRandomFileName().Truncate( rng.Next( 25, 257) ), // any size between [25, 256] in length
648  date = ( rng.NextDouble() < null_probability ) ? null : Test.generate_date( rng ),
649  datetime = (rng.NextDouble() < null_probability) ? null : Test.generate_datetime(rng),
650  decimal_ = (rng.NextDouble() < null_probability) ? null : Test.generate_decimal(rng),
651  ipv4 = ( rng.NextDouble() < null_probability ) ? null : Test.generate_IPv4( rng ),
652  time = (rng.NextDouble() < null_probability) ? null : Test.generate_time(rng),
653  timestamp = ( rng.NextDouble() < null_probability ) ? null : ((long?)rng.Next( -306102240, 293795424 ) * rng.Next( 100000 ))
654  };
655 
656  //Console.WriteLine( "#" + i + ": " + record.ToString() + "\n" ); // debug~~~~~~~~
657  records.Add( record );
658  ingestor.insert( record );
659  } // end for loop
660 
661  Console.WriteLine( $"Generated {num_records} records." );
662 
663  // Flush the ingestor (which actually inserts the records)
664  Console.WriteLine( "\nFlushing any remaining records." );
665  ingestor.flush();
666 
667  // Look up records by any key
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...");
671  // Perform the key lookup operations
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() );
677 
678  Console.WriteLine( "Are there more records to fetch?: {0}", response.has_more_records);
679 
680  } // end test_record_retrieval_by_key()
681 
682 
683  private static void test_all_types_ip_regex_3shard_0pk( string server_url, Kinetica.Options _ServerOptions )
684  {
685  // Establish a connection with Kinetica
686  Kinetica kdb = new Kinetica( server_url, _ServerOptions );
687 
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( "=======================================================================================" );
691  Console.WriteLine();
692 
693  // Create a type for our record_type_1 class
694  // Add some interesting properties for some of the data types
695  IDictionary<string, IList<string>> column_properties = new Dictionary<string, IList<string>>();
696  // Integer shard key
697  List<string> i_props = new List<string>();
698  i_props.Add( ColumnProperty.SHARD_KEY );
699  column_properties.Add( "i", i_props );
700  // Double shard key
701  List<string> d_props = new List<string>();
702  d_props.Add( ColumnProperty.SHARD_KEY );
703  column_properties.Add( "d", d_props );
704  // Short shard key
705  List<string> i16_props = new List<string>();
706  i16_props.Add( ColumnProperty.SHARD_KEY );
707  column_properties.Add( "i16", i16_props );
708 
709  // Create the KineticaType object which facilitates creating types in the database
710  KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
711 
712  // Create the type in the database
713  string type_id = type1.create( kdb );
714 
715  string table_name = "csharp_example_table_3s0pk";
716  // Clear any previously made table with the same name
717  Console.WriteLine( "Clearing any existing table named '{0}'", table_name );
718  try { kdb.clearTable( table_name, null ); } catch ( Exception ex ) { /* I don't care if the table doesn't already exists! */ }
719  Console.WriteLine();
720 
721  // Create a table of the given type
722  Console.WriteLine( $"Creating table named '{table_name}'" );
723  kdb.createTable( table_name, type_id );
724  Console.WriteLine();
725 
726  // Create the ingestor
727  int batch_size = 100;
728  // Note: May need to adjust the regex for this test to pass
729  Regex ip_regex = new Regex( "192.168.*" );
730  kinetica.Utils.WorkerList worker_list = new kinetica.Utils.WorkerList( kdb, ip_regex );
731  KineticaIngestor<record_type_all> ingestor = new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1, null, worker_list );
732 
733  // Generate data to be inserted
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 )
739  {
740  // Restricting string length to 256
741  int max_str_len = rng.Next( 0, 256 );
742  record_type_all record = new record_type_all()
743  {
744  i = rng.Next(),
745  i8 = rng.Next(),
746  i16 = rng.Next(),
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 ),
760  date = Test.generate_date( rng ),
761  datetime = Test.generate_datetime( rng ),
762  decimal_ = Test.generate_decimal( rng ),
763  ipv4 = Test.generate_IPv4( rng ),
764  time = Test.generate_time( rng ),
765  timestamp = (long) rng.Next()
766  };
767 
768  //Console.WriteLine( record.ToString() ); // debug~~~~~~~~
769  records.Add( record );
770  } // end for loop
771 
772  Console.WriteLine( $"Generated {num_records} records." );
773 
774  // Insert the records into the ingestor
775  Console.WriteLine( $"Inserting {num_records} records..." );
776  ingestor.insert( records );
777 
778  // Flush the ingestor (which actually inserts the records)
779  Console.WriteLine( "\nFlushing any remaining records." );
780  ingestor.flush();
781  } // end test_all_types_ip_regex_3shard_0pk()
782 
783 
784 
785 
786  private static void test_all_types_3pk_3shard( string server_url, Kinetica.Options _ServerOptions )
787  {
788  // Establish a connection with Kinetica
789  Kinetica kdb = new Kinetica( server_url, _ServerOptions );
790 
791  Console.WriteLine( "\n\n" );
792  Console.WriteLine( "Test Multihead Ingest: One column per Type; 3 Primary Keys, 3 Shard Keys" );
793  Console.WriteLine( "========================================================================" );
794  Console.WriteLine();
795 
796  // Create a type for our record_type_1 class
797  // Add some interesting properties for some of the data types
798  IDictionary<string, IList<string>> column_properties = new Dictionary<string, IList<string>>();
799 
800  // long shard key, also primary key
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 );
805 
806  // date primary key as well as shard key
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 );
812 
813  // time primary key as well as shard
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 );
819 
820  // Create the KineticaType object which facilitates creating types in the database
821  KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
822 
823  // Create the type in the database
824  string type_id = type1.create( kdb );
825  //Console.WriteLine( "ID of the created type: " + type_id );
826  //Console.WriteLine();
827 
828  string table_name = "csharp_example_table_3s3pk";
829  // Clear any previously made table with the same name
830  Console.WriteLine( "Clearing any existing table named '{0}'", table_name );
831  try { kdb.clearTable( table_name, null ); } catch ( Exception ex ) { /* I don't care if the table doesn't already exists! */ }
832  Console.WriteLine();
833 
834  // Create a table of the given type
835  Console.WriteLine( $"Creating table named '{table_name}'" );
836  kdb.createTable( table_name, type_id );
837  Console.WriteLine();
838 
839  // Create the ingestor
840  int batch_size = 100;
841  KineticaIngestor<record_type_all> ingestor = new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
842 
843  // Generate data to be inserted
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 )
848  {
849  // Restricting string length to 256
850  int max_str_len = rng.Next( 0, 256 );
851  record_type_all record = new record_type_all()
852  {
853  i = rng.Next(),
854  i8 = rng.Next(),
855  i16 = rng.Next(),
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 ),
869  date = Test.generate_date( rng ),
870  datetime = Test.generate_datetime( rng ),
871  decimal_ = Test.generate_decimal( rng ),
872  ipv4 = Test.generate_IPv4( rng ),
873  time = Test.generate_time( rng ),
874  timestamp = (long) rng.Next()
875  };
876 
877  //Console.WriteLine( record.ToString() ); // debug~~~~~~~~
878  ingestor.insert( record );
879  } // end for loop
880 
881  Console.WriteLine( $"Generated {num_records} records." );
882 
883  // Flush the ingestor (which actually inserts the records)
884  Console.WriteLine( "\nFlushing any remaining records." );
885  ingestor.flush();
886  } // end test_all_types_3pk_3shard()
887 
888 
889 
890  private static void test_all_types_3pk_0shard( string server_url, Kinetica.Options _ServerOptions )
891  {
892  // Establish a connection with Kinetica
893  Kinetica kdb = new Kinetica( server_url, _ServerOptions );
894 
895  Console.WriteLine( "\n\n" );
896  Console.WriteLine( "Test Multihead Ingest: One column per type; 3 Primary Keys, No Shard Key" );
897  Console.WriteLine( "========================================================================" );
898  Console.WriteLine();
899 
900  // Create a type for our record_type_1 class
901  // Add some interesting properties for some of the data types
902  IDictionary<string, IList<string>> column_properties = new Dictionary<string, IList<string>>();
903 
904  // long primary key
905  List<string> l_props = new List<string>();
906  l_props.Add( ColumnProperty.PRIMARY_KEY );
907  column_properties.Add( "l", l_props );
908 
909  // date primary key
910  List<string> date_props = new List<string>();
911  date_props.Add( ColumnProperty.PRIMARY_KEY );
912  column_properties.Add( "date", date_props );
913 
914  // time primary key as well as shard
915  List<string> time_props = new List<string>();
916  time_props.Add( ColumnProperty.PRIMARY_KEY );
917  column_properties.Add( "time", time_props );
918 
919  // Create the KineticaType object which facilitates creating types in the database
920  KineticaType type1 = KineticaType.fromClass( typeof( record_type_all ), column_properties );
921 
922  // Create the type in the database
923  string type_id = type1.create( kdb );
924  //Console.WriteLine( "ID of the created type: " + type_id );
925  //Console.WriteLine();
926 
927  string table_name = "csharp_example_table_0s3pk";
928  // Clear any previously made table with the same name
929  Console.WriteLine( "Clearing any existing table named '{0}'", table_name );
930  try { kdb.clearTable( table_name, null ); } catch ( Exception ex ) { /* I don't care if the table doesn't already exists! */ }
931  Console.WriteLine();
932 
933  // Create a table of the given type
934  Console.WriteLine( $"Creating table named '{table_name}'" );
935  kdb.createTable( table_name, type_id );
936  Console.WriteLine();
937 
938  // Create the ingestor
939  int batch_size = 100;
940  KineticaIngestor<record_type_all> ingestor = new KineticaIngestor<record_type_all>( kdb, table_name, batch_size, type1 );
941 
942  // Generate data to be inserted
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 )
947  {
948  // Restricting string length to 256
949  int max_str_len = rng.Next( 0, 256 );
950  record_type_all record = new record_type_all()
951  {
952  i = rng.Next(),
953  i8 = rng.Next(),
954  i16 = rng.Next(),
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 ),
968  date = Test.generate_date( rng ),
969  datetime = Test.generate_datetime( rng ),
970  decimal_ = Test.generate_decimal( rng ),
971  ipv4 = Test.generate_IPv4( rng ),
972  time = Test.generate_time( rng ),
973  timestamp = (long) rng.Next()
974  };
975 
976  //Console.WriteLine( record.ToString() ); // debug~~~~~~~~
977  ingestor.insert( record );
978  } // end for loop
979 
980  Console.WriteLine( $"Generated {num_records} records." );
981 
982  // Flush the ingestor (which actually inserts the records)
983  Console.WriteLine( "\nFlushing any remaining records." );
984  ingestor.flush();
985  } // end test_all_types_3pk_0shard()
986 
987 
988 
994  public static string generate_date( Random rng )
995  {
996  int past_range = -90 * 365; //980 years
997  int future_range = 20 * 365; // 20 years
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 );
1001  } // end generate_date
1002 
1003 
1004 
1010  public static string generate_datetime( Random rng )
1011  {
1012  int past_range = -90 * 365; //980 years
1013  int future_range = 20 * 365; // 20 years
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);
1022 
1023  DateTime random_datetime = new DateTime( year, month, day,
1024  hour, minute, second, msecond );
1025 
1026  // We don't have to have any time component
1027  int time_chance_percent = 90;
1028  if (rng.Next(101) > time_chance_percent)
1029  return String.Format("{0:yyyy-MM-dd}", random_datetime);
1030  else
1031  {
1032  // Don't have to have the millisecond
1033  int num_ms_digits = rng.Next(7);
1034  switch (num_ms_digits)
1035  {
1036  case 0:
1037  return String.Format("{0:yyyy-MM-dd HH:mm:ss}", random_datetime);
1038  case 1:
1039  return String.Format("{0:yyyy-MM-dd HH:mm:ss.F}", random_datetime);
1040  case 2:
1041  return String.Format("{0:yyyy-MM-dd HH:mm:ss.FF}", random_datetime);
1042  case 3:
1043  return String.Format("{0:yyyy-MM-dd HH:mm:ss.FFF}", random_datetime);
1044  case 4:
1045  return String.Format("{0:yyyy-MM-dd HH:mm:ss.FFFF}", random_datetime);
1046  case 5:
1047  return String.Format("{0:yyyy-MM-dd HH:mm:ss.FFFFF}", random_datetime);
1048  case 6:
1049  default: // not necessary, but the stupid compiler complains
1050  return String.Format("{0:yyyy-MM-dd HH:mm:ss.FFFFFF}", random_datetime);
1051  }
1052  }
1053  } // end generate_datetime
1054 
1055 
1056 
1057  private static readonly string numbers = "0123456789";
1058 
1065  public static string generate_decimal( Random rng )
1066  {
1067  string sign = (rng.Next( 2 ) == 0) ? "-" : "";
1068  // Using up to 14 integral digits to keep things simple since the decimal
1069  // range is [-922337203685477.5808, 922337203685477.5807]
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 );
1073  } // end generate_decimal
1074 
1075 
1076 
1082  public static string generate_IPv4( Random rng )
1083  {
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();
1088  string dot = ".";
1089  return ( n1 + dot + n2 + dot + n3 + dot + n4 );
1090  } // end generate_ipv4
1091 
1092 
1093 
1099  public static string generate_time( Random rng )
1100  {
1101  int max_miliseconds = 86400000;
1102  DateTime time = DateTime.Today;
1103  //Console.WriteLine( time.ToLongTimeString() ); // debug~~~~~~~~
1104  time = time.Add( TimeSpan.FromMilliseconds( rng.Next( max_miliseconds ) ) );
1105  //Console.WriteLine( String.Format( "{0:HH}:{0:mm}:{0:ss}.{0:FFF}", time ) ); // debug~~~~~~
1106  string time_str;
1107  if ( (time.Millisecond > 0) && (rng.Next( 1, 6 ) > 3) ) // two in five will get the milliseconds
1108  time_str = String.Format( "{0:HH}:{0:mm}:{0:ss}.{0:FFF}", time );
1109  else
1110  time_str = String.Format( "{0:HH}:{0:mm}:{0:ss}", time );
1111  return time_str;
1112  } // end generate_time
1113 
1114 
1115  } // end class Test
1116 } // end namespace Test
1117 
1118 
1119 
1120 
1121 
1122 
1123 
1124 
1125 
1126 
1127 
1128 
1129 
1130 
1131 
1132 
Runs some tests on multihead ingestion.
Definition: Test.cs:36
A list of worker URLs to use for multi-head ingest.
Definition: WorkerList.cs:11
static string generate_decimal(Random rng)
Generate a random decimal value (up to 15 digits of precision and up to four digits of scale)...
Definition: Test.cs:1065
static string generate_time(Random rng)
Generate a random time of the format HH:MM:SS[.mmm].
Definition: Test.cs:1099
static string generate_date(Random rng)
Generate a random date.
Definition: Test.cs:994
static string generate_IPv4(Random rng)
Generate a random IPv4 address.
Definition: Test.cs:1082
static string generate_datetime(Random rng)
Generate a random datetime.
Definition: Test.cs:1010
Extension to string that has a truncate function.
Definition: Test.cs:19
Connection Options
Definition: Kinetica.cs:50
static string Truncate(this string value, int maxLength)
Definition: Test.cs:21
API to talk to Kinetica Database
Definition: Kinetica.cs:40