pub struct GenericRecord /* private fields */ A generic record that can hold values for any Kinetica type.
It stores values in an array indexed by column position, and uses the associated Type for schema information.
Example
Dates and times
A date, time or datetime column holds text in Kinetica’s formats: yyyy-MM-dd, HH:mm:ss.SSS and yyyy-MM-dd HH:mm:ss.SSS. A record reads no other formats; format the value with chrono first:
Fractions of a second past the millisecond are dropped, not rounded. chrono refuses a day past the end of its month (2023-02-30) and the time 24:00. Zone names (America/New_York, EST) need a zone database, such as the chrono-tz crate. A fixed offset ignores daylight saving, so give the offset in effect if that is what is meant.
Implementations
impl GenericRecord
pub fn decode( record_type: &Arc<Type>, encoded: &[u8], ) -> Result<GenericRecord, KineticaError>
Decodes a record of record_type from its Avro binary form.
pub fn decode_all<B: AsRef<[u8]>>( record_type: &Arc<Type>, encoded: &[B], ) -> Result<Vec<GenericRecord>, KineticaError>
Decodes records of record_type from their Avro binary forms.
The records of a dynamic (column-wise) response, one per row, typed by record_type (see Type::from_dynamic_schema).
Create a new GenericRecord for the given type.
All values are initialized to Null.
pub fn record_type(&self) -> &Arc<Type>
Get the type definition for this record.
pub fn get_by_name(&self, name: &str) -> Option<&RecordValue>
Get a value by column name.
pub fn set<V: Into<RecordValue>>( &mut self, index: usize, value: V, ) -> Result<(), KineticaError>
Sets the value at index. The value is not checked against the column’s type here; encoding the record does that. An index past the last column fails.
pub fn set_by_name<V: Into<RecordValue>>( &mut self, name: &str, value: V, ) -> Result<(), KineticaError>
Sets the value of the column name. A name the type does not have fails with “Field ‘<name>’ does not exist.”
Sets the value at index to null; see GenericRecord::set.
pub fn set_null_by_name(&mut self, name: &str) -> Result<(), KineticaError>
Sets the value of the column name to null; see GenericRecord::set_by_name.
Get long value by index. An int value is widened.
Get double value by index. A float value is widened.
pub fn get_array(&self, index: usize) -> Result<ArrayValue, KineticaError>
The elements of an array column, or the floats of a vector column. An array column’s value is JSON text, read as an array of its element type (see Column::array_type), each element None where it is null, with these coercions: a number from text, an integer from a fraction (truncated), a boolean from a number. Bytes elements arrive as text whose characters are the bytes, or as integers, which become their minimal big-endian bytes.
pub fn get_array_by_name(&self, name: &str) -> Result<ArrayValue, KineticaError>
Self::get_array, by column name.
pub fn get_vector(&self, index: usize) -> Result<Vec<f32>, KineticaError>
The floats of a vector column, read little-endian from its bytes. Fails with “Not a vector column” for a column without a vector(N) property.
pub fn get_vector_by_name(&self, name: &str) -> Result<Vec<f32>, KineticaError>
Self::get_vector, by column name.
A JSON column’s object.
pub fn get_json_by_name( &self, name: &str, ) -> Result<Map<String, Value>, KineticaError>
Self::get_json, by column name.
Puts an array column’s value. Text goes as it is, None as null, and anything else (a Vec<i32>, say) as its JSON text.
pub fn set_array_by_name<V: Serialize>( &mut self, name: &str, value: &V, ) -> Result<(), KineticaError>
Self::set_array, by column name.
Puts a JSON column’s value. Text goes as it is, None as null, and anything else (a map, say) as its JSON text.
pub fn set_json_by_name<V: Serialize>( &mut self, name: &str, value: &V, ) -> Result<(), KineticaError>
Self::set_json, by column name.
Puts a bytes column’s value, or null.
pub fn set_bytes_by_name( &mut self, name: &str, value: Option<Vec<u8>>, ) -> Result<(), KineticaError>
Self::set_bytes, by column name.
pub fn set_vector( &mut self, index: usize, value: &[f32], ) -> Result<(), KineticaError>
Puts a vector column’s floats, little-endian. Fails with “Not a vector column” for a column without a vector(N) property, and with “Unmatched vector dimensions: found <n> but expected <n>” for another number of floats.
pub fn set_vector_text( &mut self, index: usize, text: &str, ) -> Result<(), KineticaError>
Puts a vector column’s floats given as a JSON array: “Error reading vector string” where it is not one.
pub fn set_vector_by_name( &mut self, name: &str, value: &[f32], ) -> Result<(), KineticaError>
Self::set_vector, by column name.
pub fn set_decimal( &mut self, index: usize, value: impl Into<RecordValue>, ) -> Result<(), KineticaError>
Puts a decimal column’s value: text as it is, null as null, and a number at the column’s scale, failing where that would drop a digit, and for a NaN or infinity. Trailing zeros after the decimal point are stripped (“120.00” is “120.”). A whole number at scale 0 has no decimal point, so it keeps its value.
pub fn set_decimal_by_name( &mut self, name: &str, value: impl Into<RecordValue>, ) -> Result<(), KineticaError>
Self::set_decimal, by column name.
Trait Implementations
impl Clone for GenericRecord
fn clone(&self) -> GenericRecord
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Debug for GenericRecord
impl Display for GenericRecord
”name”:value,.., each name quoted and escaped, and each value as its text: a number bare (NaN and the infinities quoted), text and bytes quoted, and null as null.
impl Eq for GenericRecord
impl Hash for GenericRecord
Consistent with GenericRecord’s equality: floats by their bits, every NaN alike.
impl KineticaRecord for GenericRecord
fn avro_schema(&self) -> &‘static str
fn use_compression() -> bool
KineticaOptions::use_snappy enabled. Read moreimpl PartialEq for GenericRecord
The same type, and every value equal, floats by their bits with every NaN alike.
impl RetrievedRecord for GenericRecord
fn decode_records( record_type: &Arc<Type>, encoded: &[ByteBuf], ) -> Result<Vec<Self>, KineticaError>
record_type. A failure reads “Could not decode object: …”.impl Serialize for GenericRecord
Encodes the record for its Avro schema, field by field in column order, each value converted for its column:
- a number goes into an
int,long,floatordoublecolumn whatever its own type, converted asasconverts it (truncated, or rounded to the nearest); - a string goes only into a
stringcolumn, and bytes only intobytes; - a nullable column is an Avro union, which takes a value only of the column’s own type, unconverted, or null.
A value the column cannot take fails the record with a message that begins with ENCODE_FAILURE_PREFIX.
impl ShardKeyExtractor for GenericRecord
fn shard_key_values(&self) -> ShardKeyValues<’_>
Returns the values of the columns the table is sharded on: its shard key columns, or its primary key columns when it has no shard key.