@@ -2762,6 +2762,78 @@ func TestIntegration_ExtractExternal(t *testing.T) {
2762
2762
}
2763
2763
}
2764
2764
2765
+ func TestIntegration_ExportDataStatistics (t * testing.T ) {
2766
+ // Create a table, extract it to GCS using EXPORT DATA statement.
2767
+ if client == nil {
2768
+ t .Skip ("Integration tests skipped" )
2769
+ }
2770
+ ctx := context .Background ()
2771
+ schema := Schema {
2772
+ {Name : "name" , Type : StringFieldType },
2773
+ {Name : "num" , Type : IntegerFieldType },
2774
+ }
2775
+ table := newTable (t , schema )
2776
+ defer table .Delete (ctx )
2777
+
2778
+ // Extract to a GCS object as CSV.
2779
+ bucketName := testutil .ProjID ()
2780
+ uri := fmt .Sprintf ("gs://%s/bq-export-test-*.csv" , bucketName )
2781
+ defer func () {
2782
+ it := storageClient .Bucket (bucketName ).Objects (ctx , & storage.Query {
2783
+ MatchGlob : "bq-export-test-*.csv" ,
2784
+ })
2785
+ for {
2786
+ obj , err := it .Next ()
2787
+ if err == iterator .Done {
2788
+ break
2789
+ }
2790
+ if err != nil {
2791
+ t .Logf ("failed to delete bucket: %v" , err )
2792
+ continue
2793
+ }
2794
+ err = storageClient .Bucket (bucketName ).Object (obj .Name ).Delete (ctx )
2795
+ t .Logf ("deleted object %s: %v" , obj .Name , err )
2796
+ }
2797
+ }()
2798
+
2799
+ // EXPORT DATA to GCS object.
2800
+ sql := fmt .Sprintf (`EXPORT DATA
2801
+ OPTIONS (
2802
+ uri = '%s',
2803
+ format = 'CSV',
2804
+ overwrite = true,
2805
+ header = true,
2806
+ field_delimiter = ';'
2807
+ )
2808
+ AS (
2809
+ SELECT 'a' as name, 1 as num
2810
+ UNION ALL
2811
+ SELECT 'b' as name, 2 as num
2812
+ UNION ALL
2813
+ SELECT 'c' as name, 3 as num
2814
+ );` ,
2815
+ uri )
2816
+ stats , _ , err := runQuerySQL (ctx , sql )
2817
+ if err != nil {
2818
+ t .Fatal (err )
2819
+ }
2820
+
2821
+ qStats , ok := stats .Details .(* QueryStatistics )
2822
+ if ! ok {
2823
+ t .Fatalf ("expected query statistics not present" )
2824
+ }
2825
+
2826
+ if qStats .ExportDataStatistics == nil {
2827
+ t .Fatal ("jobStatus missing ExportDataStatistics" )
2828
+ }
2829
+ if qStats .ExportDataStatistics .FileCount != 1 {
2830
+ t .Fatalf ("expected ExportDataStatistics to have 1 file, but got %d files" , qStats .ExportDataStatistics .FileCount )
2831
+ }
2832
+ if qStats .ExportDataStatistics .RowCount != 3 {
2833
+ t .Fatalf ("expected ExportDataStatistics to have 3 rows, got %d rows" , qStats .ExportDataStatistics .RowCount )
2834
+ }
2835
+ }
2836
+
2765
2837
func TestIntegration_ReadNullIntoStruct (t * testing.T ) {
2766
2838
// Reading a null into a struct field should return an error (not panic).
2767
2839
if client == nil {
0 commit comments