Skip to content

Commit 7295fce

Browse files
committed
krn-status-fields: expose 5 status accessors on ExecutedStatement
Adds num_modified_rows(), progress(), display_message(), diagnostic_info(), and error_details_json() getters on ExecutedStatement. Data is parsed from the SEA GET /sql/statements/{id} response in client/sea.rs; this commit only exposes the accessors so the napi binding (and Python pyo3 binding) can surface them. Structural change: the wire-protocol StatementStatus in types/sea.rs was previously decoding only `state` and `error`; the five new fields are added as `Option<...>` behind `#[serde(default)]` so they remain backward- compatible with the absent-field SEA responses today's classic-warehouse fixtures emit. The status struct flows through ExecuteResult (already carrying manifest) into ExecutedStatement, which stores it once at construction and hands out cheap field-level accessors. Unblocks NodeJS Operation.status() field synthesis (feature-tracker line 39 / kernel carry-over row). Tests: - types::sea::tests::test_statement_status_with_extended_fields - types::sea::tests::test_statement_status_extended_fields_absent - tests/v0_execute_wiremock::executed_statement_surfaces_extended_status_fields - tests/v0_execute_wiremock::executed_statement_status_fields_default_to_none Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
1 parent 1ff2cf5 commit 7295fce

7 files changed

Lines changed: 300 additions & 22 deletions

File tree

