我已经在BigQuery中定义了一个架构,
+------------------+----------+----------+
| name | type | mode |
+------------------+----------+----------+
| warehouse | INTEGER | NULLABLE |
| transaction_date | DATETIME | NULLABLE |
| style | STRING | NULLABLE |
| piece | STRING | NULLABLE |
| fabric_1 | STRING | NULLABLE |
| fabric_2 | STRING | NULLABLE |
| serial | STRING | NULLABLE |
| customer_po | STRING | NULLABLE |
| order_number | STRING | NULLABLE |
+------------------+----------+----------+
我关注的两个字段是serial和order_number,在R中预览时,它们看起来像这样:
+-----------+------------------+--------+-------+-----------+----------+------------+--------------+--------------+
| warehouse | transaction_date | style | piece | fabric_1 | fabric_2 | serial | customer_po | order_number |
+-----------+------------------+--------+-------+-----------+----------+------------+--------------+--------------+
| 80 | 4/3/19 | K28300 | ARMH | ALL CHAR | NA | 8040418253 | 1486838165 | 464374 |
| 80 | 4/3/19 | K28300 | ARMH | ALL CHAR | NA | 9040542252 | 1485798731-P | 464069 |
| 80 | 4/3/19 | K28300 | ARMH | ELEG NAVY | NA | 8040355550 | 1486826068 | 464369 |
| 80 | 4/3/19 | K28300 | ARMH | ELEG NAVY | NA | 8040532364 | 1485366411-R | 464071 |
+-----------+------------------+--------+-------+-----------+----------+------------+--------------+--------------+
在R内,这两个字段在我正在寻找的数据框中似乎被读为字符。但是,当我将数据推送到BigQuery时,这两个字段最终像这样:
+-----------+------------------+--------+-------+-----------+----------+------------+--------------+--------------+
| warehouse | transaction_date | style | piece | fabric_1 | fabric_2 | serial | customer_po | order_number |
+-----------+------------------+--------+-------+-----------+----------+------------+--------------+--------------+
| 80 | 4/3/19 | K28300 | ARMH | ALL CHAR | NA | 8040418253.0 | 1486838165 | 464374.0 |
| 80 | 4/3/19 | K28300 | ARMH | ALL CHAR | NA | 9040542252.0 | 1485798731-P | 464069.0 |
| 80 | 4/3/19 | K28300 | ARMH | ELEG NAVY | NA | 8040355550.0 | 1486826068 | 464369.0 |
| 80 | 4/3/19 | K28300 | ARMH | ELEG NAVY | NA | 8040532364.0 | 1485366411-R | 464071.0 |
+-----------+------------------+--------+-------+-----------+----------+------------+--------------+--------------+
为什么会发生这种情况,我该如何更改?供参考,我的代码将其上传:
bqr_upload_data(projectId = "project-test",
datasetId = "orders",
tableId = "daily_orders",
upload_data = df_daily_orders,
maxBadRecords = 1000,
overwrite = TRUE)
答案 0 :(得分:1)
由于我仍然是初学者,现在我不确定我的答案,但这可能会对您有所帮助。我将其添加为评论,但我的声誉还不够。
如果我正确理解,您实际上是在进行隐式转换-从数字值到字符串值,BigQuery捕获小数点以确保它正确捕获了整个值
检查here BigQuery的转换规则-第二张表,FLOAT64到String。
在您的位置,并根据您需要对表格进行的操作-我会
或
答案 1 :(得分:1)
从R上传的内容会查看列的类别,以确定哪种是BigQuery的最佳架构。尝试将数据框列的类更改为字符串,以避免通过类似的方式将其更改为浮点型
as.character(df$column)