本文整理匯總了Golang中cloud/google/com/go/bigquery.Client.Dataset方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Dataset方法的具體用法?Golang Client.Dataset怎麽用?Golang Client.Dataset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cloud/google/com/go/bigquery.Client
的用法示例。
在下文中一共展示了Client.Dataset方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: importFromFile
func importFromFile(client *bigquery.Client, datasetID, tableID, filename string) error {
ctx := context.Background()
// [START bigquery_import_from_file]
f, err := os.Open(filename)
if err != nil {
return err
}
source := bigquery.NewReaderSource(f)
source.AllowJaggedRows = true
// TODO: set other options on the GCSReference.
loader := client.Dataset(datasetID).Table(tableID).LoaderFrom(source)
loader.CreateDisposition = bigquery.CreateNever
// TODO: set other options on the Loader.
job, err := loader.Run(ctx)
if err != nil {
return err
}
status, err := job.Wait(ctx)
if err != nil {
return err
}
if err := status.Err(); err != nil {
return err
}
// [END bigquery_import_from_file]
return nil
}
示例2: importFromGCS
func importFromGCS(client *bigquery.Client, datasetID, tableID, gcsURI string) error {
ctx := context.Background()
// [START bigquery_import_from_gcs]
// For example, "gs://data-bucket/path/to/data.csv"
gcsRef := bigquery.NewGCSReference(gcsURI)
gcsRef.AllowJaggedRows = true
// TODO: set other options on the GCSReference.
loader := client.Dataset(datasetID).Table(tableID).LoaderFrom(gcsRef)
loader.CreateDisposition = bigquery.CreateNever
// TODO: set other options on the Loader.
job, err := loader.Run(ctx)
if err != nil {
return err
}
status, err := job.Wait(ctx)
if err != nil {
return err
}
if err := status.Err(); err != nil {
return err
}
// [END bigquery_import_from_gcs]
return nil
}
示例3: createDataset
func createDataset(client *bigquery.Client, datasetID string) error {
ctx := context.Background()
// [START bigquery_create_dataset]
if err := client.Dataset(datasetID).Create(ctx); err != nil {
return err
}
// [END bigquery_create_dataset]
return nil
}
示例4: deleteTable
func deleteTable(client *bigquery.Client, datasetID, tableID string) error {
ctx := context.Background()
// [START bigquery_delete_table]
table := client.Dataset(datasetID).Table(tableID)
if err := table.Delete(ctx); err != nil {
return err
}
// [END bigquery_delete_table]
return nil
}
示例5: createTable
func createTable(client *bigquery.Client, datasetID, tableID string) error {
ctx := context.Background()
// [START bigquery_create_table]
schema, err := bigquery.InferSchema(Item{})
if err != nil {
return err
}
table := client.Dataset(datasetID).Table(tableID)
if err := table.Create(ctx, schema); err != nil {
return err
}
// [END bigquery_create_table]
return nil
}
示例6: insertRows
func insertRows(client *bigquery.Client, datasetID, tableID string) error {
ctx := context.Background()
// [START bigquery_insert_stream]
u := client.Dataset(datasetID).Table(tableID).Uploader()
items := []*Item{
// Item implements the ValueSaver interface.
{Name: "n1", Count: 7},
{Name: "n2", Count: 2},
{Name: "n3", Count: 1},
}
if err := u.Put(ctx, items); err != nil {
return err
}
// [END bigquery_insert_stream]
return nil
}
示例7: listTables
func listTables(client *bigquery.Client, w io.Writer, datasetID string) error {
ctx := context.Background()
// [START bigquery_list_tables]
ts := client.Dataset(datasetID).Tables(ctx)
for {
t, err := ts.Next()
if err == iterator.Done {
break
}
if err != nil {
return err
}
fmt.Fprintf(w, "Table: %q\n", t.TableID)
}
// [END bigquery_list_tables]
return nil
}
示例8: browseTable
func browseTable(client *bigquery.Client, datasetID, tableID string) error {
ctx := context.Background()
// [START bigquery_browse_table]
table := client.Dataset(datasetID).Table(tableID)
it := table.Read(ctx)
for {
var row []bigquery.Value
err := it.Next(&row)
if err == iterator.Done {
break
}
if err != nil {
return err
}
fmt.Println(row)
}
// [END bigquery_browse_table]
return nil
}
示例9: copyTable
func copyTable(client *bigquery.Client, datasetID, srcID, dstID string) error {
ctx := context.Background()
// [START bigquery_copy_table]
dataset := client.Dataset(datasetID)
copier := dataset.Table(dstID).CopierFrom(dataset.Table(srcID))
copier.WriteDisposition = bigquery.WriteTruncate
job, err := copier.Run(ctx)
if err != nil {
return err
}
status, err := job.Wait(ctx)
if err != nil {
return err
}
if err := status.Err(); err != nil {
return err
}
// [END bigquery_copy_table]
return nil
}
示例10: exportToGCS
func exportToGCS(client *bigquery.Client, datasetID, tableID, gcsURI string) error {
ctx := context.Background()
// [START bigquery_export_gcs]
// For example, "gs://data-bucket/path/to/data.csv"
gcsRef := bigquery.NewGCSReference(gcsURI)
gcsRef.FieldDelimiter = ","
extractor := client.Dataset(datasetID).Table(tableID).ExtractorTo(gcsRef)
extractor.DisableHeader = true
job, err := extractor.Run(ctx)
if err != nil {
return err
}
status, err := job.Wait(ctx)
if err != nil {
return err
}
if err := status.Err(); err != nil {
return err
}
// [END bigquery_export_gcs]
return nil
}