Esempio n. 1
0
        private string CreateGameDataset()
        {
            string          id            = CreateDataset();
            BigQueryDataset game          = Client.GetDataset(id);
            var             historySchema = new TableSchemaBuilder
            {
                { "player", BigQueryDbType.String },
                { "score", BigQueryDbType.Int64 },
                { "level", BigQueryDbType.Int64 },
                { "game_started", BigQueryDbType.Timestamp }
            }.Build();
            var historyTable            = game.CreateTable(HistoryTableId, historySchema);
            var historyTableWithInserts = game.CreateTable(HistoryTableWithInsertsId, historySchema);

            string[] csvRows =
            {
                CreateHistoryRow("Tim",    503, 1, "2015-05-03T23:01:05"),
                CreateHistoryRow("Nadia",  450, 1, "2013-05-06T10:05:07"),
                CreateHistoryRow("Nadia", 1320, 2, "2013-06-01T15:02:07"),
                CreateHistoryRow("Ben",    300, 1, "2014-01-30T12:53:35"),
                CreateHistoryRow("Tim",   5310, 3, "2014-06-28T10:32:15"),
                CreateHistoryRow("Tim",   2000, 2, "2014-07-01T08:12:25"),
                CreateHistoryRow("Nadia", 8310, 5, "2015-03-20T14:55:10")
            };
            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(string.Join("\n", csvRows)));

            historyTable.UploadCsv(stream).PollUntilCompleted().ThrowOnAnyError();
            stream.Position = 0;
            historyTableWithInserts.UploadCsv(stream).PollUntilCompleted().ThrowOnAnyError();
            return(id);
        }
        private void CreateHighScoreTable(BigQueryDataset dataset)
        {
            var table = dataset.CreateTable(HighScoreTableId, new TableSchemaBuilder
            {
                { "player", BigQueryDbType.String },
                { "gameStarted", BigQueryDbType.Timestamp },
                { "score", BigQueryDbType.Int64 }
            }.Build());

            table.Insert(new[]
            {
                new BigQueryInsertRow {
                    { "player", "Bob" },
                    { "score", 85 },
                    { "gameStarted", new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc) }
                },
                new BigQueryInsertRow {
                    { "player", "Angela" },
                    { "score", 95 },
                    { "gameStarted", new DateTime(2002, 1, 1, 0, 0, 0, DateTimeKind.Utc) }
                },
                new BigQueryInsertRow {
                    { "player", null }, // Unnamed player...
                    { "score", 1 },
                    { "gameStarted", new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc) }
                }
            });
        }
Esempio n. 3
0
        private void CreateHighScoreExtendedTable(BigQueryDataset dataset)
        {
            var table = dataset.CreateTable(HighScoreExtendedTableId, new TableSchemaBuilder
            {
                { "player", BigQueryDbType.String },
                { "gameStarted", BigQueryDbType.Timestamp },
                { "score", BigQueryDbType.Int64 },
                { "gameFinished", BigQueryDbType.Timestamp }
            }.Build());

            var rows = new[]
            {
                new BigQueryInsertRow {
                    { "player", "Bob" },
                    { "score", 75 },
                    { "gameStarted", new DateTime(2003, 1, 1, 0, 0, 0, DateTimeKind.Utc) },
                    { "gameFinished", new DateTime(2003, 1, 1, 1, 0, 0, DateTimeKind.Utc) }
                },
                new BigQueryInsertRow {
                    { "player", "Angela" },
                    { "score", 105 },
                    { "gameStarted", new DateTime(2004, 1, 1, 0, 0, 0, DateTimeKind.Utc) },
                    { "gameFinished", new DateTime(2004, 1, 1, 3, 0, 0, DateTimeKind.Utc) }
                }
            };

            InsertAndWait(table, () => table.InsertRows(rows), 2);
        }
 private void CreateComplexTypesTable(BigQueryDataset dataset)
 {
     dataset.CreateTable(ComplexTypesTableId, new TableSchemaBuilder
     {
         { "guid", BigQueryDbType.String },
         { "tags", BigQueryDbType.String, BigQueryFieldMode.Repeated },
         { "position", new TableSchemaBuilder
             {
                 { "x", BigQueryDbType.Int64 },
                 { "y", BigQueryDbType.Int64 }
             }
         },
         { "job", new TableSchemaBuilder
             {
                 { "company", BigQueryDbType.String },
                 { "roles", BigQueryDbType.String, BigQueryFieldMode.Repeated }
             }
         },
         { "names", new TableSchemaBuilder
             {
                 { "first", BigQueryDbType.String },
                 { "last", BigQueryDbType.String }
             },
             BigQueryFieldMode.Repeated
         }
     }.Build());
 }
