0

I've searched StackOverflow and on the web and haven't found any code samples for using the Google BigQuery C# API library

Within Visual Studio, I was successfully able to add the BigQuery NuGet Library:

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

I have C# code to authenticate to the Google project ID using OAuth 2.0, and that is working. But it is not clear on how to proceed with the BigQuery API. My goal is to insert data into a BigQuery table.

rene
  • 41,474
  • 78
  • 114
  • 152
  • 1
    Your question seems a bit premature. If you start [here](https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/csharp/latest/namespaces.html) and begin clicking through the links provided on each page, you will eventually find things like [this](https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/csharp/latest/namespaceGoogle_1_1Apis_1_1Bigquery_1_1v2.html). There are insert methods in those subclasses. – Robert Harvey Jan 09 '14 at 18:49
  • Well, @RobertHarvey, I posted the link to the API documentation in my question, so its not a problem of knowing where to find the library documentation. But I can't find any actual SAMPLE CODE, which is what is most helpful to someone like me who is brand new to this API. – Michael Hanna Jan 09 '14 at 22:38
  • Currently we don't have a working sample for this API, but there are several samples for other APIs in our samples repository - https://code.google.com/p/google-api-dotnet-client/source/browse?repo=samples. – peleyal Jan 15 '14 at 23:06

1 Answers1

3

I was looking around for the same thing. Eventually, i made it work thanks to bunch of posts i came across. I wish I could mention links here but i lost track of it since it was quite a while ago. This code does streaming insert data into BigQuery table using C#.

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();
}
Patel
  • 399
  • 5
  • 12