Kinetica   C#   API  Version 7.2.3.1
BooleanTypeTests.cs
Go to the documentation of this file.
1 using System;
2 using Xunit;
3 using kinetica;
4 
5 namespace Kinetica.Tests
6 {
10  [Trait("Category", "Integration")]
11  public class BooleanTypeTests
12  {
13  private const string ConnectionUrl = "http://localhost:9191";
14  private const string Username = "admin";
15  private const string Password = "secret";
16  private const string TestTableName = "bool_type_test";
17 
18  [Fact]
20  {
21  var kdb = new kinetica.Kinetica(ConnectionUrl, new kinetica.Kinetica.Options()
22  {
23  Username = Username,
24  Password = Password
25  });
26 
27  try
28  {
29  // Setup
30  try { kdb.executeSql($"DROP TABLE IF EXISTS {TestTableName}"); } catch { }
31  kdb.executeSql($"CREATE TABLE {TestTableName} (id INT, active BOOLEAN, PRIMARY KEY(id))");
32  kdb.executeSql($"INSERT INTO {TestTableName} VALUES (1, TRUE), (2, FALSE)");
33 
34  // Query
35  var response = kdb.executeSql($"SELECT * FROM {TestTableName} ORDER BY id");
36 
37  // Assert
38  Assert.Equal(2, response.total_number_of_records);
39  Assert.Equal(2, response.data.Count);
40 
41  // Check first record (id=1, active=TRUE)
42  var record1 = response.data[0];
43  Assert.True(record1.TryGetValue("id", out var id1));
44  Assert.True(record1.TryGetValue("active", out var active1));
45 
46  // Boolean columns are stored as integers (0 or 1)
47  Assert.Equal(1, Convert.ToInt32(id1));
48  Assert.Equal(1, Convert.ToInt32(active1)); // TRUE = 1
49  Assert.True(Convert.ToBoolean(active1)); // Should convert correctly
50 
51  // Check second record (id=2, active=FALSE)
52  var record2 = response.data[1];
53  Assert.True(record2.TryGetValue("id", out var id2));
54  Assert.True(record2.TryGetValue("active", out var active2));
55 
56  Assert.Equal(2, Convert.ToInt32(id2));
57  Assert.Equal(0, Convert.ToInt32(active2)); // FALSE = 0
58  Assert.False(Convert.ToBoolean(active2)); // Should convert correctly
59  }
60  finally
61  {
62  try { kdb.executeSql($"DROP TABLE IF EXISTS {TestTableName}"); } catch { }
63  }
64  }
65 
66  [Fact]
68  {
69  var kdb = new kinetica.Kinetica(ConnectionUrl, new kinetica.Kinetica.Options()
70  {
71  Username = Username,
72  Password = Password
73  });
74 
75  try
76  {
77  // Setup
78  try { kdb.executeSql($"DROP TABLE IF EXISTS {TestTableName}"); } catch { }
79  kdb.executeSql($"CREATE TABLE {TestTableName} (id INT, active BOOLEAN, PRIMARY KEY(id))");
80 
81  // Get type info
82  var ktype = KineticaType.fromTable(kdb, TestTableName);
83 
84  // Find the 'active' column
85  KineticaType.Column? activeColumn = null;
86  foreach (var col in ktype.getColumns())
87  {
88  if (col.getName() == "active")
89  {
90  activeColumn = col;
91  break;
92  }
93  }
94 
95  Assert.NotNull(activeColumn);
96 
97  // Check that it's an INT type
98  Assert.Equal(KineticaType.Column.ColumnType.INT, activeColumn.getType());
99 
100  // Check that it has the "boolean" property
101  var props = activeColumn.getProperties();
102  Assert.Contains(ColumnProperty.BOOLEAN, props);
103  }
104  finally
105  {
106  try { kdb.executeSql($"DROP TABLE IF EXISTS {TestTableName}"); } catch { }
107  }
108  }
109  }
110 }
const string BOOLEAN
This property provides optimized memory and query performance for int columns.
ExecuteSqlResponse executeSql(ExecuteSqlRequest request_)
Execute a SQL statement (query, DML, or DDL).
Column properties used for Kinetica types.
static KineticaType fromTable(Kinetica kinetica, string tableName)
Create a KineticaType object based on an existing table in the database.
IList< KineticaRecord > data
Avro binary encoded response.
Definition: ExecuteSql.cs:1613
Tests for boolean type handling in Kinetica.
IList< string > getProperties()
Returns the properties for the column.
Definition: KineticaType.cs:67
Connection Options
Definition: Kinetica.cs:50
API to talk to Kinetica Database
Definition: Kinetica.cs:40