Big Query InsertAll使用C#

时间:2016-06-10 22:28:56

标签: c# google-bigquery

我在尝试使用Big Query插入数据时使用此代码。 一切都在运行,没有任何例外,但我的表是空的。 我的代码有什么问题?

from __future__ import division
import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(1, 2)

x = range(10)
y1 = range(10)
y2 = [2*i for i in range(10)]

# plot line graphs
ax1.plot(x, y1)
ax1.plot(x, y2)

# the maximum improvements
x_max = max(x)
y1_max = max(y1)
y2_max = max(y2)
improvements = "{:.2%}".format((y2_max-y1_max)/y1_max) # percentage

# plot arrow
ax1.annotate('',
            xy=(x_max, y2_max), xycoords='data',
            xytext=(x_max, y1_max), textcoords='data',
            arrowprops=dict(arrowstyle="->", connectionstyle="arc3",
            color='r', linewidth=3.5))

# add annotate to arrow
ax1.annotate(improvements, 
    xy=(x_max, y1_max + .3 * (y2_max-y1_max)), xycoords='data',
    xytext=(-50, 0), textcoords='offset points', color='r', weight='bold', size=10)

# for showing the expected result
ax2.plot(x, y1)
ax2.plot(x, y2)

plt.show()

1 个答案:

答案 0 :(得分:0)

您的代码看起来不错,但是唯一的问题是您需要发送数据,实际上您没有发送任何数据,请测试此代码并让我知道(我创建了一个包含两个字段P1和P2的表)

var logs = new List<TableDataInsertAllRequest.RowsData>();
var theLog = new TableDataInsertAllRequest.RowsData();
theLog.Json = new Dictionary<string, object>();
theLog.Json.Add("P1", "Hola");
theLog.Json.Add("P2", "Mundo");            
logs.Add(theLog);

var service = GetBigQueryService();
var content = new TableDataInsertAllRequest();
content.Rows = logs;
content.Kind = "bigquery#tableDataInsertAllRequest";
content.IgnoreUnknownValues = true;
content.SkipInvalidRows = true;

var insertTask = service.Tabledata.InsertAll(content, "Your_Project_Id", "Your_DataSet", "Your_Table");
TableDataInsertAllResponse response = insertTask.Execute();