2 using System.Collections.Generic;
13 [Trait(
"Category",
"Integration")]
16 private const string ConnectionUrl =
"http://localhost:9191";
17 private const string Username =
"admin";
18 private const string Password =
"secret";
34 #region Boolean Type Tests 39 var kdb = GetConnection();
40 const string tableName =
"bool_type_test";
44 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
45 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, active BOOLEAN, PRIMARY KEY(id))");
46 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, TRUE), (2, FALSE)");
48 var response = kdb.executeSql($
"SELECT * FROM {tableName} ORDER BY id");
50 Assert.Equal(2, response.total_number_of_records);
52 var record1 = response.data[0];
53 record1.TryGetValue(
"active", out var active1);
54 Assert.Equal(1, Convert.ToInt32(active1));
55 Assert.True(Convert.ToBoolean(active1));
57 var record2 = response.data[1];
58 record2.TryGetValue(
"active", out var active2);
59 Assert.Equal(0, Convert.ToInt32(active2));
60 Assert.False(Convert.ToBoolean(active2));
64 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
70 #region Array Type Tests 75 var kdb = GetConnection();
76 const string tableName =
"array_int_test";
80 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
82 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, int_values INTEGER[5], PRIMARY KEY(id))");
84 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, '[1, 2, 3, 4, 5]')");
86 var response = kdb.executeSql($
"SELECT * FROM {tableName}");
88 Assert.Equal(1, response.total_number_of_records);
90 var record = response.data[0];
91 record.TryGetValue(
"int_values", out var valuesObj);
94 var valuesStr = valuesObj?.ToString();
95 Assert.NotNull(valuesStr);
98 var values = JsonConvert.DeserializeObject<
int[]>(valuesStr!);
99 Assert.NotNull(values);
100 Assert.Equal(5, values!.Length);
101 Assert.Equal(
new[] { 1, 2, 3, 4, 5 }, values);
105 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
112 var kdb = GetConnection();
113 const string tableName =
"array_double_test";
117 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
119 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, double_values DOUBLE[3], PRIMARY KEY(id))");
121 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, '[1.1, 2.2, 3.3]')");
123 var response = kdb.executeSql($
"SELECT * FROM {tableName}");
125 Assert.Equal(1, response.total_number_of_records);
127 var record = response.data[0];
128 record.TryGetValue(
"double_values", out var valuesObj);
130 var valuesStr = valuesObj?.ToString();
131 Assert.NotNull(valuesStr);
133 var values = JsonConvert.DeserializeObject<
double[]>(valuesStr!);
134 Assert.NotNull(values);
135 Assert.Equal(3, values!.Length);
136 Assert.Equal(1.1, values[0], 5);
137 Assert.Equal(2.2, values[1], 5);
138 Assert.Equal(3.3, values[2], 5);
142 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
146 [Fact(Skip =
"VARCHAR arrays require specific Kinetica version support - test with CHAR16 instead")]
149 var kdb = GetConnection();
150 const string tableName =
"array_string_test";
154 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
157 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, str_tags CHAR16[3], PRIMARY KEY(id))");
159 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, '[\"red\", \"green\", \"blue\"]')");
161 var response = kdb.executeSql($
"SELECT * FROM {tableName}");
163 Assert.Equal(1, response.total_number_of_records);
165 var record = response.data[0];
166 record.TryGetValue(
"str_tags", out var tagsObj);
168 var tagsStr = tagsObj?.ToString();
169 Assert.NotNull(tagsStr);
171 var tags = JsonConvert.DeserializeObject<
string[]>(tagsStr!);
172 Assert.NotNull(tags);
173 Assert.Equal(3, tags!.Length);
175 var trimmedTags = tags!.Select(t => t?.Trim()).ToArray();
176 Assert.Equal(
new[] {
"red",
"green",
"blue" }, trimmedTags);
180 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
186 #region Decimal Type Tests 191 var kdb = GetConnection();
192 const string tableName =
"decimal_8byte_test";
196 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
198 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, amount DECIMAL(18,4), PRIMARY KEY(id))");
199 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, 12345.6789)");
201 var response = kdb.executeSql($
"SELECT * FROM {tableName}");
203 Assert.Equal(1, response.total_number_of_records);
205 var record = response.data[0];
206 record.TryGetValue(
"amount", out var amountObj);
209 var amountStr = amountObj?.ToString();
210 Assert.NotNull(amountStr);
212 var amount = decimal.Parse(amountStr!);
214 Assert.Equal(12345.6789m, amount);
218 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
225 var kdb = GetConnection();
226 const string tableName =
"decimal_8byte_custom_test";
230 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
232 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, price DECIMAL(10,2), PRIMARY KEY(id))");
233 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, 99999999.99)");
235 var response = kdb.executeSql($
"SELECT * FROM {tableName}");
237 Assert.Equal(1, response.total_number_of_records);
239 var record = response.data[0];
240 record.TryGetValue(
"price", out var priceObj);
242 var priceStr = priceObj?.ToString();
243 Assert.NotNull(priceStr);
245 var price = decimal.Parse(priceStr!);
246 Assert.Equal(99999999.99m, price);
250 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
257 var kdb = GetConnection();
258 const string tableName =
"decimal_12byte_test";
262 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
264 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, big_amount DECIMAL(26,13), PRIMARY KEY(id))");
265 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, 1234567890123.1234567890123)");
267 var response = kdb.executeSql($
"SELECT * FROM {tableName}");
269 Assert.Equal(1, response.total_number_of_records);
271 var record = response.data[0];
272 record.TryGetValue(
"big_amount", out var amountObj);
274 var amountStr = amountObj?.ToString();
275 Assert.NotNull(amountStr);
277 var amount = decimal.Parse(amountStr!);
279 Assert.True(Math.Abs(amount - 1234567890123.1234567890123m) < 0.0000000001m);
283 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
290 var kdb = GetConnection();
291 const string tableName =
"decimal_12byte_max_test";
295 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
297 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, big_val DECIMAL(26,13), PRIMARY KEY(id))");
298 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, 9999999999999.9999999999999)");
300 var response = kdb.executeSql($
"SELECT * FROM {tableName}");
302 Assert.Equal(1, response.total_number_of_records);
304 var record = response.data[0];
305 record.TryGetValue(
"big_val", out var valObj);
307 var valStr = valObj?.ToString();
308 Assert.NotNull(valStr);
310 var val = decimal.Parse(valStr!);
311 Assert.True(Math.Abs(val - 9999999999999.9999999999999m) < 0.0000000001m);
315 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
322 var kdb = GetConnection();
323 const string tableName =
"decimal_12byte_neg_test";
327 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
329 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, neg_val DECIMAL(26,13), PRIMARY KEY(id))");
330 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, -1234567890123.1234567890123)");
332 var response = kdb.executeSql($
"SELECT * FROM {tableName}");
334 Assert.Equal(1, response.total_number_of_records);
336 var record = response.data[0];
337 record.TryGetValue(
"neg_val", out var valObj);
339 var valStr = valObj?.ToString();
340 Assert.NotNull(valStr);
342 var val = decimal.Parse(valStr!);
343 Assert.True(Math.Abs(val - (-1234567890123.1234567890123m)) < 0.0000000001m);
347 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
354 var kdb = GetConnection();
355 const string tableName =
"decimal_typeinfo_test";
359 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
361 kdb.executeSql($
@"CREATE TABLE {tableName} ( 363 small_decimal DECIMAL(10,2), 364 default_decimal DECIMAL(18,4), 365 big_decimal DECIMAL(26,13), 372 var smallDecCol = columns.FirstOrDefault(c => c.getName() ==
"small_decimal");
373 Assert.NotNull(smallDecCol);
374 Assert.True(smallDecCol!.isDecimal());
375 Assert.Equal(10, smallDecCol.getDecimalPrecision());
376 Assert.Equal(2, smallDecCol.getDecimalScale());
377 Assert.Equal(8, smallDecCol.getDecimalByteSize());
380 var defaultDecCol = columns.FirstOrDefault(c => c.getName() ==
"default_decimal");
381 Assert.NotNull(defaultDecCol);
382 Assert.True(defaultDecCol!.isDecimal());
383 Assert.Equal(18, defaultDecCol.getDecimalPrecision());
384 Assert.Equal(4, defaultDecCol.getDecimalScale());
385 Assert.Equal(8, defaultDecCol.getDecimalByteSize());
388 var bigDecCol = columns.FirstOrDefault(c => c.getName() ==
"big_decimal");
389 Assert.NotNull(bigDecCol);
390 Assert.True(bigDecCol!.isDecimal());
391 Assert.Equal(26, bigDecCol.getDecimalPrecision());
392 Assert.Equal(13, bigDecCol.getDecimalScale());
393 Assert.Equal(12, bigDecCol.getDecimalByteSize());
397 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
412 #region WKT Geometry Type Tests 417 var kdb = GetConnection();
418 const string tableName =
"wkt_point_test";
422 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
423 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, location GEOMETRY, PRIMARY KEY(id))");
424 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, ST_GEOMFROMTEXT('POINT(-122.4194 37.7749)'))");
426 var response = kdb.executeSql($
"SELECT id, ST_ASTEXT(location) as location_wkt FROM {tableName}");
428 Assert.Equal(1, response.total_number_of_records);
430 var record = response.data[0];
431 record.TryGetValue(
"location_wkt", out var wktObj);
433 var wkt = wktObj?.ToString();
435 Assert.Contains(
"POINT", wkt!, StringComparison.OrdinalIgnoreCase);
436 Assert.Contains(
"-122.4194", wkt!);
437 Assert.Contains(
"37.7749", wkt!);
441 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
448 var kdb = GetConnection();
449 const string tableName =
"wkt_polygon_test";
453 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
454 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, boundary GEOMETRY, PRIMARY KEY(id))");
455 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, ST_GEOMFROMTEXT('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'))");
457 var response = kdb.executeSql($
"SELECT id, ST_ASTEXT(boundary) as boundary_wkt FROM {tableName}");
459 Assert.Equal(1, response.total_number_of_records);
461 var record = response.data[0];
462 record.TryGetValue(
"boundary_wkt", out var wktObj);
464 var wkt = wktObj?.ToString();
466 Assert.Contains(
"POLYGON", wkt!, StringComparison.OrdinalIgnoreCase);
470 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
476 #region UUID Type Tests 481 var kdb = GetConnection();
482 const string tableName =
"uuid_test";
486 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
487 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, uuid_val UUID, PRIMARY KEY(id))");
488 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, '550e8400-e29b-41d4-a716-446655440000')");
490 var response = kdb.executeSql($
"SELECT * FROM {tableName}");
492 Assert.Equal(1, response.total_number_of_records);
494 var record = response.data[0];
495 record.TryGetValue(
"uuid_val", out var uuidObj);
497 var uuidStr = uuidObj?.ToString();
498 Assert.NotNull(uuidStr);
500 var uuid = Guid.Parse(uuidStr!);
501 Assert.Equal(Guid.Parse(
"550e8400-e29b-41d4-a716-446655440000"), uuid);
505 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
511 #region JSON Type Tests 516 var kdb = GetConnection();
517 const string tableName =
"json_test";
521 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
522 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, data JSON, PRIMARY KEY(id))");
523 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, '{{\"name\": \"John\", \"age\": 30}}')");
525 var response = kdb.executeSql($
"SELECT * FROM {tableName}");
527 Assert.Equal(1, response.total_number_of_records);
529 var record = response.data[0];
530 record.TryGetValue(
"data", out var dataObj);
532 var jsonStr = dataObj?.ToString();
533 Assert.NotNull(jsonStr);
535 dynamic? json = JsonConvert.DeserializeObject(jsonStr!);
536 Assert.NotNull(json);
537 Assert.Equal(
"John", (
string)json!.name);
538 Assert.Equal(30, (
int)json!.age);
542 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
548 #region ULONG Type Tests 553 var kdb = GetConnection();
554 const string tableName =
"ulong_test";
558 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
560 kdb.executeSql($
"CREATE TABLE {tableName} (id INT, big_val UNSIGNED BIGINT, PRIMARY KEY(id))");
561 kdb.executeSql($
"INSERT INTO {tableName} VALUES (1, 18446744073709551615)");
563 var response = kdb.executeSql($
"SELECT * FROM {tableName}");
565 Assert.Equal(1, response.total_number_of_records);
567 var record = response.data[0];
568 record.TryGetValue(
"big_val", out var valObj);
570 var valStr = valObj?.ToString();
571 Assert.NotNull(valStr);
573 var val = ulong.Parse(valStr!);
574 Assert.Equal(ulong.MaxValue, val);
578 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
584 #region Type Information Tests 589 var kdb = GetConnection();
590 const string tableName =
"type_info_test";
594 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
597 CREATE TABLE {tableName} ( 611 var boolCol = columns.FirstOrDefault(c => c.getName() ==
"is_active");
612 Assert.NotNull(boolCol);
617 var decimalCol = columns.FirstOrDefault(c => c.getName() ==
"score");
618 Assert.NotNull(decimalCol);
620 Assert.Contains(decimalCol.getProperties(), p => p.StartsWith(
"decimal", StringComparison.OrdinalIgnoreCase));
623 var arrayCol = columns.FirstOrDefault(c => c.getName() ==
"int_tags");
624 Assert.NotNull(arrayCol);
626 Assert.Contains(arrayCol.getProperties(), p => p.StartsWith(
"array", StringComparison.OrdinalIgnoreCase));
629 var jsonCol = columns.FirstOrDefault(c => c.getName() ==
"metadata");
630 Assert.NotNull(jsonCol);
635 var uuidCol = columns.FirstOrDefault(c => c.getName() ==
"unique_id");
636 Assert.NotNull(uuidCol);
642 try { kdb.executeSql($
"DROP TABLE IF EXISTS {tableName}"); }
catch { }
void WKT_Polygon_ReadsCorrectly()
void WKT_Point_ReadsCorrectly()
const string BOOLEAN
This property provides optimized memory and query performance for int columns.
void Array_DoubleArray_ReadsCorrectly()
void TypeFromTable_CorrectlyIdentifiesColumnTypes()
Column properties used for Kinetica types.
const string JSON
Valid only for 'string' columns.
void JSON_ReadsCorrectly()
void Array_StringArray_ReadsCorrectly()
void Decimal_ColumnConstants_AreCorrect()
static KineticaType fromTable(Kinetica kinetica, string tableName)
Create a KineticaType object based on an existing table in the database.
void ULONG_ReadsCorrectly()
void Decimal_8Byte_DefaultPrecision_ReadsCorrectly()
void UUID_ReadsCorrectly()
IList< Column > getColumns()
void Boolean_StoredAsInteger_ReadsCorrectly()
void Decimal_8Byte_CustomPrecisionScale_ReadsCorrectly()
void Decimal_12Byte_NearMaxValue_ReadsCorrectly()
void Decimal_12Byte_NegativeValue_ReadsCorrectly()
const string UUID
Valid only for 'string' columns.
Tests for various data type handling in Kinetica.
void Decimal_12Byte_HighPrecision_ReadsCorrectly()
void Array_IntegerArray_ReadsCorrectly()
void Decimal_TypeFromTable_ExtractsPrecisionAndScale()
API to talk to Kinetica Database