Kinetica   C#   API  Version 7.2.3.1
TypeManagementTests.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using Xunit;
4 using Kinetica.Tests.Common;
5 using kinetica;
6 
8 {
13  [Trait("Category", "Integration")]
14  public class TypeManagementTests
15  {
16  [Fact]
17  public void TestCreateTypeBasic()
18  {
19  using var ctx = new TestContext("type_basic");
20 
21  var typeDef = @"{""type"":""record"",""name"":""simple"",""fields"":[{""name"":""id"",""type"":""int""},{""name"":""name"",""type"":""string""}]}";
22 
23  var resp = ctx.Kinetica.createType(typeDef, "simple_type", new Dictionary<string, IList<string>>(), new Dictionary<string, string>());
24 
25  Assert.False(string.IsNullOrEmpty(resp.type_id));
26  Assert.Equal("simple_type", resp.label);
27  }
28 
29  [Fact]
31  {
32  using var ctx = new TestContext("type_pk");
33 
34  var typeDef = @"{""type"":""record"",""name"":""pk_type"",""fields"":[{""name"":""id"",""type"":""int""},{""name"":""value"",""type"":""double""}]}";
35 
36  var properties = new Dictionary<string, IList<string>>
37  {
38  { "id", new List<string> { "int", "primary_key" } }
39  };
40 
41  var resp = ctx.Kinetica.createType(typeDef, "pk_type", properties, new Dictionary<string, string>());
42 
43  Assert.False(string.IsNullOrEmpty(resp.type_id));
44  }
45 
46  [Fact]
48  {
49  using var ctx = new TestContext("type_props");
50 
51  var typeDef = @"{""type"":""record"",""name"":""multi_props"",""fields"":[{""name"":""id"",""type"":""int""},{""name"":""x"",""type"":""double""},{""name"":""name"",""type"":""string""}]}";
52 
53  var properties = new Dictionary<string, IList<string>>
54  {
55  { "id", new List<string> { "int", "primary_key" } },
56  { "x", new List<string> { "data" } },
57  { "name", new List<string> { "char32" } }
58  };
59 
60  var resp = ctx.Kinetica.createType(typeDef, "multi_prop_type", properties, new Dictionary<string, string>());
61 
62  Assert.False(string.IsNullOrEmpty(resp.type_id));
63  }
64 
65  [Fact]
67  {
68  using var ctx = new TestContext("type_complex");
69 
70  var typeDef = @"{""type"":""record"",""name"":""complex_type"",""fields"":[{""name"":""id"",""type"":""int""},{""name"":""timestamp"",""type"":""long""},{""name"":""value"",""type"":""double""},{""name"":""name"",""type"":""string""},{""name"":""active"",""type"":""int""},{""name"":""score"",""type"":""float""}]}";
71 
72  var properties = new Dictionary<string, IList<string>>
73  {
74  { "id", new List<string> { "int", "primary_key" } }
75  };
76 
77  var resp = ctx.Kinetica.createType(typeDef, "complex_type", properties, new Dictionary<string, string>());
78 
79  Assert.False(string.IsNullOrEmpty(resp.type_id));
80  }
81 
82  [Fact]
83  public void TestHasTypeExists()
84  {
85  using var ctx = new TestContext("has_type_exists");
86 
87  // Create a type first
88  var typeDef = @"{""type"":""record"",""name"":""test"",""fields"":[{""name"":""id"",""type"":""int""}]}";
89  var createResp = ctx.Kinetica.createType(typeDef, "test_type", new Dictionary<string, IList<string>>(), new Dictionary<string, string>());
90 
91  // Check it exists
92  var hasResp = ctx.Kinetica.hasType(createResp.type_id, new Dictionary<string, string>());
93 
94  Assert.True(hasResp.type_exists);
95  }
96 
97  [Fact]
98  public void TestHasTypeNotExists()
99  {
100  using var ctx = new TestContext("has_type_not");
101 
102  var hasResp = ctx.Kinetica.hasType("nonexistent_type_12345", new Dictionary<string, string>());
103 
104  Assert.False(hasResp.type_exists);
105  }
106 
107  [Fact]
109  {
110  using var ctx = new TestContext("type_string");
111 
112  // Simple type with string field (strings are nullable by default in Kinetica)
113  var typeDef = @"{""type"":""record"",""name"":""string_type"",""fields"":[{""name"":""id"",""type"":""int""},{""name"":""name"",""type"":""string""}]}";
114 
115  var resp = ctx.Kinetica.createType(typeDef, "string_type", new Dictionary<string, IList<string>>(), new Dictionary<string, string>());
116 
117  Assert.False(string.IsNullOrEmpty(resp.type_id));
118  }
119  }
120 }
Tests for type management endpoints (create_type, has_type).
Test context that manages schema and cleanup for integration tests.
Definition: TestContext.cs:11