Go BigQuery创建计划查询

Go BigQuery创建计划查询,go,google-bigquery,Go,Google Bigquery,我试图在Go中创建一个调度DELETE查询,但在bigquery文档中找不到任何示例 在本文档中,他们提供的唯一示例是java和python。有没有关于如何在Go中创建日程查询的示例? 您可以在go库中找到示例。基本上这里有一些用法的例子 您应该创建一个TransferConfig,它是gcloud API的一部分,您也可以从Go使用它,即使它没有明确的文档记录 以下是实现此目标的方法: import ( datatransfer "cloud.google.com/go/bi

我试图在Go中创建一个调度
DELETE
查询,但在bigquery文档中找不到任何示例

在本文档中,他们提供的唯一示例是java和python。有没有关于如何在Go中创建日程查询的示例?

您可以在go库中找到示例。基本上这里有一些用法的例子

您应该创建一个
TransferConfig
,它是gcloud API的一部分,您也可以从
Go
使用它,即使它没有明确的文档记录

以下是实现此目标的方法:

import (
    datatransfer "cloud.google.com/go/bigquery/datatransfer/apiv1"
    "context"
    "fmt"
    structpb "github.com/golang/protobuf/ptypes/struct"
    datatransferpb "google.golang.org/genproto/googleapis/cloud/bigquery/datatransfer/v1"
)


func main() {
    projectID := "projectID"
    datasetID := "DatasetID"

    serviceAccountName := "serviceAccount@projectID.iam.gserviceaccount.com"
    ctx := context.Background()
    c, err := datatransfer.NewClient(ctx)
    if err != nil {
        panic(err)
    }

    transConf := &datatransferpb.TransferConfig{
        Name: "test",
        DisplayName: "TestQuery",
        DataSourceId: "scheduled_query",
        Destination: &datatransferpb.TransferConfig_DestinationDatasetId{
            DestinationDatasetId: datasetID,
        },
        Params: &structpb.Struct{
            Fields: map[string]*structpb.Value {
                "query": &structpb.Value {
                    Kind:  &structpb.Value_StringValue{ "DELETE FROM `datasetID.table` where field='Value' "},
            },
        },
    },
        Schedule: "every 15 minutes",
    }

    _, err = c.CreateTransferConfig(ctx, &datatransferpb.CreateTransferConfigRequest{
        Parent: fmt.Sprintf("projects/%s", projectID),
        TransferConfig: transConf,
        ServiceAccountName: serviceAccountName,
    })

    if err != nil {
        panic(err)
    }
}

我要试试这个。谢谢你,伙计!