2 using System.Collections.Generic;
6 namespace kinetica.Records;
37 private readonly
Type _type;
47 _type = type ??
throw new ArgumentNullException(nameof(type));
51 for (
int i = 0; i < _values.Length; i++)
58 #region Put Methods (by index) 61 public bool Put(
int index,
int value)
63 if (index < 0 || index >= _values.Length)
return false;
69 public bool Put(
int index,
long value)
71 if (index < 0 || index >= _values.Length)
return false;
77 public bool Put(
int index,
float value)
79 if (index < 0 || index >= _values.Length)
return false;
85 public bool Put(
int index,
double value)
87 if (index < 0 || index >= _values.Length)
return false;
93 public bool Put(
int index,
string? value)
95 if (index < 0 || index >= _values.Length)
return false;
101 public bool Put(
int index,
byte[]? value)
103 if (index < 0 || index >= _values.Length)
return false;
109 public bool Put(
int index,
bool value)
111 if (index < 0 || index >= _values.Length)
return false;
119 if (index < 0 || index >= _values.Length)
return false;
127 if (index < 0 || index >= _values.Length)
return false;
128 _values[index] = value;
134 #region Put Methods (by name) 137 public bool Put(
string name,
int value)
139 var index = _type.GetColumnIndex(name);
140 return index.HasValue &&
Put(index.Value, value);
144 public bool Put(
string name,
long value)
146 var index = _type.GetColumnIndex(name);
147 return index.HasValue &&
Put(index.Value, value);
151 public bool Put(
string name,
float value)
153 var index = _type.GetColumnIndex(name);
154 return index.HasValue &&
Put(index.Value, value);
158 public bool Put(
string name,
double value)
160 var index = _type.GetColumnIndex(name);
161 return index.HasValue &&
Put(index.Value, value);
165 public bool Put(
string name,
string? value)
167 var index = _type.GetColumnIndex(name);
168 return index.HasValue &&
Put(index.Value, value);
172 public bool Put(
string name,
byte[]? value)
174 var index = _type.GetColumnIndex(name);
175 return index.HasValue &&
Put(index.Value, value);
179 public bool Put(
string name,
bool value)
181 var index = _type.GetColumnIndex(name);
182 return index.HasValue &&
Put(index.Value, value);
188 var index = _type.GetColumnIndex(name);
189 return index.HasValue &&
PutNull(index.Value);
195 var index = _type.GetColumnIndex(name);
196 return index.HasValue &&
Put(index.Value, value);
201 #region Get Methods (by index) 206 if (index < 0 || index >= _values.Length)
return null;
207 return _values[index];
213 if (index < 0 || index >= _values.Length)
return null;
214 return _values[index].AsInt();
220 if (index < 0 || index >= _values.Length)
return null;
221 return _values[index].AsLong();
227 if (index < 0 || index >= _values.Length)
return null;
228 return _values[index].AsFloat();
234 if (index < 0 || index >= _values.Length)
return null;
235 return _values[index].AsDouble();
241 if (index < 0 || index >= _values.Length)
return null;
242 return _values[index].AsString();
248 if (index < 0 || index >= _values.Length)
return null;
249 return _values[index].AsBytes();
255 if (index < 0 || index >= _values.Length)
return null;
256 return _values[index].AsBool();
261 #region Get Methods (by name) 266 var index = _type.GetColumnIndex(name);
267 return index.HasValue ?
Get(index.Value) :
null;
273 var index = _type.GetColumnIndex(name);
274 return index.HasValue ?
GetInt(index.Value) :
null;
280 var index = _type.GetColumnIndex(name);
281 return index.HasValue ?
GetLong(index.Value) :
null;
287 var index = _type.GetColumnIndex(name);
288 return index.HasValue ?
GetFloat(index.Value) :
null;
294 var index = _type.GetColumnIndex(name);
295 return index.HasValue ?
GetDouble(index.Value) :
null;
301 var index = _type.GetColumnIndex(name);
302 return index.HasValue ?
GetString(index.Value) :
null;
308 var index = _type.GetColumnIndex(name);
309 return index.HasValue ?
GetBytes(index.Value) :
null;
315 var index = _type.GetColumnIndex(name);
316 return index.HasValue ?
GetBool(index.Value) :
null;
321 #region IKineticaRecord Implementation 333 var result =
new Dictionary<string, IList<string>>();
334 foreach (var col
in type.Columns)
336 if (col.Properties.Count > 0)
337 result[col.Name] = col.Properties.ToList();
344 #region IShardKeyExtractor Implementation 351 var shardKeyIndices = _type.ShardKeyIndices;
352 if (shardKeyIndices.Count == 0)
355 var values =
new (
string Name,
ShardKeyValue Value)[shardKeyIndices.Count];
357 for (
int i = 0; i < shardKeyIndices.Count; i++)
359 var idx = shardKeyIndices[i];
360 var col = _type.GetColumn(idx)!;
361 var recordValue = _values[idx];
363 var shardValue = ConvertToShardKeyValue(recordValue, col.ColumnType);
364 values[i] = (col.Name, shardValue);
375 return columnType
switch 377 ColumnType.Integer or ColumnType.
Int8 or ColumnType.
Int16 or ColumnType.
Boolean 416 #region Utility Methods 424 Array.Copy(_values, copy._values, _values.Length);
433 for (
int i = 0; i < _values.Length; i++)
447 var result =
new object?[_values.Length];
448 for (
int i = 0; i < _values.Length; i++)
450 var value = _values[i];
451 result[i] = value.
Type switch 470 var sb =
new StringBuilder();
471 sb.Append(_type.Label);
474 for (
int i = 0; i < _type.ColumnCount; i++)
476 if (i > 0) sb.Append(
", ");
477 var col = _type.GetColumn(i)!;
480 sb.Append(_values[i]);
484 return sb.ToString();
string? AsString()
Gets the value as a string.
static ShardKeyValue Int(int value)
Creates a 32-bit integer shard key value.
int ColumnCount
Gets the number of columns.
static ShardKeyValue Float(float value)
Creates a 32-bit float shard key value.
bool Put(string name, float value)
Sets a float value by column name.
bool PutNull(string name)
Sets a null value by column name.
int? GetInt(string name)
Gets an integer value by column name.
byte? [] GetBytes(string name)
Gets a bytes value by column name.
string? GetString(int index)
Gets a string value by column index.
float? GetFloat(int index)
Gets a float value by column index.
override string ToString()
static RecordValue Null()
Creates a null record value.
string? GetString(string name)
Gets a string value by column name.
long? GetLong(string name)
Gets a long value by column name.
bool Put(string name, string? value)
Sets a string value by column name.
static RecordValue Long(long value)
Creates a 64-bit integer record value.
Combined interface for records that support bulk insertion with shard-aware routing.
bool PutNull(int index)
Sets a null value by column index.
static ShardKeyValue Int16(short value)
Creates a 16-bit integer shard key value.
ShardKeyValues GetShardKeyValues()
Returns shard key column names and their typed values.
bool Put(int index, int value)
Sets an integer value by column index.
bool Put(string name, double value)
Sets a double value by column name.
GenericRecord(Type type)
Creates a new GenericRecord for the given type.
long? AsLong()
Gets the value as a 64-bit integer.
static ShardKeyValue Uuid(string value)
Creates a UUID shard key value (standard format).
bool Put(int index, double value)
Sets a double value by column index.
static ShardKeyValue Time(string value)
Creates a time shard key value (HH:MM:SS.mmm format).
static RecordValue Boolean(bool value)
Creates a boolean record value (stored as int).
bool IsNull
Returns true if this value is null.
int? AsInt()
Gets the value as a 32-bit integer.
int? GetInt(int index)
Gets an integer value by column index.
RecordValue? Get(string name)
Gets the raw RecordValue by column name.
static ShardKeyValue Double(double value)
Creates a 64-bit double shard key value.
bool? GetBool(string name)
Gets a boolean value by column name.
bool Put(int index, string? value)
Sets a string value by column index.
static RecordValue Float(float value)
Creates a 32-bit float record value.
static ShardKeyValue Ipv4(string value)
Creates an IPv4 shard key value (dotted-quad format).
static ShardKeyValue Null()
Creates a null shard key value.
Collection of shard key column names and values.
static ShardKeyValue Timestamp(long value)
Creates a timestamp shard key value (milliseconds since Unix epoch).
bool Put(int index, float value)
Sets a float value by column index.
static ShardKeyValue Decimal(string value)
Creates a decimal shard key value (string representation).
bool? GetBool(int index)
Gets a boolean value by column index.
static RecordValue String(string value)
Creates a string record value.
static ShardKeyValues Empty
Creates an empty ShardKeyValues collection.
bool Put(string name, RecordValue value)
Sets a RecordValue by column name.
static ShardKeyValue Int8(sbyte value)
Creates an 8-bit integer shard key value.
bool Put(int index, byte[]? value)
Sets a bytes value by column index.
void Clear()
Resets all values to null.
static ShardKeyValue DateTime(string value)
Creates a datetime shard key value (YYYY-MM-DD HH:MM:SS.mmm format).
string GetAvroSchema()
Returns the Avro schema as a JSON string for this record type.
object? [] ToObjectArray()
Gets all values as objects (for Avro serialization).
RecordValue? Get(int index)
Gets the raw RecordValue at the specified index.
static ShardKeyValue Long(long value)
Creates a 64-bit integer shard key value.
bool Put(int index, bool value)
Sets a boolean value by column index.
static RecordValue Bytes(byte[] value)
Creates a bytes record value.
double? GetDouble(string name)
Gets a double value by column name.
bool Put(int index, RecordValue value)
Sets a RecordValue by column index.
static ShardKeyValue Date(string value)
Creates a date shard key value (YYYY-MM-DD format).
Type RecordType
Gets the Type definition for this record.
long? GetLong(int index)
Gets a long value by column index.
double? AsDouble()
Gets the value as a 64-bit double.
Immutable collection of metadata about a Kinetica type.
byte? [] GetBytes(int index)
Gets a bytes value by column index.
static ShardKeyValue String(string value)
Creates a string shard key value.
bool Put(int index, long value)
Sets a long value by column index.
A typed value for shard key computation.
A generic record that can hold values for any Kinetica type.
GenericRecord Clone()
Creates a copy of this record.
bool Put(string name, bool value)
Sets a boolean value by column name.
bool Put(string name, byte[]? value)
Sets a bytes value by column name.
RecordValueType Type
Gets the type of this record value.
static RecordValue Int(int value)
Creates a 32-bit integer record value.
float? GetFloat(string name)
Gets a float value by column name.
RecordValueType
Represents the type of a record value.
bool Put(string name, long value)
Sets a long value by column name.
float? AsFloat()
Gets the value as a 32-bit float.
static RecordValue Double(double value)
Creates a 64-bit double record value.
double? GetDouble(int index)
Gets a double value by column index.
static ShardKeyValue Boolean(bool value)
Creates a boolean shard key value.
A typed value that can be stored in a GenericRecord.
bool Put(string name, int value)
Sets an integer value by column name.
static IReadOnlyDictionary< string, IList< string > > GetTypeProperties(Type type)
Returns type properties for this record type.