[
https://issues.apache.org/jira/browse/BEAM-6769?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16792765#comment-16792765
]
Juta Staes commented on BEAM-6769:
----------------------------------
When writing bytes in py2 to bq to an existing table, without specifying the
schema, the current behavior is
using bytes
{code:java}
(pipeline
| 'create' >> beam.Create([{'bytes':b'\xab\xac\xad', 'date':'2000-01-01',
'time':'00:00:00'}])
| 'write' >> beam.io.WriteToBigQuery(table_id)
>> ValueError: 'utf8' codec can't decode byte 0xab in position 0: invalid start
>> byte. NAN, INF and -INF values are not JSON compliant.{code}
using base-64
{code:java}
(pipeline
| 'create' >> beam.Create([{'bytes':'q6yt', 'date':'2000-01-01',
'time':'00:00:00'}])
| 'write' >> beam.io.WriteToBigQuery(table_id)
>> 'Invalid schema update. Field bytes has changed type from BYTES to
>> STRING'{code}
The only way to successfully write bytes is:
{code:java}
(pipeline
| 'create' >> beam.Create([{'bytes':'q6yt', 'date':'2000-01-01',
'time':'00:00:00'}])
| 'write' >> beam.io.WriteToBigQuery(table_id,
schema={"fields": [{"name": "bytes","type": "BYTES"},
{"name": "date","type": "DATE"},{"name": "time","type":
"TIME"}]}){code}
> BigQuery IO does not support bytes in Python 3
> ----------------------------------------------
>
> Key: BEAM-6769
> URL: https://issues.apache.org/jira/browse/BEAM-6769
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-py-core
> Reporter: Juta Staes
> Assignee: Juta Staes
> Priority: Major
> Time Spent: 2h
> Remaining Estimate: 0h
>
> In Python 2 you could write bytes data to BigQuery. This is tested in
>
> [https://github.com/apache/beam/blob/master/sdks/python/apache_beam/io/gcp/big_query_query_to_table_it_test.py#L186]
> Python 3 does not support
> {noformat}
> json.dumps({'test': b'test'}){noformat}
> which is used to encode the data in
>
> [https://github.com/apache/beam/blob/master/sdks/python/apache_beam/io/gcp/bigquery_tools.py#L959]
>
> How should writing bytes to BigQuery be handled in Python 3?
> * Forbid writing bytes into BigQuery on Python 3
> * Guess the encoding (utf-8?)
> * Pass the encoding to BigQuery
> cc: [~tvalentyn]
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)