2 using System.Reflection;
27 [Trait(
"Category",
"WireFormat")]
28 [Trait(
"Category",
"RecordKey")]
33 .GetType(
"kinetica.Utils.RecordKey");
38 private object CreateRecordKey(
int bufferSize)
40 return Activator.CreateInstance(RecordKeyType, bufferSize)!;
46 private void InvokeAddDecimal(
object key,
string value,
int precision,
int scale)
48 var method = RecordKeyType.GetMethod(
"addDecimal",
new[] { typeof(
string), typeof(
int), typeof(
int) });
49 method!.Invoke(key,
new object[] { value, precision, scale });
55 private byte[] GetBuffer(
object key)
57 var field = RecordKeyType.GetField(
"buffer", BindingFlags.NonPublic | BindingFlags.Instance);
58 return (
byte[])field!.GetValue(key)!;
64 private int GetCurrentSize(
object key)
66 var field = RecordKeyType.GetField(
"current_size", BindingFlags.NonPublic | BindingFlags.Instance);
67 return (
int)field!.GetValue(key)!;
83 var key = CreateRecordKey(8);
86 InvokeAddDecimal(key,
"123.45", 18, 4);
89 var buffer = GetBuffer(key);
90 Assert.Equal(8, GetCurrentSize(key));
93 long expected = 1234500L;
94 long actual = BitConverter.ToInt64(buffer, 0);
95 Assert.Equal(expected, actual);
111 var key = CreateRecordKey(8);
114 InvokeAddDecimal(key,
"-987.6543", 18, 4);
117 var buffer = GetBuffer(key);
118 Assert.Equal(8, GetCurrentSize(key));
121 long expected = -9876543L;
122 long actual = BitConverter.ToInt64(buffer, 0);
123 Assert.Equal(expected, actual);
130 var key = CreateRecordKey(8);
133 InvokeAddDecimal(key,
null!, 18, 4);
136 var buffer = GetBuffer(key);
137 Assert.Equal(8, GetCurrentSize(key));
138 Assert.Equal(0L, BitConverter.ToInt64(buffer, 0));
145 var key = CreateRecordKey(12);
148 InvokeAddDecimal(key,
"12345.678901", 38, 10);
151 var buffer = GetBuffer(key);
152 Assert.Equal(12, GetCurrentSize(key));
155 bool hasNonZero =
false;
156 for (
int i = 0; i < 12; i++)
164 Assert.True(hasNonZero,
"12-byte decimal should have non-zero content");
171 var key = CreateRecordKey(12);
174 InvokeAddDecimal(key,
"", 38, 10);
177 var buffer = GetBuffer(key);
178 Assert.Equal(12, GetCurrentSize(key));
180 for (
int i = 0; i < 12; i++)
182 Assert.Equal(0, buffer[i]);
190 var key = CreateRecordKey(12);
193 InvokeAddDecimal(key,
"9999999999999999999.9999999999", 38, 10);
196 var buffer = GetBuffer(key);
197 Assert.Equal(12, GetCurrentSize(key));
200 bool hasHighBytes = buffer[8] != 0 || buffer[9] != 0 || buffer[10] != 0 || buffer[11] != 0;
209 var key = CreateRecordKey(12);
212 InvokeAddDecimal(key,
"-12345.678901", 38, 10);
215 var buffer = GetBuffer(key);
216 Assert.Equal(12, GetCurrentSize(key));
220 bool hasSignExtension = buffer[11] == 0xFF;
221 Assert.True(hasSignExtension,
"Negative 12-byte decimal should have sign extension");
237 var key = CreateRecordKey(8);
240 InvokeAddDecimal(key,
"12345.6789", 18, 4);
243 Assert.Equal(8, GetCurrentSize(key));
259 var key = CreateRecordKey(12);
262 InvokeAddDecimal(key,
"12345.6789", 19, 4);
265 Assert.Equal(12, GetCurrentSize(key));
void AddDecimal_PrecisionBoundary_At18_Uses8Bytes()
WIRE FORMAT TEST: Verifies precision boundary - precision 18 uses 8-byte encoding.
void AddDecimal_PrecisionBoundary_At19_Uses12Bytes()
WIRE FORMAT TEST: Verifies precision boundary - precision 19 uses 12-byte encoding.
Wire-format pinning tests for RecordKey decimal encoding.
void AddDecimal_8Byte_WithNull_StoresZeros()
void AddDecimal_12Byte_WithNegativeValue_StoresCorrectly()
void AddDecimal_8Byte_WithNegativeValue_StoresCorrectly()
WIRE FORMAT TEST: Verifies 8-byte decimal encoding for negative values.
void AddDecimal_12Byte_WithLargeValue_StoresCorrectly()
void AddDecimal_12Byte_WithSimpleValue_StoresCorrectly()
Immutable collection of metadata about a Kinetica type.
void AddDecimal_8Byte_WithSimpleValue_StoresCorrectly()
WIRE FORMAT TEST: Verifies 8-byte decimal encoding for positive values.
API to talk to Kinetica Database
void AddDecimal_12Byte_WithNull_StoresZeros()