bigquery: address issue with RowIterator behavior

Existing behavior for row iterators was to nil out the pagefetcher
when reading a table/result with zero rows.  While fine for the
normal iteration case, this causes issues when wrapping an iterator in a
pager.

This change drops the special case behavior, at the (potential) cost
of a unnecessary roundtrip for zero result queries.

This change also adds some simple literal testing to verify behavior,
since we do not currently do much testing for corner cases like zero
result queries.

Fixes: #1642

Change-Id: I919840af660903940fa0f60e6afd5e2d9cc39d19
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/47910
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tyler Bui-Palsulich <tbp@google.com>
Reviewed-by: Jean de Klerk <deklerk@google.com>
diff --git a/bigquery/integration_test.go b/bigquery/integration_test.go
index a86000c..7fb3eae 100644
--- a/bigquery/integration_test.go
+++ b/bigquery/integration_test.go
@@ -794,6 +794,50 @@
 	}
 }
 
+func TestIntegration_SimpleRowResults(t *testing.T) {
+	if client == nil {
+		t.Skip("Integration tests skipped")
+	}
+	ctx := context.Background()
+
+	testCases := []struct {
+		description string
+		query       string
+		want        [][]Value
+	}{
+		{
+			description: "literals",
+			query:       "select 17 as foo",
+			want:        [][]Value{{int64(17)}},
+		},
+		{
+			description: "empty results",
+			query:       "SELECT * FROM (select 17 as foo) where false",
+			want:        [][]Value{},
+		},
+		{
+			// Note: currently CTAS returns the rows due to the destination table reference,
+			// but it's not clear that it should.
+			// https://github.com/googleapis/google-cloud-go/issues/1467 for followup.
+			description: "ctas ddl",
+			query:       fmt.Sprintf("CREATE TABLE %s.%s AS SELECT 17 as foo", dataset.DatasetID, tableIDs.New()),
+			want:        [][]Value{{int64(17)}},
+		},
+	}
+	for _, tc := range testCases {
+		curCase := tc
+		t.Run(curCase.description, func(t *testing.T) {
+			t.Parallel()
+			q := client.Query(curCase.query)
+			it, err := q.Read(ctx)
+			if err != nil {
+				t.Fatalf("%s read error: %v", curCase.description, err)
+			}
+			checkReadAndTotalRows(t, curCase.description, it, curCase.want)
+		})
+	}
+}
+
 func TestIntegration_InsertAndRead(t *testing.T) {
 	if client == nil {
 		t.Skip("Integration tests skipped")
diff --git a/bigquery/job.go b/bigquery/job.go
index 596154d..6a51973 100644
--- a/bigquery/job.go
+++ b/bigquery/job.go
@@ -298,9 +298,6 @@
 		return nil, errors.New("bigquery: query job missing destination table")
 	}
 	dt := bqToTable(destTable, j.c)
-	if totalRows == 0 {
-		pf = nil
-	}
 	it := newRowIterator(ctx, dt, pf)
 	it.Schema = schema
 	it.TotalRows = totalRows