@@ -38,6 +38,7 @@ use crate::routing::{Shard, ShardAwarePortRange};
38
38
use crate :: statement:: batch:: BoundBatch ;
39
39
use crate :: statement:: batch:: { Batch , BatchStatement } ;
40
40
use crate :: statement:: bound:: BoundStatement ;
41
+ use crate :: statement:: execute:: { Execute , ExecutePageable } ;
41
42
use crate :: statement:: prepared:: { PartitionKeyError , PreparedStatement } ;
42
43
use crate :: statement:: unprepared:: Statement ;
43
44
use crate :: statement:: { Consistency , PageSize , StatementConfig } ;
@@ -58,7 +59,7 @@ use std::time::Duration;
58
59
use tokio:: time:: timeout;
59
60
#[ cfg( feature = "unstable-cloud" ) ]
60
61
use tracing:: warn;
61
- use tracing:: { debug, error , trace, trace_span, Instrument } ;
62
+ use tracing:: { debug, trace, trace_span, Instrument } ;
62
63
use uuid:: Uuid ;
63
64
64
65
pub ( crate ) const TABLET_CHANNEL_SIZE : usize = 8192 ;
@@ -483,7 +484,8 @@ impl Session {
483
484
statement : impl Into < Statement > ,
484
485
values : impl SerializeRow ,
485
486
) -> Result < QueryResult , ExecutionError > {
486
- self . do_query_unpaged ( & statement. into ( ) , values) . await
487
+ let statement = statement. into ( ) ;
488
+ ( & statement, values) . execute ( self ) . await
487
489
}
488
490
489
491
/// Queries a single page from the database, optionally continuing from a saved point.
@@ -543,7 +545,9 @@ impl Session {
543
545
values : impl SerializeRow ,
544
546
paging_state : PagingState ,
545
547
) -> Result < ( QueryResult , PagingStateResponse ) , ExecutionError > {
546
- self . do_query_single_page ( & statement. into ( ) , values, paging_state)
548
+ let statement = statement. into ( ) ;
549
+ ( & statement, values)
550
+ . execute_pageable :: < true > ( self , paging_state)
547
551
. await
548
552
}
549
553
@@ -808,9 +812,9 @@ impl Session {
808
812
values : impl BatchValues ,
809
813
) -> Result < QueryResult , ExecutionError > {
810
814
let batch = self . last_minute_prepare_batch ( batch, & values) . await ?;
811
- let batch = BoundBatch :: from_batch ( batch. as_ref ( ) , values) ?;
812
-
813
- self . do_batch ( & batch ) . await
815
+ BoundBatch :: from_batch ( batch. as_ref ( ) , values) ?
816
+ . execute ( self )
817
+ . await
814
818
}
815
819
}
816
820
@@ -991,38 +995,6 @@ impl Session {
991
995
Ok ( session)
992
996
}
993
997
994
- async fn do_query_unpaged (
995
- & self ,
996
- statement : & Statement ,
997
- values : impl SerializeRow ,
998
- ) -> Result < QueryResult , ExecutionError > {
999
- let ( result, paging_state_response) = self
1000
- . query ( statement, values, None , PagingState :: start ( ) )
1001
- . await ?;
1002
- if !paging_state_response. finished ( ) {
1003
- error ! ( "Unpaged unprepared query returned a non-empty paging state! This is a driver-side or server-side bug." ) ;
1004
- return Err ( ExecutionError :: LastAttemptError (
1005
- RequestAttemptError :: NonfinishedPagingState ,
1006
- ) ) ;
1007
- }
1008
- Ok ( result)
1009
- }
1010
-
1011
- async fn do_query_single_page (
1012
- & self ,
1013
- statement : & Statement ,
1014
- values : impl SerializeRow ,
1015
- paging_state : PagingState ,
1016
- ) -> Result < ( QueryResult , PagingStateResponse ) , ExecutionError > {
1017
- self . query (
1018
- statement,
1019
- values,
1020
- Some ( statement. get_validated_page_size ( ) ) ,
1021
- paging_state,
1022
- )
1023
- . await
1024
- }
1025
-
1026
998
/// Sends a request to the database.
1027
999
/// Optionally continues fetching results from a saved point.
1028
1000
///
@@ -1034,7 +1006,7 @@ impl Session {
1034
1006
/// that we need to require users to make a conscious decision to use paging or not. For that, we expose
1035
1007
/// the aforementioned 3 methods clearly differing in naming and API, so that no unconscious choices about paging
1036
1008
/// should be made.
1037
- async fn query (
1009
+ pub ( crate ) async fn query (
1038
1010
& self ,
1039
1011
statement : & Statement ,
1040
1012
values : impl SerializeRow ,
@@ -1299,23 +1271,15 @@ impl Session {
1299
1271
& self ,
1300
1272
statement : & BoundStatement ,
1301
1273
) -> Result < QueryResult , ExecutionError > {
1302
- let ( result, paging_state) = self . execute ( statement, None , PagingState :: start ( ) ) . await ?;
1303
- if !paging_state. finished ( ) {
1304
- error ! ( "Unpaged prepared query returned a non-empty paging state! This is a driver-side or server-side bug." ) ;
1305
- return Err ( ExecutionError :: LastAttemptError (
1306
- RequestAttemptError :: NonfinishedPagingState ,
1307
- ) ) ;
1308
- }
1309
- Ok ( result)
1274
+ statement. execute ( self ) . await
1310
1275
}
1311
1276
1312
1277
async fn do_execute_single_page (
1313
1278
& self ,
1314
1279
statement : & BoundStatement ,
1315
1280
paging_state : PagingState ,
1316
1281
) -> Result < ( QueryResult , PagingStateResponse ) , ExecutionError > {
1317
- let page_size = statement. prepared . get_validated_page_size ( ) ;
1318
- self . execute ( statement, Some ( page_size) , paging_state) . await
1282
+ statement. execute_pageable :: < true > ( self , paging_state) . await
1319
1283
}
1320
1284
1321
1285
/// Sends a prepared request to the database, optionally continuing from a saved point.
@@ -1328,7 +1292,7 @@ impl Session {
1328
1292
/// that we need to require users to make a conscious decision to use paging or not. For that, we expose
1329
1293
/// the aforementioned 3 methods clearly differing in naming and API, so that no unconscious choices about paging
1330
1294
/// should be made.
1331
- async fn execute (
1295
+ pub ( crate ) async fn execute_bound_statement (
1332
1296
& self ,
1333
1297
statement : & BoundStatement ,
1334
1298
page_size : Option < PageSize > ,
@@ -1449,7 +1413,7 @@ impl Session {
1449
1413
. map_err ( PagerExecutionError :: NextPageError )
1450
1414
}
1451
1415
1452
- async fn do_batch ( & self , batch : & BoundBatch ) -> Result < QueryResult , ExecutionError > {
1416
+ pub ( crate ) async fn do_batch ( & self , batch : & BoundBatch ) -> Result < QueryResult , ExecutionError > {
1453
1417
// Shard-awareness behavior for batch will be to pick shard based on first batch statement's shard
1454
1418
// If users batch statements by shard, they will be rewarded with full shard awareness
1455
1419
let execution_profile = batch
@@ -1750,10 +1714,10 @@ impl Session {
1750
1714
traces_events_query. config . consistency = consistency;
1751
1715
traces_events_query. set_page_size ( TRACING_QUERY_PAGE_SIZE ) ;
1752
1716
1753
- let ( traces_session_res , traces_events_res ) = tokio :: try_join! (
1754
- self . do_query_unpaged ( & traces_session_query , ( tracing_id, ) ) ,
1755
- self . do_query_unpaged ( & traces_events_query , ( tracing_id , ) )
1756
- ) ?;
1717
+ let session_query = ( & traces_session_query , ( tracing_id , ) ) ;
1718
+ let events_query = ( & traces_events_query , ( tracing_id, ) ) ;
1719
+ let ( traces_session_res , traces_events_res ) =
1720
+ tokio :: try_join! ( session_query . execute ( self ) , events_query . execute ( self ) ) ?;
1757
1721
1758
1722
// Get tracing info
1759
1723
let maybe_tracing_info: Option < TracingInfo > = traces_session_res
0 commit comments