You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "Steven Ensslen (JIRA)" <ji...@apache.org> on 2019/05/16 02:28:00 UTC

[jira] [Commented] (BEAM-5510) Records including datetime to be saved as DATETIME or TIMESTAMP in BigQuery

    [ https://issues.apache.org/jira/browse/BEAM-5510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16840930#comment-16840930 ] 

Steven Ensslen commented on BEAM-5510:
--------------------------------------

This defect remains in 2.12.0, and affects `datetime.date` and `datetime.time` in addition to `datetime.datetime`.  I'm working around it with this:

 
{color:#569cd6}class{color} {color:#4ec9b0}ConvertDatesToStringsFn{color}{color:#d4d4d4}({color}{color:#4ec9b0}beam{color}{color:#d4d4d4}.{color}{color:#4ec9b0}DoFn{color}{color:#d4d4d4}):{color}
{color:#ce9178}"""{color}
{color:#ce9178} Workaround for https://issues.apache.org/jira/browse/BEAM-5510{color}
{color:#ce9178} """{color}
{color:#569cd6}def{color} {color:#dcdcaa}process{color}{color:#d4d4d4}({color}{color:#9cdcfe}self{color}{color:#d4d4d4}, {color}{color:#9cdcfe}record{color}{color:#d4d4d4}):{color}
{color:#c586c0}for{color}{color:#d4d4d4} key {color}{color:#569cd6}in{color}{color:#d4d4d4} record:{color}
{color:#c586c0}if{color}{color:#d4d4d4} ({color}{color:#4ec9b0}type{color}{color:#d4d4d4}(record[key]) {color}{color:#d4d4d4}=={color}{color:#d4d4d4} datetime):{color}
{color:#d4d4d4} record[key] {color}{color:#d4d4d4}={color}{color:#d4d4d4} record[key].strftime({color:#ce9178}'%Y-%m-{color}{color:#569cd6}%dT{color:#ce9178}%H:%M:%S{color}{color}{color:#ce9178}'{color}){color}
{color:#c586c0}elif{color}{color:#d4d4d4} ({color}{color:#4ec9b0}type{color}{color:#d4d4d4}(record[key]) {color}{color:#d4d4d4}=={color}{color:#d4d4d4} date):({color}
{color:#d4d4d4} record[key] {color}{color:#d4d4d4}={color}{color:#d4d4d4} record[key].strftime({color}{color:#ce9178}'%Y-%m-{color}{color:#569cd6}%d{color}{color:#ce9178}'{color}{color:#d4d4d4}){color}
{color:#c586c0}elif{color}{color:#d4d4d4} ({color}{color:#4ec9b0}type{color}{color:#d4d4d4}(record[key]) {color}{color:#d4d4d4}=={color}{color:#d4d4d4} time):{color}
{color:#d4d4d4} record[key] {color}{color:#d4d4d4}={color}{color:#d4d4d4} record[key].strftime({color}{color:#ce9178}'%H:%M:%S'{color}{color:#d4d4d4}){color}
{color:#c586c0}yield{color}{color:#d4d4d4} record{color}
 

> Records including datetime to be saved as DATETIME or TIMESTAMP in BigQuery
> ---------------------------------------------------------------------------
>
>                 Key: BEAM-5510
>                 URL: https://issues.apache.org/jira/browse/BEAM-5510
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-py-core
>    Affects Versions: 2.6.0
>            Reporter: Pascal Gula
>            Priority: Major
>
> When trying to write some row in BigQuery that include a python datetime object, the marshaling used to save a row in BigQuery is impossible.
> {code:java}
> File "/home/pascal/Wks/GitHub/PEAT-AI/Albatros/venv/local/lib/python2.7/site-packages/apache_beam/internal/gcp/json_value.py", line 124, in to_json_value
>     raise TypeError('Cannot convert %s to a JSON value.' % repr(obj))
> TypeError: Cannot convert datetime.datetime(2018, 9, 25, 18, 57, 18, 108579) to a JSON value. [while running 'save/WriteToBigQuery']
> {code}
> However, this is something perfectly feasible, as `google-cloud-python` supports it since this issue has been solved: [https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2957]
> thanks to this pull request: [https://github.com/GoogleCloudPlatform/google-cloud-python/pull/3426/files]
> As similar approach could be taken for the `json_value.py` helper.
> Is there any workaround that can be applied to solve this issue? 
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)