@@ -31,7 +31,7 @@ use arrow_ipc::writer::StreamWriter;
3131use arrow_schema:: { DataType , Field , Fields , Schema } ;
3232use base64:: { engine:: general_purpose:: STANDARD , Engine } ;
3333use databricks_sql_kernel:: {
34- AuthConfig , ConnectionConfig , ErrorCode , ExecutedStatementHandle ,
34+ AuthConfig , ConnectionConfig , DirectStatement , ErrorCode , ExecutedStatementHandle ,
3535 GeospatialResultRepresentation , HttpConfig , ResultBatch , ResultConfig , Session , TryNextBatch ,
3636 TypedValue , MAX_CLIENT_QUERY_TIMEOUT ,
3737} ;
@@ -2217,6 +2217,51 @@ async fn polling_path_carries_terminal_status_not_initial() {
22172217 exec. close ( ) . await . expect ( "close" ) ;
22182218}
22192219
2220+ #[ tokio:: test]
2221+ async fn execute_direct_populates_dml_counts_without_consuming_results ( ) {
2222+ for state in [ "SUCCEEDED" , "CLOSED" ] {
2223+ for ( batch, reported_count, expected_count) in [
2224+ ( int64_batch ( "num_affected_rows" , vec ! [ 2 ] ) , None , Some ( 2 ) ) ,
2225+ ( int64_batch ( "num_affected_rows" , vec ! [ 0 ] ) , None , Some ( 0 ) ) ,
2226+ ( dml_count_batch ( 9 , 4 , 3 , 2 ) , None , Some ( 9 ) ) ,
2227+ ( int64_batch ( "num_affected_rows" , vec ! [ 2 ] ) , Some ( 7 ) , Some ( 7 ) ) ,
2228+ ( int64_batch ( "n" , vec ! [ 1 ] ) , None , None ) ,
2229+ ] {
2230+ let server = MockServer :: start ( ) . await ;
2231+ mount_create_session ( & server) . await ;
2232+ mount_delete_session ( & server) . await ;
2233+ mount_close_any_statement ( & server) . await ;
2234+
2235+ let mut body: serde_json:: Value =
2236+ serde_json:: from_str ( & succeeded_inline_body_with_status (
2237+ "stmt-direct-count" ,
2238+ & batch,
2239+ reported_count,
2240+ None ,
2241+ None ,
2242+ None ,
2243+ ) )
2244+ . unwrap ( ) ;
2245+ body[ "status" ] [ "state" ] = json ! ( state) ;
2246+ mount_execute ( & server, body. to_string ( ) ) . await ;
2247+
2248+ let session = open_session ( & server) . await ;
2249+ let mut stmt = session. statement ( ) ;
2250+ stmt. spec ( ) . sql ( "UPDATE t SET x = x + 1" ) ;
2251+ let DirectStatement :: Completed ( mut exec) = stmt. execute_direct ( ) . await . unwrap ( ) else {
2252+ panic ! ( "inline {state} result must return a completed statement" ) ;
2253+ } ;
2254+
2255+ assert_eq ! ( exec. num_modified_rows( ) , expected_count) ;
2256+ let batches = drain ( exec. result_stream_mut ( ) ) . await ;
2257+ assert_eq ! ( batches. len( ) , 1 ) ;
2258+ assert_eq ! ( batches[ 0 ] . columns( ) , batch. columns( ) ) ;
2259+ assert_eq ! ( exec. num_modified_rows( ) , expected_count) ;
2260+ exec. close ( ) . await . expect ( "close" ) ;
2261+ }
2262+ }
2263+ }
2264+
22202265#[ tokio:: test]
22212266async fn polling_path_materializes_dml_count_after_terminal_state ( ) {
22222267 // The synchronous poll loop deliberately reads raw status responses. DML
0 commit comments