Last active
July 30, 2019 20:30
-
-
Save mvrmoreira/e97481513724be50956c6af75f91b380 to your computer and use it in GitHub Desktop.
GoogleBigQuerySpike
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using Google.Cloud.BigQuery.V2; | |
namespace GoogleBigQuerySpike | |
{ | |
public class Loan | |
{ | |
public string Id { get; set; } | |
public DateTime CreationDate { get; set; } | |
public decimal DisbursedAmount { get; set; } | |
public decimal InterestRate { get; set; } | |
public Borrower Borrower { get; set; } | |
public Loan(string id, DateTime creationDate, decimal disbursedAmount, decimal interestRate, Borrower borrower) | |
{ | |
Id = id; | |
CreationDate = creationDate; | |
DisbursedAmount = disbursedAmount; | |
InterestRate = interestRate; | |
Borrower = borrower; | |
} | |
public BigQueryInsertRow GetBigQueryInsertRow() | |
{ | |
var fields = new Dictionary<string, object>(); | |
fields.Add("Id", Id); | |
fields.Add("BorrowerId", Borrower.Id); | |
fields.Add("BorrowerName", Borrower.Name); | |
fields.Add("CreationDate", CreationDate.ToString("yyyy-MM-ddTHH:mm:ss")); | |
fields.Add("DisbursedAmount", DisbursedAmount.ToString()); | |
fields.Add("InterestRate", (double)InterestRate); | |
var row = new BigQueryInsertRow(this.Id); | |
row.Add(fields); | |
return row; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Google.Cloud.BigQuery.V2; | |
namespace GoogleBigQuerySpike | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello!"); | |
try | |
{ | |
string projectId = "spike-moreira"; | |
string datasetId = "teste"; | |
string tableId = "loans"; | |
var client = BigQueryClient.Create(projectId); | |
var borrower = new Borrower("jps9rkg28yk78j3eb94348cqy", "Niterói Rugby", new DateTime(1973, 1, 1)); | |
var loan = new Loan("jps9rm77e356gyfxnmmd28cx5", DateTime.UtcNow, 30000, 5.99m, borrower); | |
var row = loan.GetBigQueryInsertRow(); | |
var options = new InsertOptions(); | |
options.AllowUnknownFields = true; | |
client.InsertRow(projectId, datasetId, tableId, row, options); | |
} | |
catch (Exception ex) | |
{ | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment