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

Use new Pull message behind the feature flag #196

Merged
merged 2 commits into from
Aug 28, 2024
Merged
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
4 changes: 3 additions & 1 deletion lib/src/bolt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ mod request;
mod structs;
mod summary;

pub use request::{Commit, Discard, Goodbye, Hello, HelloBuilder, Reset, Rollback, WrapExtra};
pub use request::{
Commit, Discard, Goodbye, Hello, HelloBuilder, Pull, Reset, Rollback, WrapExtra,
};
pub use structs::{
Bolt, BoltRef, Date, DateDuration, DateTime, DateTimeZoneId, DateTimeZoneIdRef, Duration,
LegacyDateTime, LegacyDateTimeZoneId, LegacyDateTimeZoneIdRef, LocalDateTime, LocalTime, Node,
Expand Down
33 changes: 20 additions & 13 deletions lib/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::{
use begin::Begin;
use bytes::Bytes;
use failure::Failure;
use pull::Pull;
use record::Record;
use run::Run;
pub(crate) use success::Success;
Expand All @@ -37,30 +36,34 @@ pub enum BoltResponse {
pub enum BoltRequest {
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Hello` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Hello` instead.")
)]
Hello(hello::Hello),
Run(Run),
Pull(Pull),
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Discard` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Pull` instead.")
)]
Pull(pull::Pull),
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.9.0", note = "Use `crate::bolt::Discard` instead.")
)]
Discard(discard::Discard),
Begin(Begin),
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Commit` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Commit` instead.")
)]
Commit(commit::Commit),
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Rollback` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Rollback` instead.")
)]
Rollback(rollback::Rollback),
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Reset` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Reset` instead.")
)]
Reset(reset::Reset),
}
Expand Down Expand Up @@ -107,7 +110,7 @@ impl HelloBuilder {
impl BoltRequest {
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Hello` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Hello` instead.")
)]
pub fn hello(
agent: BoltString,
Expand All @@ -133,13 +136,17 @@ impl BoltRequest {
BoltRequest::Run(Run::new(db.into(), query.into(), params))
}

#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.9.0", note = "Use `crate::bolt::Pull` instead.")
)]
pub fn pull(n: usize, qid: i64) -> BoltRequest {
BoltRequest::Pull(Pull::new(n as i64, qid))
BoltRequest::Pull(pull::Pull::new(n as i64, qid))
}

#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Discard` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Discard` instead.")
)]
pub fn discard() -> BoltRequest {
BoltRequest::Discard(discard::Discard::default())
Expand All @@ -152,23 +159,23 @@ impl BoltRequest {

#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Commit` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Commit` instead.")
)]
pub fn commit() -> BoltRequest {
BoltRequest::Commit(commit::Commit::new())
}

#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Rollback` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Rollback` instead.")
)]
pub fn rollback() -> BoltRequest {
BoltRequest::Rollback(rollback::Rollback::new())
}

#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Reset` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Reset` instead.")
)]
pub fn reset() -> BoltRequest {
BoltRequest::Reset(reset::Reset::new())
Expand Down
2 changes: 1 addition & 1 deletion lib/src/messages/bye.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use neo4rs_macros::BoltStruct;
#[signature(0xB0, 0x02)]
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Bye` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Bye` instead.")
)]
pub struct Bye;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/messages/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use neo4rs_macros::BoltStruct;
#[signature(0xB0, 0x12)]
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Commit` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Commit` instead.")
)]
pub struct Commit;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/messages/discard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use neo4rs_macros::BoltStruct;
#[signature(0xB1, 0x2F)]
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Discard` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Discard` instead.")
)]
pub struct Discard {
extra: BoltMap,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/messages/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use neo4rs_macros::BoltStruct;
#[signature(0xB1, 0x01)]
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Hello` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Hello` instead.")
)]
pub struct Hello {
extra: BoltMap,
Expand Down
7 changes: 7 additions & 0 deletions lib/src/messages/pull.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#![cfg_attr(feature = "unstable-bolt-protocol-impl-v2", allow(deprecated))]

use crate::types::BoltMap;
use neo4rs_macros::BoltStruct;

#[derive(Debug, PartialEq, Clone, BoltStruct)]
#[signature(0xB1, 0x3F)]
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.9.0", note = "Use `crate::bolt::Pull` instead.")
)]
pub struct Pull {
extra: BoltMap,
}
Expand All @@ -14,6 +20,7 @@ impl Default for Pull {
}

