[ https://issues.apache.org/jira/browse/FLINK-24176?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17414990#comment-17414990 ]
Marios Trivizas edited comment on FLINK-24176 at 9/14/21, 3:06 PM: ------------------------------------------------------------------- * This is issue is still valid for current flink *master* branch. * It's traced down to the calcite optimizer which doesn't keep the alias * Seems that the behaviour is a bit flaky, for example the following query ends up with the correct fields: {code:java} SELECT max(a) as max_a, c as alias_c , sum(a) as sum_a FROM my_table group by c, HOP(ts, INTERVAL '1' SECOND) {code} gives the following columns: {code:java} max_a, alias_c, sum_a{code} * The issue doesn't occur if the newer *toDataStream()* and *toChangelogStream()* are used instead of the deprecated *toAppendStream()* ** This is because the new methods apply a final projection which fixes any changes and lost aliases that happen during the optimisation. was (Author: matriv): * This is issue is still valid for current flink *master* branch. * It's traced down to the calcite optimizer which doesn't keep the alias * Seems that the behaviour is a bit flaky, for example the following query ends up with the correct fields: {code:java} SELECT max(a) as max_a, c as alias_c , sum(a) as sum_a FROM my_table group by c, HOP(ts, INTERVAL '1' SECOND) {code} ** gives the following columns: {code:java} max_a, alias_c, sum_a{code} * The issue doesn't occur if the newer *toDataStream()* and *toChangelogStream()* are used instead of the deprecated *toAppendStream()* ** This is because the new methods apply a final projection which fixes any changes and lost aliases that happen during the optimisation. > Column alias in Flink-SQL is unsuccessful after converting Table to > DataStream<Row> > ------------------------------------------------------------------------------------- > > Key: FLINK-24176 > URL: https://issues.apache.org/jira/browse/FLINK-24176 > Project: Flink > Issue Type: Bug > Components: API / DataStream, Table SQL / API > Affects Versions: 1.12.0 > Environment: java version "1.8.0_291" > Flink version : 1.12-csadh1.3.0.0 > Flink scala version: 2.12 > Reporter: Wang Guanglei > Priority: Critical > > Hi team, > I found an interesting issue while using Flink-SQL. If the group window > function and aggregating operation are used in one SQL statement at the same > time, some column aliases will be unsuccessful after converting the table to > DataStream<Row>. > Following is a part of the code : > {code:java} > //代码占位符 > tableEnv.createTemporaryView("my_table", in); > String sqlQuery = "SELECT c as alias_c, sum(a) as sum_a FROM my_table group > by c, TUMBLE(ts, INTERVAL '1' SECOND)"; > Table result = tableEnv.sqlQuery(sqlQuery); > System.out.println("Table schema: " + result.getSchema()); > DataStream<Row> resultDataStream = tableEnv.toAppendStream(result, Row.class); > final RowTypeInfo type1 = (RowTypeInfo)resultDataStream.getType(); > System.out.println("Field names: " + Arrays.toString(type1.getFieldNames())); > {code} > Output: > Table schema: root > |-- *alias_c*: STRING > |-- sum_a: INT > Field names: [*c*, sum_a] > > > -- This message was sent by Atlassian Jira (v8.3.4#803005)