private void CreateHighScoreTable(BigqueryDataset dataset) { var table = dataset.CreateTable(HighScoreTableId, new TableSchemaBuilder { { "player", BigqueryDbType.String }, { "gameStarted", BigqueryDbType.Timestamp }, { "score", BigqueryDbType.Integer } }.Build()); table.Insert(new[] { new InsertRow { { "player", "Bob" }, { "score", 85 }, { "gameStarted", new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc) } }, new InsertRow { { "player", "Angela" }, { "score", 95 }, { "gameStarted", new DateTime(2002, 1, 1, 0, 0, 0, DateTimeKind.Utc) } }, new InsertRow { { "player", null }, // Unnamed player... { "score", 1 }, { "gameStarted", new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc) } } }); }
private void CreateComplexTypesTable(BigqueryDataset dataset) { dataset.CreateTable(ComplexTypesTableId, new TableSchemaBuilder { { "guid", BigqueryDbType.String }, { "tags", BigqueryDbType.String, FieldMode.Repeated }, { "position", new TableSchemaBuilder { { "x", BigqueryDbType.Integer }, { "y", BigqueryDbType.Integer } } } }.Build()); }
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, FieldMode.Required }, { "age", BigqueryDbType.Integer }, { "gender", BigqueryDbType.String }, { "phoneNumber", new TableSchemaBuilder { { "areaCode", BigqueryDbType.Integer }, { "number", BigqueryDbType.Integer } } }, { "children", new TableSchemaBuilder { { "name", BigqueryDbType.String }, { "gender", BigqueryDbType.String }, { "age", BigqueryDbType.Integer }, }, FieldMode.Repeated }, { "citiesLived", new TableSchemaBuilder { { "place", BigqueryDbType.String }, { "yearsLived", BigqueryDbType.Integer, FieldMode.Repeated }, }, FieldMode.Repeated } }.Build()); // TODO: We need to make this easier to use. List <string> jsonRows = LoadTextResource("personsData.json"); var bytes = Encoding.UTF8.GetBytes(string.Join("\n", jsonRows)); var job = table.UploadJson(new MemoryStream(bytes)); var result = job.Poll(); 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.Integer }, { "level", BigqueryDbType.Integer }, { "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); }