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

Query paging API: hardening, robustness, explicitness #1061

Merged
merged 19 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e2758fe
statement: introduce strongly-typed PageSize
wprzytula Aug 7, 2024
22f558b
underive Default for QueryResult & ResultMetadata
wprzytula Aug 22, 2024
9648b3d
requests: make paging state strongly typed
wprzytula Aug 6, 2024
6d9249f
statement: make page size mandatory
wprzytula Aug 19, 2024
5dc11b2
connection: add `_raw` {suf/in}fix to relevant methods
wprzytula Aug 26, 2024
e6f0268
connection: execute_raw takes prepared by ref
wprzytula Aug 26, 2024
e415267
connection: introduce non-raw query() and execute()
wprzytula Aug 26, 2024
c008d76
connection: pass page size through request API
wprzytula Aug 19, 2024
1eaf42c
session: make {query,execute} methods unpaged
wprzytula Aug 19, 2024
bfa853c
session: add "_unpaged" suffix to {query,execute}
wprzytula Aug 19, 2024
343b500
connection: make {query,execute}(_raw) methods unpaged
wprzytula Aug 26, 2024
dfe79e9
connection: append "_unpaged" to {query,execute}_{raw}
wprzytula Aug 26, 2024
6ae5fa6
connection: use query_unpaged for some internal queries
wprzytula Aug 26, 2024
c5140c9
codewide: rename {query,execute}_paged to %_single_page
wprzytula Aug 23, 2024
4f8cf18
session: {query,execute}_single_page pass page state explicitly
wprzytula Aug 20, 2024
d0f0fb4
connection: query_single_page takes paging state
wprzytula Aug 26, 2024
ec1c2e7
session: rename {query,execute}_inner to %
wprzytula Aug 20, 2024
f82d85a
session: update docstrings wrt paging
wprzytula Aug 20, 2024
a1286de
docs: update for new paging API
wprzytula Aug 20, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let uri = "127.0.0.1:9042";

let session: Session = SessionBuilder::new().known_node(uri).build().await?;

let result = session.query("SELECT a, b, c FROM ks.t", &[]).await?;
let result = session.query_unpaged("SELECT a, b, c FROM ks.t", &[]).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is precisely the kind of query and place you want people NOT to use query_unpaged. :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...which explains why we need this refactor that much :P

let mut iter = result.rows_typed::<(i32, i32, String)>()?;
while let Some((a, b, c)) = iter.next().transpose()? {
println!("a, b, c: {}, {}, {}", a, b, c);
Expand Down
4 changes: 2 additions & 2 deletions docs/source/data-types/blob.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use scylla::IntoTypedRows;
// We can insert it by reference to not move the whole blob
let to_insert: Vec<u8> = vec![1, 2, 3, 4, 5];
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (&to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&to_insert,))
.await?;

// Read blobs from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a full scan, just page.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are so many unpaged queries present in our docs... I suggest postponing rewrite of them to a separate follow-up PR.

let mut iter = result.rows_typed::<(Vec<u8>,)>()?;
while let Some((blob_value,)) = iter.next().transpose()? {
println!("{:?}", blob_value);
Expand Down
24 changes: 12 additions & 12 deletions docs/source/data-types/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use scylla::IntoTypedRows;
// Insert a list of ints into the table
let my_list: Vec<i32> = vec![1, 2, 3, 4, 5];
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (&my_list,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&my_list,))
.await?;

// Read a list of ints from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paged.

let mut iter = result.rows_typed::<(Vec<i32>,)>()?;
while let Some((list_value,)) = iter.next().transpose()? {
println!("{:?}", list_value);
Expand All @@ -39,11 +39,11 @@ use scylla::IntoTypedRows;
// Insert a set of ints into the table
let my_set: Vec<i32> = vec![1, 2, 3, 4, 5];
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (&my_set,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&my_set,))
.await?;

// Read a set of ints from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Vec<i32>,)>()?;
while let Some((list_value,)) = iter.next().transpose()? {
println!("{:?}", list_value);
Expand All @@ -63,11 +63,11 @@ use std::collections::HashSet;
// Insert a set of ints into the table
let my_set: HashSet<i32> = vec![1, 2, 3, 4, 5].into_iter().collect();
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (&my_set,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&my_set,))
.await?;

