C# разбирать объект в строке Google BigQuery - PullRequest
0 голосов
/ 12 февраля 2020

Я очень новичок в Google Big Query, и мне трудно вставить строку в таблицу.

Например, у меня есть таблица:

iso2 [string|required]
names [record|required]
names.name [string|required]
names.language [string|required]
names.official [boolean|required]

И у меня есть класс:

class Country{
   string Iso2 {get;set;}
   List<CountryName> Names {get;set;}

   class CountryName{
      string Name {get;set;}
      string Language {get;set;}
      bool Official {get;set;
   }
}

И я создаю страну

var country = new Country(){
   Iso2 = "nl",
   Names = new Country.CountryName(){
      Name = "Nederland",
      Language = "nl",
      Official = true
   }
}

BigQueryClient client = BigQueryClient.Create(projectId);
//How do I insert this country into the table?

Итак, как мне преобразовать объект, чтобы его можно было вставить в Google BigQuery

1 Ответ

0 голосов
/ 13 февраля 2020

Вы можете найти здесь некоторые официальные фрагменты кода C# относительно BigQuery SDK. В файле TableInsertRows.cs вы можете найти следующий пример:

using Google.Cloud.BigQuery.V2;
using System;

public class BigQueryTableInsertRows
{
    public void TableInsertRows(
        string projectId = "your-project-id",
        string datasetId = "your_dataset_id",
        string tableId = "your_table_id"
    )
    {
        BigQueryClient client = BigQueryClient.Create(projectId);
        BigQueryInsertRow[] rows = new BigQueryInsertRow[]
        {
            // The insert ID is optional, but can avoid duplicate data
            // when retrying inserts.
            new BigQueryInsertRow(insertId: "row1") {
                { "name", "Washington" },
                { "post_abbr", "WA" }
            },
            new BigQueryInsertRow(insertId: "row2") {
                { "name", "Colorado" },
                { "post_abbr", "CO" }
            }
        };
        client.InsertRows(datasetId, tableId, rows);
    }
}

Надеюсь, это поможет

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...