Example #1
0
func printValues(ctx context.Context, it *bigquery.RowIterator) {
	// one-space padding.
	tw := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)

	for {
		var vals []bigquery.Value
		err := it.Next(&vals)
		if err == iterator.Done {
			break
		}
		if err != nil {
			fmt.Printf("err calling get: %v\n", err)
		}
		sep := ""
		for _, v := range vals {
			fmt.Fprintf(tw, "%s%v", sep, v)
			sep = "\t"
		}
		fmt.Fprintf(tw, "\n")
	}
	tw.Flush()
	fmt.Println()
}
// printResults prints results from a query to the Shakespeare dataset.
func printResults(w io.Writer, iter *bigquery.RowIterator) error {
	for {
		var row []bigquery.Value
		err := iter.Next(&row)
		if err == iterator.Done {
			return nil
		}
		if err != nil {
			return err
		}

		fmt.Fprintln(w, "titles:")
		ts := row[0].([]bigquery.Value)
		for _, t := range ts {
			record := t.([]bigquery.Value)
			title := record[0].(string)
			cnt := record[1].(int64)
			fmt.Fprintf(w, "\t%s: %d\n", title, cnt)
		}

		words := row[1].(int64)
		fmt.Fprintf(w, "total unique words: %d\n", words)
	}
}