Skip to content

Commit

Permalink
add null support
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Gardner committed Jul 14, 2023
1 parent 1b2d239 commit 85d7266
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion ignite-rs/src/protocol/complex_obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::cache::{QueryEntity, QueryField};
use crate::error::{IgniteError, IgniteResult};
use crate::protocol::{
read_bool, read_i16, read_i32, read_i64, read_string, read_u16, read_u8, write_i16, write_i32,
write_i64, write_string, write_u16, write_u8, TypeCode, COMPLEX_OBJ_HEADER_LEN,
write_i64, write_null, write_string, write_u16, write_u8, TypeCode, COMPLEX_OBJ_HEADER_LEN,
FLAG_COMPACT_FOOTER, FLAG_HAS_SCHEMA, FLAG_OFFSET_ONE_BYTE, FLAG_OFFSET_TWO_BYTES,
FLAG_USER_TYPE, HAS_RAW_DATA,
};
Expand All @@ -22,6 +22,7 @@ pub enum IgniteValue {
Bool(bool),
Timestamp(i64, i32), // milliseconds since 1 Jan 1970 UTC, Nanosecond fraction of a millisecond.
Decimal(i32, Vec<u8>), // scale, big int value in bytes
Null,
}

#[derive(Debug, PartialEq, Eq)]
Expand All @@ -33,6 +34,7 @@ pub enum IgniteType {
Bool,
Timestamp,
Decimal(i32, i32), // precision, scale
Null,
}

#[derive(Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -97,6 +99,9 @@ impl ComplexObject {
write_i32(&mut values, data.len() as i32)?;
values.write_all(data)?;
}
IgniteValue::Null => {
write_null(&mut values)?;
}
}
}
Ok((values, schema))
Expand Down Expand Up @@ -216,6 +221,7 @@ impl ReadableType for ComplexObject {
remainder.read_exact(&mut buf)?;
IgniteValue::Decimal(scale, buf)
}
TypeCode::Null => IgniteValue::Null,
_ => {
let msg = format!("Unknown type: {:?}", field_type);
Err(IgniteError::from(msg.as_str()))?
Expand Down
5 changes: 5 additions & 0 deletions ignite-rs/tests/int-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ mod int_test {
name: "INT".to_string(),
r#type: IgniteType::Int
},
IgniteField {
name: "NULL_INT".to_string(),
r#type: IgniteType::Int
},
IgniteField {
name: "SMALL".to_string(),
r#type: IgniteType::Short
Expand Down Expand Up @@ -112,6 +116,7 @@ mod int_test {
IgniteValue::Bool(true),
IgniteValue::Decimal(1, vec![20]),
IgniteValue::Int(3),
IgniteValue::Null,
IgniteValue::Short(4),
IgniteValue::String("c".to_string()),
IgniteValue::String("varchar".to_string()),
Expand Down
5 changes: 3 additions & 2 deletions ignite-rs/tests/resources/rainbow.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ create table rainbow (
dec DECIMAL, -- java.math.BigDecimal
-- double DOUBLE, -- java.lang.Double -- TODO: add support for this type
int INT, -- java.lang.Integer
null_int INT, -- java.lang.Integer
-- real REAL, -- java.lang.Float -- TODO: add support for this type
small SMALLINT, -- java.lang.Short
-- tiny TINYINT, -- java.lang.Byte -- TODO: add support for this type
Expand All @@ -18,5 +19,5 @@ create table rainbow (
primary key (big)
);

insert into rainbow (big, bool, dec, int, small, char, var, ts) values
(1, true, 2.0, 3, 4, 'c', 'varchar', timestamp '2023-06-21 12:34:56 UTC');
insert into rainbow (big, bool, dec, int, null_int, small, char, var, ts) values
(1, true, 2.0, 3, null, 4, 'c', 'varchar', timestamp '2023-06-21 12:34:56 UTC');

0 comments on commit 85d7266

Please sign in to comment.