使用bq load加载带有NULL列的CSV

时间:2015-01-03 16:36:14

标签: mysql csv google-bigquery

我正在尝试使用bq工具将mysql(使用outfile)生成的CSV文件(实际上是TSV)上传到Bigquery。该表具有以下模式:

enter image description here

以下是示例数据文件:

"6.02"  "0000"  "101"   \N  "Md Fiesta Chicken|1|6.69|M|300212|100|100^M Sourdough|1|0|M|51301|112|112" "6.5"   \N  "V03"   "24270310376"   "10/17/2014 3:34 PM"    "6.02"  "30103" "452"   "302998"    "2014-12-08 10:57:15"   \N

这就是我尝试使用bq CLI工具上传它的方式:

$ bq load -F '\t' --quote '"' --allow_jagged_rows receipt_archive.receipts /tmp/rec.csv
BigQuery error in load operation: Error processing job
'circular-gist-812:bqjob_r8d0bbc3192b065_0000014ab097c63c_1': Too many errors encountered. Limit is: 0.
Failure details:
- File: 0 / Line:1 / Field:16: Could not parse '\N' as a timestamp.
Required format is YYYY-MM-DD HH:MM[:SS[.SSSSSS]]

我认为问题是updated_at列是NULL&因此跳过了。所以任何想法我怎么能告诉它考虑空/空列?

2 个答案:

答案 0 :(得分:1)

CuriousMind - 这不是一个答案。只是使用浮点数代替小数的问题的一个例子......

CREATE TABLE fd (f FLOAT(5,2),d DECIMAL(5,2));

INSERT INTO fd VALUES (100.30,100.30),(100.70,100.70;

SELECT * FROM fd;
+--------+--------+
| f      | d      |
+--------+--------+
| 100.30 | 100.30 |
| 100.70 | 100.70 |
+--------+--------+

SELECT f/3+f/3+f/3,d/3+d/3+d/3 FROM fd;
+-------------+-------------+
| f/3+f/3+f/3 | d/3+d/3+d/3 |
+-------------+-------------+
|  100.300003 |  100.300000 |
|  100.699997 |  100.700000 |
+-------------+-------------+

SELECT (f/3)*3,(d/3)*3 FROM fd;
+------------+------------+
| (f/3)*3    | (d/3)*3    |
+------------+------------+
| 100.300003 | 100.300000 |
| 100.699997 | 100.700000 |
+------------+------------+

但是为什么这是一个问题,我听到你问?

好吧,请考虑以下内容......

SELECT * FROM fd WHERE f <= 100.699997;
+--------+--------+
| f      | d      |
+--------+--------+
| 100.30 | 100.30 |
| 100.70 | 100.70 |
+--------+--------+

......现在肯定不是在处理钱时会出现什么情况?

答案 1 :(得分:1)

要在CSV文件中指定“null”,请忽略该字段的所有数据。 (看起来您使用的是未指定的转义语法“\ N”。)

例如:

$ echo 2, > rows.csv
$ bq load tmp.test rows.csv a:integer,b:integer
$ bq head tmp.test
+---+------+
| a |  b   |
+---+------+
| 2 | NULL |
+---+------+