Skip to content

Commit 2aa0924

Browse files
fix(batch): retain decoded counts across scalar status enrichment
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
1 parent 3a3c4a0 commit 2aa0924

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

‎src/statement/executed_async.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,8 @@ impl ExecutedAsyncStatement {
542542
// Payload before metadata keeps concurrent publications from mixing observations.
543543
let pending = self.pending_result.lock().ok();
544544
if let Ok(mut guard) = self.latest_status.lock() {
545-
if self.parameter_set_count != 0 && fresh.num_modified_rows.is_none() {
545+
// Scalar status enrichment cannot establish a whole-batch count.
546+
if self.parameter_set_count != 0 {
546547
fresh.num_modified_rows = guard.num_modified_rows;
547548
}
548549
*guard = fresh;

‎tests/v0_execute_wiremock.rs‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3840,6 +3840,53 @@ async fn native_batch_direct_and_async_use_aggregate_counts() {
38403840
assert_eq!(attached.num_modified_rows(), None);
38413841
assert_eq!(native_batch_requests(&server).await.len(), 1);
38423842
}
3843+
3844+
for (last_count, expected) in [(4, Some(6)), (-2, None)] {
3845+
let server = MockServer::start().await;
3846+
mount_create_session(&server).await;
3847+
mount_close_any_statement(&server).await;
3848+
let first = native_batch_counts(vec![Some(2)], None);
3849+
let last = native_batch_counts(vec![Some(last_count)], None);
3850+
let mut body: serde_json::Value =
3851+
serde_json::from_str(&succeeded_inline_body("batch-paged", &first)).unwrap();
3852+
body["manifest"]["total_chunk_count"] = json!(2);
3853+
body["manifest"]["total_row_count"] = json!(2);
3854+
body["result"]["next_chunk_index"] = json!(1);
3855+
mount_execute(&server, running_body("batch-paged")).await;
3856+
mount_status(&server, "batch-paged", body.to_string()).await;
3857+
Mock::given(method("GET"))
3858+
.and(path("/api/2.0/sql/statements/batch-paged/result/chunks/1"))
3859+
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
3860+
"chunk_index": 1, "row_offset": 1, "row_count": 1,
3861+
"attachment": STANDARD.encode(arrow_ipc_bytes(&last)),
3862+
})))
3863+
.mount(&server)
3864+
.await;
3865+
let session = open_session(&server).await;
3866+
let mut statement = session.statement();
3867+
statement.spec().sql("INSERT INTO t VALUES (?)");
3868+
for value in [11, 29] {
3869+
statement
3870+
.spec()
3871+
.param(1, TypedValue::Int64(value))
3872+
.unwrap()
3873+
.add_parameter_set();
3874+
}
3875+
let executed = statement.submit().await.unwrap();
3876+
executed.status().await.unwrap();
3877+
assert_eq!(executed.num_modified_rows(), None);
3878+
let _stream = executed.await_result().await.unwrap();
3879+
assert_eq!(executed.num_modified_rows(), expected);
3880+
assert_eq!(
3881+
executed.reader().unwrap().num_modified_rows().unwrap(),
3882+
expected
3883+
);
3884+
executed.status().await.unwrap();
3885+
assert_eq!(executed.num_modified_rows(), expected);
3886+
let _stream = executed.fetch_result().await.unwrap();
3887+
assert_eq!(executed.num_modified_rows(), expected);
3888+
assert_eq!(native_batch_requests(&server).await.len(), 1);
3889+
}
38433890
}
38443891

38453892
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]

0 commit comments

Comments
 (0)