impl Pull {
#[cfg_attr(feature = "unstable-bolt-protocol-impl-v2", allow(dead_code))]
pub fn new(n: i64, qid: i64) -> Pull {
let mut extra = BoltMap::default();
extra.put("n".into(), n.into());
Expand Down
2 changes: 1 addition & 1 deletion lib/src/messages/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use neo4rs_macros::BoltStruct;
#[signature(0xB0, 0x0F)]
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Reset` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Reset` instead.")
)]
pub struct Reset;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/messages/rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use neo4rs_macros::BoltStruct;
#[signature(0xB0, 0x13)]
#[cfg_attr(
feature = "unstable-bolt-protocol-impl-v2",
deprecated(since = "0.8.0", note = "Use `crate::bolt::Rollback` instead.")
deprecated(since = "0.9.0", note = "Use `crate::bolt::Rollback` instead.")
)]
pub struct Rollback;

Expand Down
78 changes: 59 additions & 19 deletions lib/src/stream.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#[cfg(not(feature = "unstable-bolt-protocol-impl-v2"))]
use crate::messages::{BoltRequest, BoltResponse};
#[cfg(feature = "unstable-streaming-summary")]
use crate::summary::StreamingSummary;
#[cfg(feature = "unstable-bolt-protocol-impl-v2")]
use crate::{
bolt::{Bolt, Pull, Response, WrapExtra as _},
summary::Streaming,
BoltType,
};

use crate::{
errors::{Error, Result},
messages::{BoltRequest, BoltResponse},
pool::ManagedConnection,
row::Row,
txn::TransactionHandle,
Expand Down Expand Up @@ -118,27 +125,60 @@ impl RowStream {

match self.state {
State::Ready => {
let pull = BoltRequest::pull(self.fetch_size, self.qid);
let connection = handle.connection();
connection.send(pull).await?;
#[cfg(feature = "unstable-bolt-protocol-impl-v2")]
{
let pull = Pull::some(self.fetch_size as i64).for_query(self.qid);
let connection = handle.connection();
connection.send_as(pull).await?;

self.state = loop {
match connection.recv().await {
Ok(BoltResponse::Success(s)) => {
break if s.get("has_more").unwrap_or(false) {
State::Ready
} else {
State::Complete(None)
};
self.state = loop {
let response = connection
.recv_as::<Response<Vec<Bolt>, Streaming>>()
.await?;
match response {
Response::Detail(record) => {
let record = BoltList::from(
record
.into_iter()
.map(BoltType::from)
.collect::<Vec<BoltType>>(),
);
let row = Row::new(self.fields.clone(), record);
self.buffer.push_back(row);
}
Response::Success(Streaming::HasMore) => break State::Ready,
Response::Success(Streaming::Done(s)) => {
break State::Complete(Some(s))
}
otherwise => return Err(otherwise.into_error("PULL")),
}
Ok(BoltResponse::Record(record)) => {
let row = Row::new(self.fields.clone(), record.data);
self.buffer.push_back(row);
};
}

#[cfg(not(feature = "unstable-bolt-protocol-impl-v2"))]
{
let pull = BoltRequest::pull(self.fetch_size, self.qid);
let connection = handle.connection();
connection.send(pull).await?;

self.state = loop {
match connection.recv().await {
Ok(BoltResponse::Success(s)) => {
break if s.get("has_more").unwrap_or(false) {
State::Ready
} else {
State::Complete(None)
};
}
Ok(BoltResponse::Record(record)) => {
let row = Row::new(self.fields.clone(), record.data);
self.buffer.push_back(row);
}
Ok(msg) => return Err(msg.into_error("PULL")),
Err(e) => return Err(e),
}
Ok(msg) => return Err(msg.into_error("PULL")),
Err(e) => return Err(e),
}
};
};
}
}
State::Complete(ref mut _summary) => {
#[cfg(feature = "unstable-streaming-summary")]
Expand Down