‎src/client/sea.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,16 @@ impl SeaRestTransport {
380380
.create_reader(&response.statement_id, &response)
381381
.await?;
382382

383-
// `server_state` carries the terminal state forward so the
384-
// executed handle can skip a redundant CloseStatement when
385-
// the server already cleaned up (state=Closed).
386-
let server_state = response.status.state;
383+
// The full `status` is carried forward so the executed handle
384+
// can skip a redundant CloseStatement when the server already
385+
// cleaned up (status.state=Closed) AND expose
386+
// num_modified_rows / progress / etc. without a second
387+
// GetStatementStatus round-trip.
387388
Ok(ExecuteResult {
388389
statement_id: response.statement_id,
389390
reader,
390391
manifest: response.manifest,
391-
server_state,
392+
status: response.status,
392393
})
393394
}
394395
}
@@ -521,12 +522,11 @@ impl Transport for SeaRestTransport {
521522
StatementOutcome::Done(r) => {
522523
let reader_factory = self.reader_factory()?;
523524
let reader = reader_factory.create_reader(&r.statement_id, &r).await?;
524-
let server_state = r.status.state;
525525
Ok(Some(ExecuteResult {
526526
statement_id: r.statement_id,
527527
reader,
528528
manifest: r.manifest,
529-
server_state,
529+
status: r.status,
530530
}))
531531
}
532532
StatementOutcome::NotReady(_) => Ok(None),

‎src/client/transport.rs‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,30 @@ pub(crate) struct SessionInfo {
6767

6868
/// Result from [`Transport::execute_statement`]. Contains the
6969
/// statement ID (for cancellation/cleanup), a reader over the result
70-
/// data, and optionally the SEA manifest for metadata propagation.
70+
/// data, optionally the SEA manifest for metadata propagation, and
71+
/// the terminal `StatementStatus` so callers can surface
72+
/// `num_modified_rows` / `progress` / etc. without a second
73+
/// GetStatementStatus round-trip.
7174
pub(crate) struct ExecuteResult {
7275
pub statement_id: String,
7376
pub reader: Box<dyn ResultReader + Send>,
7477
pub manifest: Option<ResultManifest>,
75-
/// Terminal state the server reported in its final response.
76-
/// `Closed` means the server has already cleaned up the
77-
/// statement on its end — the kernel must NOT issue a
78+
/// Terminal status the server reported in its final response.
79+
///
80+
/// `status.state == Closed` means the server has already cleaned
81+
/// up the statement on its end — the kernel must NOT issue a
7882
/// separate `CloseStatement` for it (the server returns 404
79-
/// `STATEMENT_NOT_FOUND` on such redundant closes). This is
80-
/// the common case when the kernel omits `wait_timeout` from
81-
/// the execute request: the server holds the connection for
82-
/// its default wait, returns inline data with `state=CLOSED`,
83-
/// and is done. Setting a concrete `wait_timeout` yields
84-
/// `Succeeded` instead and requires an explicit close.
85-
pub server_state: StatementState,
83+
/// `STATEMENT_NOT_FOUND` on such redundant closes). This is the
84+
/// common case when the kernel omits `wait_timeout` from the
85+
/// execute request: the server holds the connection for its
86+
/// default wait, returns inline data with `state=CLOSED`, and is
87+
/// done. Setting a concrete `wait_timeout` yields `Succeeded`
88+
/// instead and requires an explicit close.
89+
///
90+
/// The full status is carried (not just the state) so the
91+
/// `ExecutedStatement` can expose `num_modified_rows` / `progress`
92+
/// / etc. without a second GetStatementStatus round-trip.
93+
pub status: StatementStatus,
8694
}
8795

8896
impl std::fmt::Debug for ExecuteResult {
@@ -91,7 +99,7 @@ impl std::fmt::Debug for ExecuteResult {
9199
.field("statement_id", &self.statement_id)
92100
.field("reader", &"<dyn ResultReader>")
93101
.field("manifest", &self.manifest)
94-
.field("server_state", &self.server_state)
102+
.field("status", &self.status)
95103
.finish()
96104
}
97105
}

‎src/reader/cloudfetch/link_fetcher.rs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ mod tests {
547547
use super::*;
548548
use crate::client::{ExecuteResult, SessionInfo};
549549
use crate::reader::EmptyReader;
550-
use crate::types::sea::{ExecuteParams, StatementState};
550+
use crate::types::sea::{ExecuteParams, StatementState, StatementStatus};
551551
use arrow_schema::Schema;
552552
use std::collections::HashMap;
553553
use std::sync::Arc as StdArc;
@@ -591,7 +591,15 @@ mod tests {
591591
statement_id: "mock-statement".to_string(),
592592
reader: Box::new(EmptyReader::new(StdArc::new(Schema::empty()))),
593593
manifest: None,
594-
server_state: StatementState::Succeeded,
594+
status: StatementStatus {
595+
state: StatementState::Succeeded,
596+
error: None,
597+
num_modified_rows: None,
598+
progress: None,
599+
display_message: None,
600+
diagnostic_info: None,
601+
error_details_json: None,
602+
},
595603
})
596604
}
597605

‎src/statement/executed.rs‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use crate::result_stream::{ResultStream, SchemaRef};
3333
use crate::session::SessionInner;
3434
use crate::statement::handle::ExecutedStatementHandle;
3535
use crate::statement::validity::ValidityFlag;
36+
use crate::types::sea::StatementStatus as SeaStatementStatus;
3637
use async_trait::async_trait;
3738
use std::sync::atomic::{AtomicBool, Ordering};
3839
use std::sync::Arc;
@@ -47,6 +48,11 @@ pub struct ExecutedStatement {
4748
/// stale calls locally with no network round-trip.
4849
valid: ValidityFlag,
4950
result_stream: ResultStream,
51+
/// Terminal SEA `StatementStatus` captured at construction.
52+
/// Kept as the wire-shape struct so the accessor methods can
53+
/// hand back individual fields without re-querying the server.
54+
/// Mutated only at construction; no interior mutability.
55+
status: SeaStatementStatus,
5056
/// Flips to `true` after the first successful (or the first
5157
/// duplicate-call short-circuited) `close()`. Tells `Drop` to
5258
/// skip its fire-and-forget cleanup so an explicit close
@@ -69,13 +75,15 @@ impl ExecutedStatement {
6975
valid: ValidityFlag,
7076
result_stream: ResultStream,
7177
closed: Arc<AtomicBool>,
78+
status: SeaStatementStatus,
7279
) -> Self {
7380
Self {
7481
session,
7582
statement_id,
7683
valid,
7784
result_stream,
7885
closed,
86+
status,
7987
}
8088
}
8189

@@ -101,6 +109,42 @@ impl ExecutedStatement {
101109
pub fn result_stream_mut(&mut self) -> &mut ResultStream {
102110
&mut self.result_stream
103111
}
112+
113+
/// Rows modified by the statement (UPDATE / INSERT / DELETE /
114+
/// MERGE). Absent for SELECT and on warehouses that don't surface
115+
/// the counter.
116+
pub fn num_modified_rows(&self) -> Option<i64> {
117+
self.status.num_modified_rows
118+
}
119+
120+
/// Fractional completion in `[0.0, 1.0]`. Populated on analytics
121+
/// warehouses; absent elsewhere. On a terminal `ExecutedStatement`
122+
/// this is typically `Some(1.0)` when populated at all.
123+
pub fn progress(&self) -> Option<f64> {
124+
self.status.progress
125+
}
126+
127+
/// Server-supplied user-facing message. Distinct from the
128+
/// `error.message` carried inside `Failed` — populated on
129+
/// non-error states too (e.g. cancellation reasons, progress
130+
/// hints).
131+
pub fn display_message(&self) -> Option<&str> {
132+
self.status.display_message.as_deref()
133+
}
134+
135+
/// Server-supplied diagnostic detail — multi-line text with
136+
/// stack frames or operator context. Intended for log / support
137+
/// surfaces; not user-facing.
138+
pub fn diagnostic_info(&self) -> Option<&str> {
139+
self.status.diagnostic_info.as_deref()
140+
}
141+
142+
/// Server-supplied JSON blob with extended error details.
143+
/// Pass-through string — wrappers parse if they need structured
144+
/// access.
145+
pub fn error_details_json(&self) -> Option<&str> {
146+
self.status.error_details_json.as_deref()
147+
}
104148
}
105149

106150
#[async_trait]

‎src/statement/mutable.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl Statement {
174174
// path. See `prepare_for_dispatch` for why omitting
175175
// `wait_timeout` typically yields `Closed` on the inline-result
176176
// fast path.
177-
let already_closed = result.server_state == StatementState::Closed;
177+
let already_closed = result.status.state == StatementState::Closed;
178178
let closed = Arc::new(AtomicBool::new(already_closed));
179179
self.last_statement_id = Some(result.statement_id.clone());
180180
self.last_valid = Some(valid.clone());
@@ -187,6 +187,7 @@ impl Statement {
187187
valid,
188188
result_stream,
189189
closed,
190+
result.status,
190191
))
191192
}
192193
.instrument(span)

‎src/types/sea.rs‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ pub struct StatementStatus {
3838
pub state: StatementState,
3939
#[serde(default)]
4040
pub error: Option<ServiceError>,
41+
/// Number of rows modified by the statement (UPDATE / INSERT /
42+
/// DELETE / MERGE). Absent on SELECT and on warehouses that don't
43+
/// surface the counter.
44+
#[serde(default)]
45+
pub num_modified_rows: Option<i64>,
46+
/// Fractional completion in `[0.0, 1.0]`. Populated on analytics
47+
/// warehouses; absent (or always 1.0 on terminal) elsewhere.
48+
#[serde(default)]
49+
pub progress: Option<f64>,
50+
/// Server-supplied user-facing message (e.g. "Statement was
51+
/// canceled by the user" or progress hints). Distinct from
52+
/// `error.message`; populated on non-error states too.
53+
#[serde(default)]
54+
pub display_message: Option<String>,
55+
/// Server-supplied diagnostic detail — multi-line text with
56+
/// stack frames or operator context. Intended for log / support
57+
/// surfaces, not user-facing strings.
58+
#[serde(default)]
59+
pub diagnostic_info: Option<String>,
60+
/// Server-supplied JSON blob with extended error details.
61+
/// Pass-through string — wrappers parse if they need structured
62+
/// access.
63+
#[serde(default)]
64+
pub error_details_json: Option<String>,
4165
}
4266

4367
/// Possible states of a statement during execution.
@@ -492,6 +516,56 @@ mod tests {
492516
assert_eq!(manifest.total_row_count, Some(0));
493517
}
494518

519+
#[test]
520+
fn test_statement_status_with_extended_fields() {
521+
// SEA response with all five extended status fields populated.
522+
let json = r#"{
523+
"statement_id": "stmt-extended",
524+
"status": {
525+
"state": "SUCCEEDED",
526+
"num_modified_rows": 42,
527+
"progress": 0.875,
528+
"display_message": "Statement completed",
529+
"diagnostic_info": "operator=Scan; rows=42",
530+
"error_details_json": "{\"trace\":\"...\"}"
531+
}
532+
}"#;
533+
534+
let response: StatementExecutionResponse = serde_json::from_str(json).unwrap();
535+
assert_eq!(response.status.state, StatementState::Succeeded);
536+
assert_eq!(response.status.num_modified_rows, Some(42));
537+
assert_eq!(response.status.progress, Some(0.875));
538+
assert_eq!(
539+
response.status.display_message,
540+
Some("Statement completed".to_string())
541+
);
542+
assert_eq!(
543+
response.status.diagnostic_info,
544+
Some("operator=Scan; rows=42".to_string())
545+
);
546+
assert_eq!(
547+
response.status.error_details_json,
548+
Some(r#"{"trace":"..."}"#.to_string())
549+
);
550+
}
551+
552+
#[test]
553+
fn test_statement_status_extended_fields_absent() {
554+
// Minimal SEA response — extended fields are optional and
555+
// default to None when the server omits them.
556+
let json = r#"{
557+
"statement_id": "stmt-min",
558+
"status": { "state": "SUCCEEDED" }
559+
}"#;
560+
561+
let response: StatementExecutionResponse = serde_json::from_str(json).unwrap();
562+
assert_eq!(response.status.num_modified_rows, None);
563+
assert_eq!(response.status.progress, None);
564+
assert_eq!(response.status.display_message, None);
565+
assert_eq!(response.status.diagnostic_info, None);
566+
assert_eq!(response.status.error_details_json, None);
567+
}
568+
495569
#[test]
496570
fn test_column_info_with_interval_type() {
497571
let json = r#"{

0 commit comments

Comments
 (0)