Kinetica   C#   API  Version 7.2.3.1
AsyncBooleanTypeTests.cs
Go to the documentation of this file.
1 using System;
2 using System.Threading.Tasks;
3 using Xunit;
5 using kinetica;
6 
8 {
12  [Trait("Category", "Integration")]
13  [Trait("Category", "Async")]
14  public class AsyncBooleanTypeTests
15  {
16  [Fact]
18  {
19  using var ctx = new TestContext("async_bool_stored");
20  var tableName = ctx.QualifiedTable("bool_type_test");
21 
22  // Setup
23  await ctx.Kinetica.ExecuteSqlAsync($"CREATE TABLE {tableName} (id INT, active BOOLEAN, PRIMARY KEY(id))");
24  await ctx.Kinetica.ExecuteSqlAsync($"INSERT INTO {tableName} VALUES (1, TRUE), (2, FALSE)");
25 
26  // Query
27  var response = await ctx.Kinetica.ExecuteSqlAsync($"SELECT * FROM {tableName} ORDER BY id");
28 
29  // Assert
30  Assert.Equal(2, response.total_number_of_records);
31  Assert.Equal(2, response.data.Count);
32 
33  // Check first record (id=1, active=TRUE)
34  var record1 = response.data[0];
35  Assert.True(record1.TryGetValue("id", out var id1));
36  Assert.True(record1.TryGetValue("active", out var active1));
37 
38  // Boolean columns are stored as integers (0 or 1)
39  Assert.Equal(1, Convert.ToInt32(id1));
40  Assert.Equal(1, Convert.ToInt32(active1)); // TRUE = 1
41  Assert.True(Convert.ToBoolean(active1)); // Should convert correctly
42 
43  // Check second record (id=2, active=FALSE)
44  var record2 = response.data[1];
45  Assert.True(record2.TryGetValue("id", out var id2));
46  Assert.True(record2.TryGetValue("active", out var active2));
47 
48  Assert.Equal(2, Convert.ToInt32(id2));
49  Assert.Equal(0, Convert.ToInt32(active2)); // FALSE = 0
50  Assert.False(Convert.ToBoolean(active2)); // Should convert correctly
51  }
52 
53  [Fact]
55  {
56  using var ctx = new TestContext("async_bool_typeinfo");
57  var tableName = ctx.QualifiedTable("bool_type_test");
58 
59  // Setup
60  await ctx.Kinetica.ExecuteSqlAsync($"CREATE TABLE {tableName} (id INT, active BOOLEAN, PRIMARY KEY(id))");
61 
62  // Get type info
63  var ktype = KineticaType.fromTable(ctx.Kinetica, tableName);
64 
65  // Find the 'active' column
66  KineticaType.Column? activeColumn = null;
67  foreach (var col in ktype.getColumns())
68  {
69  if (col.getName() == "active")
70  {
71  activeColumn = col;
72  break;
73  }
74  }
75 
76  Assert.NotNull(activeColumn);
77 
78  // Check that it's an INT type
79  Assert.Equal(KineticaType.Column.ColumnType.INT, activeColumn.getType());
80 
81  // Check that it has the "boolean" property
82  var props = activeColumn.getProperties();
83  Assert.Contains(ColumnProperty.BOOLEAN, props);
84  }
85  }
86 }
const string BOOLEAN
This property provides optimized memory and query performance for int columns.
Test context that manages schema and cleanup for integration tests.
Definition: TestContext.cs:11
Column properties used for Kinetica types.
Async tests for boolean type handling in Kinetica.
static KineticaType fromTable(Kinetica kinetica, string tableName)
Create a KineticaType object based on an existing table in the database.
IList< string > getProperties()
Returns the properties for the column.
Definition: KineticaType.cs:67