Beispiel #1
0
func (r *BigQueryReader) bqClient() *bigquery.Client {
	if r.client == nil {
		if r.UnflattenResults {
			tmpTable := r.TmpTableName
			r.client = bigquery.New(r.config.JsonPemPath, bigquery.AllowLargeResults(true, tmpTable, false))
		} else {
			r.client = bigquery.New(r.config.JsonPemPath)
		}
		r.client.PrintDebug = false
	}
	return r.client
}
Beispiel #2
0
func main() {
	bqClient := client.New(JSON_PEM_PATH)
	query := "select * from publicdata:samples.shakespeare limit 500;"

	dataChan := make(chan client.Data)
	go bqClient.AsyncQuery(100, DATASET, PROJECTID, query, dataChan)

L:
	for {
		select {
		case d, ok := <-dataChan:
			if d.Err != nil {
				fmt.Println("Error with data: ", d.Err)
				break L
			}

			if d.Rows != nil && d.Headers != nil {
				fmt.Println("Got rows: ", len(d.Rows))
				fmt.Println("Headers: ", d.Headers)
			}

			if !ok {
				fmt.Println("Data channel closed")
				break L
			}
		}
	}
}
Beispiel #3
0
func (w *BigQueryWriter) bqClient() *bigquery.Client {
	if w.client == nil {
		w.client = bigquery.New(w.config.JsonPemPath)
		w.client.PrintDebug = true
		if w.fieldsForNewTable != nil {
			err := w.client.InsertNewTableIfDoesNotExist(w.config.ProjectID, w.config.DatasetID, w.tableName, w.fieldsForNewTable)
			if err != nil {
				// Only thrown if table existence could not be verified or if the table could not be created.
				panic(err)
			}
		}
	}
	return w.client
}
Beispiel #4
0
func main() {
	bqClient := client.New(JSON_PEM_PATH)

	// run a sync query
	query := "select * from publicdata:samples.shakespeare limit 100;"

	rows, headers, err := bqClient.Query("shakespeare", PROJECTID, query)
	if err != nil {
		fmt.Println("Error: ", err)
	} else {
		fmt.Println("Got rows: ", len(rows))
		fmt.Println("Headers: ", headers)
		fmt.Println("Rows: ", rows)
	}
}
Beispiel #5
0
func main() {
	bqClient := client.New(PEM_PATH, SERVICE_ACCOUNT_EMAIL, SERVICE_ACCOUNT_CLIENT_ID, SECRET)

	// run a sync query
	query := "select * from publicdata:samples.shakespeare limit 100;"

	rows, headers, err := bqClient.Query("shakespeare", DATASET, query)
	if err != nil {
		fmt.Println("Error: ", err)
	} else {
		fmt.Println("Got rows: ", len(rows))
		fmt.Println("Headers: ", headers)
		fmt.Println("Rows: ", rows)
	}
}
func main() {
	bqClient := client.New(JSON_PEM_PATH)

	fields := map[string]string{
		"name":       "STRING",
		"timestamp":  "INTEGER",
		"desc":       "STRING",
		"created_at": "TIMESTAMP",
	}

	tableName := "some_table_name"

	err := bqClient.InsertNewTable(PROJECTID, DATASETID, tableName, fields)
	if err != nil {
		fmt.Println("Table insert failed:", err)
	}
}