You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Vladislav Keda <vl...@glowbyteconsulting.com> on 2022/02/02 16:16:28 UTC
Creating Flink SQL Row with named fields
Hi,
I'm trying to create Row(..) using Flink SQL, but I can't assign names to
its fields.
*For example:*Input table1 structure:* (id INT, some_name STRING)*
Query: *select *, ROW(id, some_name) as row1 from table1*
Output result structure:
*(id INT , some_name STRING, row1 ROW (EXPR$0 INT, EXPR$1 STRING))*
*Each nested field has a name like EXPR$<N> that does not satisfy me.*
*If I write, for example:*Input table1 structure:* (id INT, some_name
STRING)*
Query: *select *, ROW(id as nested_id, some_name as nested_some_name) as
row1 from table1*
Output result structure: *(id INT , some_name STRING, row1 ROW (EXPR$0
INT, EXPR$1 STRING))*
*I will get an exception like: *
*Caused by: org.apache.flink.table.api.SqlParserException: SQL parse
failed. Encountered "as" at line 1, column 20.Was expecting one of: ")"
... "," ... at
org.apache.flink.table.planner.parse.CalciteParser.parse(CalciteParser.java:56)
at
org.apache.flink.table.planner.delegation.ParserImpl.parse(ParserImpl.java:98)
at
org.apache.flink.table.api.internal.TableEnvironmentImpl.sqlQuery(TableEnvironmentImpl.java:704)
at
ru.glowbyte.streaming.core.operators.internal.sql.SqlDrivenOperator.sqlQuery(SqlDrivenOperator.java:159)
... 59 more*
How can I set the name for the field?
Flink version - 1.13.3.
---
Best Regards,
Vladislav Keda
Re: Creating Flink SQL Row with named fields
Posted by Vladislav Keda <vl...@glowbyteconsulting.com>.
Thanks a lot!
---
Best Regards,
Vladislav Keda
чт, 3 февр. 2022 г. в 12:13, Francesco Guardiani <fr...@ververica.com>:
> Hi,
>
> Unfortunately at the moment, creating a row with named fields is not
> possible from the ROW constructor.
>
> One solution could be to wrap it in a cast, like: CAST((f0 + 12, 'Hello
> world') AS ROW<i INT, s STRING>)
> Or you could create a UDF and use the @DataTypeHint to define the row
> return type, with named fields.
>
> Feel free to open an issue about that
>
> FG
>
> On Wed, Feb 2, 2022 at 5:18 PM Vladislav Keda <
> vladislav.keda@glowbyteconsulting.com> wrote:
>
>> Hi,
>>
>> I'm trying to create Row(..) using Flink SQL, but I can't assign names to
>> its fields.
>>
>>
>> *For example:*Input table1 structure:* (id INT, some_name STRING)*
>> Query: *select *, ROW(id, some_name) as row1 from table1*
>> Output result structure:
>> *(id INT , some_name STRING, row1 ROW (EXPR$0 INT, EXPR$1 STRING))*
>>
>> *Each nested field has a name like EXPR$<N> that does not satisfy me.*
>>
>> *If I write, for example:*Input table1 structure:* (id INT, some_name
>> STRING)*
>> Query: *select *, ROW(id as nested_id, some_name as nested_some_name)
>> as row1 from table1*
>> Output result structure: *(id INT , some_name STRING, row1 ROW (EXPR$0
>> INT, EXPR$1 STRING))*
>>
>>
>> *I will get an exception like: *
>>
>>
>>
>>
>>
>>
>>
>>
>> *Caused by: org.apache.flink.table.api.SqlParserException: SQL parse
>> failed. Encountered "as" at line 1, column 20.Was expecting one of: ")"
>> ... "," ... at
>> org.apache.flink.table.planner.parse.CalciteParser.parse(CalciteParser.java:56)
>> at
>> org.apache.flink.table.planner.delegation.ParserImpl.parse(ParserImpl.java:98)
>> at
>> org.apache.flink.table.api.internal.TableEnvironmentImpl.sqlQuery(TableEnvironmentImpl.java:704)
>> at
>> ru.glowbyte.streaming.core.operators.internal.sql.SqlDrivenOperator.sqlQuery(SqlDrivenOperator.java:159)
>> ... 59 more*
>>
>> How can I set the name for the field?
>>
>> Flink version - 1.13.3.
>>
>> ---
>>
>> Best Regards,
>> Vladislav Keda
>>
>
Re: Creating Flink SQL Row with named fields
Posted by Francesco Guardiani <fr...@ververica.com>.
Hi,
Unfortunately at the moment, creating a row with named fields is not
possible from the ROW constructor.
One solution could be to wrap it in a cast, like: CAST((f0 + 12, 'Hello
world') AS ROW<i INT, s STRING>)
Or you could create a UDF and use the @DataTypeHint to define the row
return type, with named fields.
Feel free to open an issue about that
FG
On Wed, Feb 2, 2022 at 5:18 PM Vladislav Keda <
vladislav.keda@glowbyteconsulting.com> wrote:
> Hi,
>
> I'm trying to create Row(..) using Flink SQL, but I can't assign names to
> its fields.
>
>
> *For example:*Input table1 structure:* (id INT, some_name STRING)*
> Query: *select *, ROW(id, some_name) as row1 from table1*
> Output result structure:
> *(id INT , some_name STRING, row1 ROW (EXPR$0 INT, EXPR$1 STRING))*
>
> *Each nested field has a name like EXPR$<N> that does not satisfy me.*
>
> *If I write, for example:*Input table1 structure:* (id INT, some_name
> STRING)*
> Query: *select *, ROW(id as nested_id, some_name as nested_some_name) as
> row1 from table1*
> Output result structure: *(id INT , some_name STRING, row1 ROW (EXPR$0
> INT, EXPR$1 STRING))*
>
>
> *I will get an exception like: *
>
>
>
>
>
>
>
>
> *Caused by: org.apache.flink.table.api.SqlParserException: SQL parse
> failed. Encountered "as" at line 1, column 20.Was expecting one of: ")"
> ... "," ... at
> org.apache.flink.table.planner.parse.CalciteParser.parse(CalciteParser.java:56)
> at
> org.apache.flink.table.planner.delegation.ParserImpl.parse(ParserImpl.java:98)
> at
> org.apache.flink.table.api.internal.TableEnvironmentImpl.sqlQuery(TableEnvironmentImpl.java:704)
> at
> ru.glowbyte.streaming.core.operators.internal.sql.SqlDrivenOperator.sqlQuery(SqlDrivenOperator.java:159)
> ... 59 more*
>
> How can I set the name for the field?
>
> Flink version - 1.13.3.
>
> ---
>
> Best Regards,
> Vladislav Keda
>