【发布时间】:2019-10-29 02:50:11
【问题描述】:
我正在编写一个 Google Apps 脚本以将数据从 Mysql 数据库发送到 Big Query 表。
我知道如何查询 mysql 数据库。我知道如何将 csv 文件或 Google 表格中的数据写入大查询。但是,我希望能够将 mysql 查询结果直接发送到 BigQuery。我怎样才能做到这一点?
基本上,我的 SQL 结果存储在一个变量中:
var results = stmt.executeQuery('select * from table');
表格很基本:
Col1 Col2 Col3
String 1 foo1 1
String 2 foo2 2
String 3 foo3 3
etc... etc... etc...
从 Big Query 端脚本我有这个:
var data = results.getBlob().setContentType('application/octet-stream');
显然,在运行我的脚本时出现以下错误:
Cannot find function getBlob in object
我不太明白如何访问results 变量中的数据,也不知道如何将它们格式化为可读格式以执行以下.getBlob().setContentType('application/octet-stream')
到目前为止,我已经尝试通过使用以下循环的 push 方法将 results 值传递到名为 rawdata 的新变量中:
while (results.next()) {
var rowString = '';
for (var col = 0; col < numCols; col++) {
rowString += results.getString(col + 1) + '\t';
}
Logger.log(rowString);
rawdata.push(rowString)
}
但是rawdata.getBlob().setContentType('application/octet-stream'); 给我返回同样的错误。
我不知道如何格式化我的 rawdata 或 results 变量。
【问题讨论】:
-
getBlob()需要在 (CVS) 文件上使用的接缝?见developers.google.com/apps-script/advanced/bigquery -
所以除了使用 CVS 作为中间体,我没有其他选择了吗?
标签: mysql jdbc google-apps-script google-bigquery