Esempio n. 5
0
        private void CreateExhaustiveTypesTable(BigQueryDataset dataset)
        {
            // Record containing a single string, a repeated string and a nested record
            TableSchema recordSchema = new TableSchemaBuilder
            {
                { "single_string", BigQueryDbType.String },
                { "repeated_string", BigQueryDbType.String, BigQueryFieldMode.Repeated },
                { "nested_record",
                  new TableSchemaBuilder {
                      { "a", BigQueryDbType.Int64 },
                      { "b", BigQueryDbType.Int64 },
                  } }
            }.Build();

            var table = dataset.CreateTable(ExhaustiveTypesTableId, new TableSchemaBuilder
            {
                // Single fields
                { "single_string", BigQueryDbType.String },
                { "single_bool", BigQueryDbType.Bool },
                { "single_bytes", BigQueryDbType.Bytes },
                { "single_date", BigQueryDbType.Date },
                { "single_datetime", BigQueryDbType.DateTime },
                { "single_time", BigQueryDbType.Time },
                { "single_timestamp", BigQueryDbType.Timestamp },
                { "single_int64", BigQueryDbType.Int64 },
                { "single_float64", BigQueryDbType.Float64 },
                { "single_numeric", BigQueryDbType.Numeric },
                { "single_geography", BigQueryDbType.Geography },
                { "single_record", recordSchema },

                // Repeated fields
                { "array_string", BigQueryDbType.String, BigQueryFieldMode.Repeated },
                { "array_bool", BigQueryDbType.Bool, BigQueryFieldMode.Repeated },
                { "array_bytes", BigQueryDbType.Bytes, BigQueryFieldMode.Repeated },
                { "array_date", BigQueryDbType.Date, BigQueryFieldMode.Repeated },
                { "array_datetime", BigQueryDbType.DateTime, BigQueryFieldMode.Repeated },
                { "array_time", BigQueryDbType.Time, BigQueryFieldMode.Repeated },
                { "array_timestamp", BigQueryDbType.Timestamp, BigQueryFieldMode.Repeated },
                { "array_int64", BigQueryDbType.Int64, BigQueryFieldMode.Repeated },
                { "array_float64", BigQueryDbType.Float64, BigQueryFieldMode.Repeated },
                { "array_numeric", BigQueryDbType.Numeric, BigQueryFieldMode.Repeated },
                { "array_geography", BigQueryDbType.Geography, BigQueryFieldMode.Repeated },
                { "array_record", recordSchema, BigQueryFieldMode.Repeated },
            }.Build());

            InsertAndWait(table, () => table.InsertRow(ExhaustiveTypesTest.GetSampleRow()), 1);
        }
        private void CreatePeopleTable(BigQueryDataset dataset)
        {
            // Sample schema taken from 
            // https://cloud.google.com/bigquery/docs/data
            // Data is loaded in UploadTest.
            var table = dataset.CreateTable(PeopleTableId, new TableSchemaBuilder
            {
                { "name", BigQueryDbType.String },
                { "fullName", BigQueryDbType.String, BigQueryFieldMode.Required },
                { "age", BigQueryDbType.Int64 },
                { "gender", BigQueryDbType.String },
                { "phoneNumber", new TableSchemaBuilder
                    {
                        { "areaCode", BigQueryDbType.Int64 },
                        { "number", BigQueryDbType.Int64 }
                    }
                },
                { "children", new TableSchemaBuilder
                    {
                        { "name", BigQueryDbType.String },
                        { "gender", BigQueryDbType.String },
                        { "age", BigQueryDbType.Int64 },
                    },
                    BigQueryFieldMode.Repeated
                },
                { "citiesLived", new TableSchemaBuilder
                    {
                        { "place", BigQueryDbType.String },
                        { "yearsLived", BigQueryDbType.Int64, BigQueryFieldMode.Repeated },
                    },
                    BigQueryFieldMode.Repeated
                }
            }.Build());
            List<string> jsonRows = LoadTextResource("personsData.json");
            var job = table.UploadJson(jsonRows);

            var result = job.PollUntilCompleted();
            var errors = result.Status.ErrorResult;
            if (errors != null)
            {
                throw new Exception("Errors uploading JSON: " + errors);
            }
        }
        private string CreateGameDataset()
        {
            string          id            = CreateDataset();
            BigQueryDataset game          = Client.GetDataset(id);
            var             historySchema = new TableSchemaBuilder
            {
                { "player", BigQueryDbType.String },
                { "score", BigQueryDbType.Int64 },
                { "level", BigQueryDbType.Int64 },
                { "game_started", BigQueryDbType.Timestamp }
            }.Build();
            var historyTable = game.CreateTable(HistoryTableId, historySchema);

            historyTable.Insert(
                CreateHistoryRow("Tim", 503, 1, "2015-05-03T23:01:05"),
                CreateHistoryRow("Nadia", 450, 1, "2013-05-06T10:05:07"),
                CreateHistoryRow("Nadia", 1320, 2, "2013-06-01T15:02:07"),
                CreateHistoryRow("Ben", 300, 1, "2014-01-30T12:53:35"),
                CreateHistoryRow("Tim", 5310, 3, "2014-06-28T10:32:15"),
                CreateHistoryRow("Tim", 2000, 2, "2014-07-01T08:12:25"),
                CreateHistoryRow("Nadia", 8310, 5, "2015-03-20T14:55:10")
                );
            return(id);
        }