简体   繁体   English

BigQuery仅在流式缓冲区中显示值的第一个字母

[英]BigQuery only shows first letter of value in streaming buffer

I am streaming data into BigQuery using the Python client library. 我正在使用Python客户端库将数据流式传输到BigQuery中。 The row of data lands in the BQ streaming buffer just fine, but when I run a query to view it I can only see the first letter of the value I have inserted. 数据行恰好位于BQ流缓冲区中,但是当我运行查询来查看它时,我只能看到我插入的值的第一个字母。

Specifically, I run a snippet of Python like this: 具体来说,我像这样运行一段Python:

from google.cloud import bigquery
client = bigquery.Client()
dataset_id = 'mydataset'
table_id = 'mytable'
table_ref = client.dataset(dataset_id).table(table_id)
table = client.get_table(table_ref)
rows_to_insert = [(u'testString')]
client.insert_rows(table, rows_to_insert)

Then when I run SELECT * FROM mytable , the result value I get only has 't' instead of 'testString' 然后,当我运行SELECT * FROM mytable ,我得到的结果值只有't'而不是'testString'

I'm guessing this has something to do with the streaming buffer and should show me the entire value once it has been rewritten in BQ native format. 我猜想这与流缓冲区有关,一旦以BQ本机格式重写了它的全部值,它应该向我显示。 But it would be great if someone could clarify it for me. 但是,如果有人可以为我澄清这一点,那就太好了。

When you are streaming data in BigQuery, every row is a python tuple type. 在BigQuery中流式传输数据时,每一行都是python元组类型。 To define a tuple in python properly, you will need to add one more , . 要定义在python正确元组,则需要增加一个, For example: 例如:

>>> type( ('a') )
<type 'str'>

>>> type( ('a',) )
<type 'tuple'>

As it is stated in this Stackoverflow answer . Stackoverflow答案中所述

The way you have it now, it sends an array of individual characters, so every character will get in a different column (in case you have more columns). 您现在所拥有的方式,它将发送一个由单个字符组成的数组,因此每个字符将进入不同的列(以防您有更多的列)。

Just replace rows_to_insert = [(u'testString')] with rows_to_insert = [(u'testString',)] and your string will be stored properly. 只需将rows_to_insert = [(u'testString')]替换为rows_to_insert = [(u'testString',)] ,您的字符串将被正确存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM