@@ -479,7 +479,7 @@ func TestIntegration_SnapshotAndRestore(t *testing.T) {
479
479
FROM
480
480
UNNEST(GENERATE_ARRAY(0,999))
481
481
` , qualified )
482
- if err := runQueryJob (ctx , sql ); err != nil {
482
+ if _ , err := runQueryJob (ctx , sql ); err != nil {
483
483
t .Fatalf ("couldn't instantiate base table: %v" , err )
484
484
}
485
485
@@ -872,7 +872,7 @@ func TestIntegration_DatasetUpdateAccess(t *testing.T) {
872
872
sql := fmt .Sprintf (`
873
873
CREATE FUNCTION ` + "`%s`" + `(x INT64) AS (x * 3);` ,
874
874
routine .FullyQualifiedName ())
875
- if err := runQueryJob (ctx , sql ); err != nil {
875
+ if _ , err := runQueryJob (ctx , sql ); err != nil {
876
876
t .Fatal (err )
877
877
}
878
878
defer routine .Delete (ctx )
@@ -1288,7 +1288,7 @@ func TestIntegration_RoutineStoredProcedure(t *testing.T) {
1288
1288
END` ,
1289
1289
routine .FullyQualifiedName ())
1290
1290
1291
- if err := runQueryJob (ctx , sql ); err != nil {
1291
+ if _ , err := runQueryJob (ctx , sql ); err != nil {
1292
1292
t .Fatal (err )
1293
1293
}
1294
1294
defer routine .Delete (ctx )
@@ -2013,7 +2013,8 @@ func TestIntegration_DML(t *testing.T) {
2013
2013
('b', [1], STRUCT<BOOL>(FALSE)),
2014
2014
('c', [2], STRUCT<BOOL>(TRUE))` ,
2015
2015
table .DatasetID , table .TableID )
2016
- if err := runQueryJob (ctx , sql ); err != nil {
2016
+ stats , err := runQueryJob (ctx , sql )
2017
+ if err != nil {
2017
2018
t .Fatal (err )
2018
2019
}
2019
2020
wantRows := [][]Value {
@@ -2022,11 +2023,23 @@ func TestIntegration_DML(t *testing.T) {
2022
2023
{"c" , []Value {int64 (2 )}, []Value {true }},
2023
2024
}
2024
2025
checkRead (t , "DML" , table .Read (ctx ), wantRows )
2026
+ if stats == nil {
2027
+ t .Fatalf ("no query stats" )
2028
+ }
2029
+ if stats .DMLStats == nil {
2030
+ t .Fatalf ("no dml stats" )
2031
+ }
2032
+ wantRowCount := int64 (len (wantRows ))
2033
+ if stats .DMLStats .InsertedRowCount != wantRowCount {
2034
+ t .Fatalf ("dml stats mismatch. got %d inserted rows, want %d" , stats .DMLStats .InsertedRowCount , wantRowCount )
2035
+ }
2025
2036
}
2026
2037
2027
2038
// runQueryJob is useful for running queries where no row data is returned (DDL/DML).
2028
- func runQueryJob (ctx context.Context , sql string ) error {
2029
- return internal .Retry (ctx , gax.Backoff {}, func () (stop bool , err error ) {
2039
+ func runQueryJob (ctx context.Context , sql string ) (* QueryStatistics , error ) {
2040
+ var stats * QueryStatistics
2041
+ var err error
2042
+ err = internal .Retry (ctx , gax.Backoff {}, func () (stop bool , err error ) {
2030
2043
job , err := client .Query (sql ).Run (ctx )
2031
2044
if err != nil {
2032
2045
if e , ok := err .(* googleapi.Error ); ok && e .Code < 500 {
@@ -2041,8 +2054,15 @@ func runQueryJob(ctx context.Context, sql string) error {
2041
2054
}
2042
2055
return false , err
2043
2056
}
2057
+ status := job .LastStatus ()
2058
+ if status .Statistics != nil {
2059
+ if qStats , ok := status .Statistics .Details .(* QueryStatistics ); ok {
2060
+ stats = qStats
2061
+ }
2062
+ }
2044
2063
return true , nil
2045
2064
})
2065
+ return stats , err
2046
2066
}
2047
2067
2048
2068
func TestIntegration_TimeTypes (t * testing.T ) {
@@ -2082,7 +2102,7 @@ func TestIntegration_TimeTypes(t *testing.T) {
2082
2102
"VALUES ('%s', '%s', '%s', '%s')" ,
2083
2103
table .DatasetID , table .TableID ,
2084
2104
d , CivilTimeString (tm ), CivilDateTimeString (dtm ), ts .Format ("2006-01-02 15:04:05" ))
2085
- if err := runQueryJob (ctx , query ); err != nil {
2105
+ if _ , err := runQueryJob (ctx , query ); err != nil {
2086
2106
t .Fatal (err )
2087
2107
}
2088
2108
wantRows = append (wantRows , wantRows [0 ])
@@ -2506,7 +2526,7 @@ func TestIntegration_ExtractExternal(t *testing.T) {
2506
2526
sql := fmt .Sprintf (`INSERT %s.%s (name, num)
2507
2527
VALUES ('a', 1), ('b', 2), ('c', 3)` ,
2508
2528
table .DatasetID , table .TableID )
2509
- if err := runQueryJob (ctx , sql ); err != nil {
2529
+ if _ , err := runQueryJob (ctx , sql ); err != nil {
2510
2530
t .Fatal (err )
2511
2531
}
2512
2532
// Extract to a GCS object as CSV.
@@ -2932,7 +2952,7 @@ func TestIntegration_MaterializedViewLifecycle(t *testing.T) {
2932
2952
FROM
2933
2953
UNNEST(GENERATE_ARRAY(0,999))
2934
2954
` , qualified )
2935
- if err := runQueryJob (ctx , sql ); err != nil {
2955
+ if _ , err := runQueryJob (ctx , sql ); err != nil {
2936
2956
t .Fatalf ("couldn't instantiate base table: %v" , err )
2937
2957
}
2938
2958
@@ -3060,7 +3080,7 @@ func TestIntegration_ModelLifecycle(t *testing.T) {
3060
3080
UNION ALL
3061
3081
SELECT 'b' AS f1, 3.8 AS label
3062
3082
)` , modelRef )
3063
- if err := runQueryJob (ctx , sql ); err != nil {
3083
+ if _ , err := runQueryJob (ctx , sql ); err != nil {
3064
3084
t .Fatal (err )
3065
3085
}
3066
3086
defer model .Delete (ctx )
@@ -3243,7 +3263,7 @@ func TestIntegration_RoutineComplexTypes(t *testing.T) {
3243
3263
(SELECT SUM(IF(elem.name = "foo",elem.val,null)) FROM UNNEST(arr) AS elem)
3244
3264
)` ,
3245
3265
routine .FullyQualifiedName ())
3246
- if err := runQueryJob (ctx , sql ); err != nil {
3266
+ if _ , err := runQueryJob (ctx , sql ); err != nil {
3247
3267
t .Fatal (err )
3248
3268
}
3249
3269
defer routine .Delete (ctx )
@@ -3303,7 +3323,7 @@ func TestIntegration_RoutineLifecycle(t *testing.T) {
3303
3323
sql := fmt .Sprintf (`
3304
3324
CREATE FUNCTION ` + "`%s`" + `(x INT64) AS (x * 3);` ,
3305
3325
routine .FullyQualifiedName ())
3306
- if err := runQueryJob (ctx , sql ); err != nil {
3326
+ if _ , err := runQueryJob (ctx , sql ); err != nil {
3307
3327
t .Fatal (err )
3308
3328
}
3309
3329
defer routine .Delete (ctx )
0 commit comments