// Read a set of ints from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paged.

let mut iter = result.rows_typed::<(HashSet<i32>,)>()?;
while let Some((list_value,)) = iter.next().transpose()? {
println!("{:?}", list_value);
Expand All @@ -87,11 +87,11 @@ use std::collections::BTreeSet;
// Insert a set of ints into the table
let my_set: BTreeSet<i32> = vec![1, 2, 3, 4, 5].into_iter().collect();
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (&my_set,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&my_set,))
.await?;

// Read a set of ints from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paged.

let mut iter = result.rows_typed::<(BTreeSet<i32>,)>()?;
while let Some((list_value,)) = iter.next().transpose()? {
println!("{:?}", list_value);
Expand All @@ -116,11 +116,11 @@ let mut my_map: HashMap<String, i32> = HashMap::new();
my_map.insert("abcd".to_string(), 16);

session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (&my_map,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&my_map,))
.await?;

// Read a map from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paged.

let mut iter = result.rows_typed::<(HashMap<String, i32>,)>()?;
while let Some((map_value,)) = iter.next().transpose()? {
println!("{:?}", map_value);
Expand All @@ -142,11 +142,11 @@ let mut my_map: BTreeMap<String, i32> = BTreeMap::new();
my_map.insert("abcd".to_string(), 16);

session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (&my_map,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&my_map,))
.await?;

// Read a map from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paged.

