[ 
https://issues.apache.org/jira/browse/BEAM-13374?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alexey Romanenko updated BEAM-13374:
------------------------------------
    Status: Open  (was: Triage Needed)

> ToJson() of a Row with a DateTime field fails with an exception
> ---------------------------------------------------------------
>
>                 Key: BEAM-13374
>                 URL: https://issues.apache.org/jira/browse/BEAM-13374
>             Project: Beam
>          Issue Type: Bug
>          Components: beam-model
>    Affects Versions: 2.33.0
>            Reporter: Sergei Lilichenko
>            Priority: P2
>
> The following code fails with "class org.joda.time.Instant cannot be cast to 
> class org.joda.time.DateTime" exception at ToJson.of() transform. 
> The root cause of it appears to be [this conversion to 
> Instant|https://github.com/apache/beam/blob/85a122735f84c0ee46ba0fb583d9ff9e05dcf2fc/sdks/java/core/src/main/java/org/apache/beam/sdk/values/RowUtils.java#L554].
> This bug appeared in a JDBC processing pipeline where a TIMESTAMP column is 
> part of the result set retrieved using JdbcIO.readRows(). 
>  
> {code:java}
> Pipeline p = Pipeline.create();
> Schema schema = Schema.of(Field.of("timestamp", FieldType.DATETIME));
> p
>     .apply("DateTime values", Create.of(new DateTime()))
>     .apply("To Row", ParDo.of(new DoFn<DateTime, Row>() {
>       @ProcessElement
>       public void toRow(@Element DateTime dateTime, OutputReceiver<Row> 
> rowOutputReceiver) {
>         rowOutputReceiver.output(
>             Row.withSchema(schema)
>                 .withFieldValue("timestamp", dateTime)
>                 .build());
>       }
>     }))
>     .setCoder(RowCoder.of(schema))
>     .apply("To Json", ToJson.of())
>     .apply("Print to Console", ParDo.of(new DoFn<String, Void>() {
>       @ProcessElement
>       public void print(@Element String expectedJson) {
>         System.out.println("JSON: " + expectedJson);
>       }
>     }));
> p.run().waitUntilFinish(); {code}
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to