You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "xuyang (Jira)" <ji...@apache.org> on 2024/12/02 03:12:00 UTC

[jira] [Commented] (FLINK-36284) StreamTableEnvironment#toDataStream(Table table, Class targetClass) is not suitable for setting targetClass as a class generated by Avro.

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

xuyang commented on FLINK-36284:
--------------------------------

[~twalthr] Yes, my intention is to ensure that the existing tests pass even after the removal of the legacy methods, since 2.0 will completely remove the APIs related legacy table source & sink. The blocking case that cannot be resolved without modifying the current code is the one described in this Jira.

> Switching to TypeInformation just to convert to DataType will loose precision.

IIUC, the conversion from Avro types to TypeInformation results in a loss of precision before this fix (and possibly converting TypeInformation to DataType also loses precision?).

In any case, my approach is to address issues as they arise. Do you have any specific cases and Jira tickets related to this? I will try to look into it.

> StreamTableEnvironment#toDataStream(Table table, Class<T> targetClass) is not suitable for setting targetClass as a class generated by Avro.
> --------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-36284
>                 URL: https://issues.apache.org/jira/browse/FLINK-36284
>             Project: Flink
>          Issue Type: Improvement
>          Components: Formats (JSON, Avro, Parquet, ORC, SequenceFile), Table SQL / API
>            Reporter: xuyang
>            Assignee: xuyang
>            Priority: Blocker
>              Labels: pull-request-available
>             Fix For: 2.0-preview
>
>         Attachments: image-2024-09-14-17-39-16-698.png
>
>
> This issue can be fired by updating the {{testAvroToAvro}} method in the {{org.apache.flink.table.runtime.batch.AvroTypesITCase}} class.
>  
> {code:java}
> @Test
> public void testAvroToAvro() {
>     StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
>     StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
>     DataStream<User> ds = testData(env);
>     // before: using deprecated method
>     // Table t = tEnv.fromDataStream(ds, selectFields(ds));
>     // after: using recommended new method
>     Table t = tEnv.fromDataStream(ds);
>     Table result = t.select($("*"));
>     // before: using deprecated method
>     // List<User> results =
>     //        CollectionUtil.iteratorToList(
>     //                DataStreamUtils.collect(tEnv.toAppendStream(result, User.class)));
>     // after: using recommended new method
>     List<User> results =
>         CollectionUtil.iteratorToList(
>                 DataStreamUtils.collect(tEnv.toDataStream(result, User.class)));
>     List<User> expected = Arrays.asList(USER_1, USER_2, USER_3);
>     assertThat(results).isEqualTo(expected);
> } {code}
> An exception will be thrown:
> !image-2024-09-14-17-39-16-698.png|width=1049,height=594!
>  
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)