Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try send null-typed value instead typed null #22

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion ydb/src/client_table_test_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,40 @@ SELECT $test AS test;
Ok(())
}

#[tokio::test]
#[traced_test]
// #[ignore]
async fn send_null_value_as_nullable_param() -> YdbResult<()> {
let client = create_client().await?;
let table_client = client.table_client();
let res: Option<i32> = table_client
.retry_transaction(|tx| async {
let mut tx = tx;
let param = Value::Null;

let res = tx
.query(
Query::from(
"
DECLARE $res AS Int32?;

SELECT $res AS res;
",
)
.with_params(ydb_params!("$res" => param)),
)
.await?;
let mut row = res.into_only_row()?;
return Ok(row.remove_field_by_name("res")?);
})
.await?
.try_into()?;

assert_eq!(None, res);

return Ok(());
}

#[tokio::test]
#[traced_test]
#[ignore] // need YDB access
Expand Down Expand Up @@ -542,7 +576,7 @@ DECLARE $values AS List<Struct<

UPSERT INTO stream_query
SELECT
*
*
FROM
AS_TABLE($values);
",
Expand Down
2 changes: 2 additions & 0 deletions ydb/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ impl Session {

let mut channel = self.get_channel().await?;
let response = channel.execute_data_query(req).await?;
debug!("response: {}", serde_json::to_string(&response.get_ref())?);

let operation_result: ExecuteQueryResult = self.handle_operation_result(response)?;

trace!(
Expand Down
19 changes: 19 additions & 0 deletions ydb/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const SECONDS_PER_DAY: u64 = 60 * 60 * 24;
#[non_exhaustive]
pub enum Value {
Void,
Null,
Bool(bool),
Int8(i8),
Uint8(u8),
Expand Down Expand Up @@ -280,6 +281,7 @@ impl Value {
_ => unimplemented!("{:?} ({})", P::from_i32(*t_id), *t_id),
},
T::VoidType(_) => Value::Void,
T::NullType(_) => Value::Null,
T::OptionalType(val) => {
let t = if let Some(item) = &val.item {
Some(*item.clone())
Expand Down Expand Up @@ -319,6 +321,7 @@ impl Value {
pub(crate) fn from_proto(t: &Value, proto_value: ydb_proto::Value) -> YdbResult<Self> {
let res = match (t, proto_value) {
(Value::Void, _) => Value::Void,
(Value::Null, _) => Value::Null,
(
t,
ydb_proto::Value {
Expand Down Expand Up @@ -456,6 +459,21 @@ impl Value {
..ydb_proto::Value::default()
}),
},
Self::Null => ydb_proto::TypedValue {
r#type: Some(ydb_proto::Type {
r#type: Some(ydb_proto::r#type::Type::NullType(
prost_types::NullValue::NullValue.into(),
)),
..ydb_proto::Type::default()
}),
value: Some(ydb_proto::Value {
value: Some(ydb_proto::value::Value::NullFlagValue(
prost_types::NullValue::NullValue.into(),
)),
..ydb_proto::Value::default()
}),
..ydb_proto::TypedValue::default()
},
Self::Bool(val) => proto_typed_value(pt::Bool, pv::BoolValue(val)),
Self::Int8(val) => proto_typed_value(pt::Int8, pv::Int32Value(val.into())),
Self::Uint8(val) => proto_typed_value(pt::Uint8, pv::Uint32Value(val.into())),
Expand Down Expand Up @@ -623,6 +641,7 @@ mod test {
num_tests!(values, Value::Double, f64);

values.push(Value::Void);
values.push(Value::Null);

values.push(Value::Date(std::time::Duration::from_secs(1633996800))); //Tue Oct 12 00:00:00 UTC 2021
values.push(Value::DateTime(std::time::Duration::from_secs(1634000523))); //Tue Oct 12 01:02:03 UTC 2021
Expand Down