22 [Trait(
"Category",
"WireFormat")]
23 [Trait(
"Category",
"Protocol")]
26 #region RecordKey Wire Format Tests 37 .GetType(
"kinetica.Utils.RecordKey");
38 var recordKey = Activator.CreateInstance(recordKeyType, 4);
40 var addIntMethod = recordKeyType.GetMethod(
"addInt");
41 addIntMethod!.Invoke(recordKey,
new object[] { 12345 });
44 var bufferField = recordKeyType.GetField(
"buffer",
45 System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
46 var buffer = (
byte[])bufferField!.GetValue(recordKey)!;
50 byte[] expected = { 0x39, 0x30, 0x00, 0x00 };
51 Assert.Equal(expected, buffer);
63 .GetType(
"kinetica.Utils.RecordKey");
64 var recordKey = Activator.CreateInstance(recordKeyType, 8);
66 var addCharNMethod = recordKeyType.GetMethod(
"addCharN");
67 addCharNMethod!.Invoke(recordKey,
new object[] {
"ABCD", 8 });
70 var bufferField = recordKeyType.GetField(
"buffer",
71 System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
72 var buffer = (
byte[])bufferField!.GetValue(recordKey)!;
75 byte[] expected = { 0x00, 0x00, 0x00, 0x00, 0x44, 0x43, 0x42, 0x41 };
76 Assert.Equal(expected, buffer);
87 .GetType(
"kinetica.Utils.RecordKey");
88 var recordKey = Activator.CreateInstance(recordKeyType, 8);
90 var addLongMethod = recordKeyType.GetMethod(
"addLong");
91 addLongMethod!.Invoke(recordKey,
new object[] { 9876543210L });
94 var bufferField = recordKeyType.GetField(
"buffer",
95 System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
96 var buffer = (
byte[])bufferField!.GetValue(recordKey)!;
99 byte[] expected = { 234, 22, 176, 76, 2, 0, 0, 0 };
100 Assert.Equal(expected, buffer);
112 .GetType(
"kinetica.Utils.RecordKey");
113 var recordKey = Activator.CreateInstance(recordKeyType, 8);
115 var addDecimalMethod = recordKeyType.GetMethod(
"addDecimal",
116 new[] { typeof(
string), typeof(
int), typeof(
int) });
117 addDecimalMethod!.Invoke(recordKey,
new object[] {
"123.4567", 18, 4 });
120 var bufferField = recordKeyType.GetField(
"buffer",
121 System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
122 var buffer = (
byte[])bufferField!.GetValue(recordKey)!;
126 long expected = 1234567L;
127 long actual = BitConverter.ToInt64(buffer, 0);
128 Assert.Equal(expected, actual);
139 .GetType(
"kinetica.Utils.RecordKey");
140 var recordKey = Activator.CreateInstance(recordKeyType, 12);
142 var addDecimalMethod = recordKeyType.GetMethod(
"addDecimal",
143 new[] { typeof(
string), typeof(
int), typeof(
int) });
145 addDecimalMethod!.Invoke(recordKey,
new object[] {
"12345678901234567890.123456", 38, 6 });
148 var bufferField = recordKeyType.GetField(
"buffer",
149 System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
150 var buffer = (
byte[])bufferField!.GetValue(recordKey)!;
151 var currentSizeField = recordKeyType.GetField(
"current_size",
152 System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
153 var size = (int)currentSizeField!.GetValue(recordKey)!;
156 Assert.Equal(12, size);
159 bool hasNonZero = buffer.Any(b => b != 0);
160 Assert.True(hasNonZero,
"12-byte decimal buffer should contain non-zero bytes");
165 #region Type Schema Encoding Tests 175 string schemaJson =
@"{ 176 ""type"": ""record"", 177 ""name"": ""TestRecord"", 179 {""name"": ""id"", ""type"": ""int""}, 180 {""name"": ""name"", ""type"": ""string""} 190 Assert.Contains(
"\"type\":\"record\"", generatedSchema.Replace(
" ",
""));
191 Assert.Contains(
"\"name\":\"TestRecord\"", generatedSchema.Replace(
" ",
""));
192 Assert.Contains(
"\"fields\"", generatedSchema);
193 Assert.Contains(
"\"id\"", generatedSchema);
194 Assert.Contains(
"\"name\"", generatedSchema);
204 string schemaJson =
@"{ 205 ""type"": ""record"", 206 ""name"": ""NullableTest"", 208 {""name"": ""optional_int"", ""type"": [""null"", ""int""]} 218 Assert.Contains(
"[\"null\",\"int\"]", generatedSchema.Replace(
" ",
""));
223 #region Column Property Encoding Tests 243 #region Compression Tests 254 string originalText =
"Hello, Kinetica! This is a test of compression. " +
255 "The data should compress well due to repetition. " +
256 "The data should compress well due to repetition.";
257 byte[] originalBytes = Encoding.UTF8.GetBytes(originalText);
260 byte[] compressed = Snappier.Snappy.CompressToArray(originalBytes);
261 byte[] decompressed = Snappier.Snappy.DecompressToArray(compressed);
264 Assert.Equal(originalBytes, decompressed);
267 Assert.True(compressed.Length < originalBytes.Length,
268 $
"Compressed size ({compressed.Length}) should be less than original ({originalBytes.Length})");
273 #region Regression Tests 279 [Fact(Skip =
"KineticaType does not support empty schemas - requires at least one field")]
283 string schemaJson =
@"{ 284 ""type"": ""record"", 285 ""name"": ""EmptyRecord"", 297 Assert.NotNull(recordSchema);
298 Assert.Empty(recordSchema!.Fields);
310 .GetType(
"kinetica.Utils.RecordKey");
311 var recordKey = Activator.CreateInstance(recordKeyType, 12);
313 var addIntMethod = recordKeyType.GetMethod(
"addInt");
314 var addCharNMethod = recordKeyType.GetMethod(
"addCharN");
317 addIntMethod!.Invoke(recordKey,
new object[] { 999 });
318 addCharNMethod!.Invoke(recordKey,
new object[] {
"KEY", 8 });
321 var bufferField = recordKeyType.GetField(
"buffer",
322 System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
323 var buffer = (
byte[])bufferField!.GetValue(recordKey)!;
327 Assert.Equal(0xE7, buffer[0]);
328 Assert.Equal(0x03, buffer[1]);
329 Assert.Equal(0x00, buffer[2]);
330 Assert.Equal(0x00, buffer[3]);
333 Assert.Equal(0x00, buffer[4]);
334 Assert.Equal(0x00, buffer[5]);
335 Assert.Equal(0x00, buffer[6]);
336 Assert.Equal(0x00, buffer[7]);
337 Assert.Equal(0x00, buffer[8]);
338 Assert.Equal((
byte)
'Y', buffer[9]);
339 Assert.Equal((
byte)
'E', buffer[10]);
340 Assert.Equal((
byte)
'K', buffer[11]);
const string PRIMARY_KEY
This property indicates that this column will be part of (or the entire) primary key.
Column properties used for Kinetica types.
const string TIMESTAMP
Valid only for 'long' columns.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
const string SHARD_KEY
This property indicates that this column will be part of (or the entire) shard key.
const string DICT
This property indicates that this column should be dictionary encoded.
const string NULLABLE
This property indicates that this column is nullable.
API to talk to Kinetica Database