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);
    }
Esempio n. 2
0
        // [END bigquery_load_from_file]

        // [START bigquery_table_insert_rows]
        public void UploadJsonStreaming(string datasetId, string tableId,
                                        BigQueryClient client)
        {
            // The insert ID is optional, but can avoid duplicate data
            // when retrying inserts.
            BigQueryInsertRow row1 = new BigQueryInsertRow("row1")
            {
                { "title", "exampleJsonFromStream" },
                { "unique_words", 1 }
            };
            BigQueryInsertRow row2 = new BigQueryInsertRow("row2")
            {
                { "title", "moreExampleJsonFromStream" },
                { "unique_words", 1 }
            };

            client.InsertRows(datasetId, tableId, row1, row2);
        }
Esempio n. 3
0
        public Task ProcessBatchAsync(IReadOnlyList <Contact> batch, CancellationToken token)
        {
            var rows = new List <BigQueryInsertRow>();

            foreach (var contact in batch)
            {
                var interactions = contact.Interactions;

                foreach (var interaction in interactions)
                {
                    var runStarted = interaction.Events.OfType <RunStarted>().ToList();

                    if (runStarted.Any())
                    {
                        var row = new BigQueryInsertRow(interaction.Id.ToString())
                        {
                            { "ContactId", contact.Id.ToString() },
                            { "InteractionId", interaction.Id.ToString() },
                            { "RunStart", runStarted.First().Time.ToUniversalTime() }
                        };


                        var runEnded = interaction.Events.OfType <RunEnded>().ToList();

                        if (runEnded.Any())
                        {
                            row.Add("RunEnd", runEnded.First().Time.ToUniversalTime());
                        }
                        rows.Add(row);
                    }
                }
            }
            if (rows.Any())
            {
                var            cred   = Google.Apis.Auth.OAuth2.GoogleCredential.FromFile(@"C:\dev\symposium2019\cred.json");
                BigQueryClient client = BigQueryClient.Create(projectId, cred);
                client.InsertRows(datasetId, tableId, rows);
            }

            return(Task.Delay(1));
        }