【问题标题】:Sample Code for Using the Google BigQuery C# API library使用 Google BigQuery C# API 库的示例代码
【发布时间】:2015-06-25 06:24:07
【问题描述】:

我在 StackOverflow 和网络上搜索过,但没有找到任何使用 Google BigQuery C# API library 的代码示例

在 Visual Studio 中,我成功地添加了 BigQuery NuGet 库:

PM> Install-Package Google.Apis.Bigquery.v2 -Pre

我有使用 OAuth 2.0 对 Google 项目 ID 进行身份验证的 C# 代码,这很有效。但目前尚不清楚如何继续使用 BigQuery API。我的目标是将数据插入到 BigQuery 表中。

【问题讨论】:

  • 您的问题似乎有点为时过早。如果您从here 开始并开始单击每个页面上提供的链接,您最终会找到类似this 的内容。这些子类中有插入方法。
  • 好吧,@RobertHarvey,我在我的问题中发布了 API 文档的链接,所以知道在哪里可以找到库文档不是问题。但是我找不到任何实际的 SAMPLE CODE,这对像我这样对这个 API 全新的人来说是最有帮助的。
  • 目前我们没有此 API 的工作示例,但我们的示例存储库中有几个其他 API 的示例 - code.google.com/p/google-api-dotnet-client/source/…

标签: c# google-api-dotnet-client


【解决方案1】:

我一直在寻找同样的东西。最终,多亏了我遇到的一堆帖子,我才成功了。我希望我能在这里提到链接,但我已经忘记了它,因为那是很久以前的事了。此代码使用 C# 将数据流式插入 BigQuery 表。

protected void DoStreamingInsert()
{
    var rowList = new List<TableDataInsertAllRequest.RowsData>();

    var row1 = new TableDataInsertAllRequest.RowsData();
    var row2 = new TableDataInsertAllRequest.RowsData();

    row1.Json = new Dictionary<string, object>();
    row1.Json.Add("TextField", "SomeTest");
    row1.Json.Add("DataField", "2014-10-31 00:00:00.0000");
    //row1.InsertId = DateTime.Now.Ticks.ToString();    Give this ID to prevent duplicate insert

    row2.Json = new Dictionary<string, object>();
    row2.Json.Add("TextField", "SomeTest1");
    row2.Json.Add("DataField", "2014-11-30 00:00:00.0000");

    rowList.Add(row1);
    rowList.Add(row2);

    var content = new TableDataInsertAllRequest();
    content.Rows = rowList;
    content.Kind = "bigquery#tableDataInsertAllRequest";
    content.IgnoreUnknownValues = true;
    content.SkipInvalidRows = true;
    var insertTask = BQDefs.BQService.Tabledata.InsertAll(content,
            BQDefs.ProjectID, BQDefs.DataSet, BQDefs.TableName);
            

    TableDataInsertAllResponse response = insertTask.Execute();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    • 2017-04-21
    • 1970-01-01
    • 2012-11-23
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    相关资源
    最近更新 更多