let mut iter = result.rows_typed::<(BTreeMap<String, i32>,)>()?;
while let Some((map_value,)) = iter.next().transpose()? {
println!("{:?}", map_value);
Expand Down
2 changes: 1 addition & 1 deletion docs/source/data-types/counter.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use scylla::IntoTypedRows;
use scylla::frame::value::Counter;

// Read counter from the table
let result = session.query("SELECT c FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT c FROM keyspace.table", &[]).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paged.

let mut iter = result.rows_typed::<(Counter,)>()?;
while let Some((counter_value,)) = iter.next().transpose()? {
let counter_int_value: i64 = counter_value.0;
Expand Down
12 changes: 6 additions & 6 deletions docs/source/data-types/date.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ let to_insert = CqlDate((1 << 31) + 7);

// Insert date into the table
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read raw Date from the table
if let Some(rows) = session
.query("SELECT a FROM keyspace.table", &[])
.query_unpaged("SELECT a FROM keyspace.table", &[])
.await?
.rows
{
Expand Down Expand Up @@ -63,11 +63,11 @@ let to_insert = NaiveDate::from_ymd_opt(2021, 3, 24).unwrap();

// Insert date into the table
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read NaiveDate from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(NaiveDate,)>()?;
while let Some((date_value,)) = iter.next().transpose()? {
println!("{:?}", date_value);
Expand Down Expand Up @@ -97,11 +97,11 @@ let to_insert = Date::from_calendar_date(2021, Month::March, 24).unwrap();

// Insert date into the table
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read Date from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Date,)>()?;
while let Some((date_value,)) = iter.next().transpose()? {
println!("{:?}", date_value);
Expand Down
8 changes: 4 additions & 4 deletions docs/source/data-types/decimal.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use std::str::FromStr;
let to_insert: CqlDecimal =
CqlDecimal::from_signed_be_bytes_and_exponent(vec![0x01, 0xE2, 0x40], 3);
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a decimal from the table
if let Some(rows) = session.query("SELECT a FROM keyspace.table", &[]).await?.rows {
if let Some(rows) = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?.rows {
for row in rows.into_typed::<(CqlDecimal,)>() {
let (decimal_value,): (CqlDecimal,) = row?;
}
Expand All @@ -48,11 +48,11 @@ use std::str::FromStr;
// Insert a decimal into the table
let to_insert: BigDecimal = BigDecimal::from_str("12345.0")?;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a decimal from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(BigDecimal,)>()?;
while let Some((decimal_value,)) = iter.next().transpose()? {
println!("{:?}", decimal_value);
Expand Down
4 changes: 2 additions & 2 deletions docs/source/data-types/duration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use scylla::frame::value::CqlDuration;
// Insert some duration into the table
let to_insert: CqlDuration = CqlDuration { months: 1, days: 2, nanoseconds: 3 };
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read duration from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(CqlDuration,)>()?;
while let Some((duration_value,)) = iter.next().transpose()? {
println!("{:?}", duration_value);
Expand Down
4 changes: 2 additions & 2 deletions docs/source/data-types/inet.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use std::net::{IpAddr, Ipv4Addr};
// Insert some ip address into the table
let to_insert: IpAddr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read inet from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(IpAddr,)>()?;
while let Some((inet_value,)) = iter.next().transpose()? {
println!("{:?}", inet_value);
Expand Down
28 changes: 14 additions & 14 deletions docs/source/data-types/primitive.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ use scylla::IntoTypedRows;
// Insert a bool into the table
let to_insert: bool = true;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a bool from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(bool,)>()?;
while let Some((bool_value,)) = iter.next().transpose()? {
println!("{}", bool_value);
Expand All @@ -41,11 +41,11 @@ use scylla::IntoTypedRows;
// Insert a tinyint into the table
let to_insert: i8 = 123;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a tinyint from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(i8,)>()?;
while let Some((tinyint_value,)) = iter.next().transpose()? {
println!("{:?}", tinyint_value);
Expand All @@ -68,11 +68,11 @@ use scylla::IntoTypedRows;
// Insert a smallint into the table
let to_insert: i16 = 12345;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a smallint from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(i16,)>()?;
while let Some((smallint_value,)) = iter.next().transpose()? {
println!("{}", smallint_value);
Expand All @@ -95,11 +95,11 @@ use scylla::IntoTypedRows;
// Insert an int into the table
let to_insert: i32 = 12345;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read an int from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(i32,)>()?;
while let Some((int_value,)) = iter.next().transpose()? {
println!("{}", int_value);
Expand All @@ -122,11 +122,11 @@ use scylla::IntoTypedRows;
// Insert a bigint into the table
let to_insert: i64 = 12345;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a bigint from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(i64,)>()?;
while let Some((bigint_value,)) = iter.next().transpose()? {
println!("{:?}", bigint_value);
Expand All @@ -149,11 +149,11 @@ use scylla::IntoTypedRows;
// Insert a float into the table
let to_insert: f32 = 123.0;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a float from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(f32,)>()?;
while let Some((float_value,)) = iter.next().transpose()? {
println!("{:?}", float_value);
Expand All @@ -176,11 +176,11 @@ use scylla::IntoTypedRows;
// Insert a double into the table
let to_insert: f64 = 12345.0;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a double from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(f64,)>()?;
while let Some((double_value,)) = iter.next().transpose()? {
println!("{:?}", double_value);
Expand Down
6 changes: 3 additions & 3 deletions docs/source/data-types/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ use scylla::IntoTypedRows;
// Insert some text into the table as a &str
let to_insert_str: &str = "abcdef";
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert_str,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert_str,))
.await?;

// Insert some text into the table as a String
let to_insert_string: String = "abcdef".to_string();
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert_string,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert_string,))
.await?;

// Read ascii/text/varchar from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(String,)>()?;
while let Some((text_value,)) = iter.next().transpose()? {
println!("{}", text_value);
Expand Down
12 changes: 6 additions & 6 deletions docs/source/data-types/time.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ let to_insert = CqlTime(64 * 1_000_000_000);

// Insert time into the table
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read time from the table
if let Some(rows) = session
.query("SELECT a FROM keyspace.table", &[])
.query_unpaged("SELECT a FROM keyspace.table", &[])
.await?
.rows
{
Expand Down Expand Up @@ -63,11 +63,11 @@ let to_insert = NaiveTime::from_hms_nano_opt(1, 2, 3, 456_789_012);

// Insert time into the table
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read time from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(NaiveTime,)>()?;
while let Some((time_value,)) = iter.next().transpose()? {
println!("{:?}", time_value);
Expand Down Expand Up @@ -95,11 +95,11 @@ let to_insert = Time::from_hms_nano(1, 2, 3, 456_789_012).unwrap();

// Insert time into the table
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read time from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Time,)>()?;
while let Some((time_value,)) = iter.next().transpose()? {
println!("{:?}", time_value);
Expand Down
Loading
Loading