You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Francis Conroy <fr...@switchdin.com> on 2022/02/16 00:07:17 UTC
Change column names Pyflink Table/Datastream API
Hi all,
I'm hoping to be able to change the column names when creating a table from
a datastream, the flatmap function generating the stream is returning a
Tuple4.
It's currently working as follows:
inputmetrics = table_env.from_data_stream(ds, Schema.new_builder()
.column("f0", "BIGINT")
.column("f1", "STRING")
.column("f2", "STRING")
.column("f3", "DOUBLE")
.build())
I'm trying to rename the columns f0, f1, f2, f3 to proper names e.g.
timestamp, device, name, value. So far I've tried using from_fields, and
column_by_expression("timestamp", "f0")
I'd prefer not to change the output type of my previous flatMapFunction (to
say a named Row) for performance purposes.
Thanks,
Francis
--
This email and any attachments are proprietary and confidential and are
intended solely for the use of the individual to whom it is addressed. Any
views or opinions expressed are solely those of the author and do not
necessarily reflect or represent those of SwitchDin Pty Ltd. If you have
received this email in error, please let us know immediately by reply email
and delete it from your system. You may not use, disseminate, distribute or
copy this message nor disclose its contents to anyone.
SwitchDin Pty Ltd
(ABN 29 154893857) PO Box 1165, Newcastle NSW 2300 Australia
Re: Change column names Pyflink Table/Datastream API
Posted by Francis Conroy <fr...@switchdin.com>.
Hi Dian,
Using .alias ended up working for me. Thanks for getting back to me.
On Thu, 17 Feb 2022 at 01:15, Dian Fu <di...@gmail.com> wrote:
> Hi Francis,
>
> There should be multiple ways to achieve this. Do you mean that all these
> methods don't work for you? If so, could you show the sample code? Besides,
> another way you may try is `inputmetrics.alias("timestamp, device, name,
> value")`.
>
> Regards,
> Dian
>
> On Wed, Feb 16, 2022 at 8:14 AM Francis Conroy <
> francis.conroy@switchdin.com> wrote:
>
>> Hi all,
>>
>> I'm hoping to be able to change the column names when creating a table
>> from a datastream, the flatmap function generating the stream is returning
>> a Tuple4.
>>
>> It's currently working as follows:
>>
>> inputmetrics = table_env.from_data_stream(ds, Schema.new_builder()
>> .column("f0", "BIGINT")
>> .column("f1", "STRING")
>> .column("f2", "STRING")
>> .column("f3", "DOUBLE")
>> .build())
>>
>> I'm trying to rename the columns f0, f1, f2, f3 to proper names e.g.
>> timestamp, device, name, value. So far I've tried using from_fields, and
>>
>> column_by_expression("timestamp", "f0")
>>
>> I'd prefer not to change the output type of my previous flatMapFunction
>> (to say a named Row) for performance purposes.
>>
>> Thanks,
>> Francis
>>
>> This email and any attachments are proprietary and confidential and are
>> intended solely for the use of the individual to whom it is addressed. Any
>> views or opinions expressed are solely those of the author and do not
>> necessarily reflect or represent those of SwitchDin Pty Ltd. If you have
>> received this email in error, please let us know immediately by reply email
>> and delete it from your system. You may not use, disseminate, distribute or
>> copy this message nor disclose its contents to anyone.
>> SwitchDin Pty Ltd (ABN 29 154893857) PO Box 1165, Newcastle NSW 2300
>> Australia
>>
>
--
This email and any attachments are proprietary and confidential and are
intended solely for the use of the individual to whom it is addressed. Any
views or opinions expressed are solely those of the author and do not
necessarily reflect or represent those of SwitchDin Pty Ltd. If you have
received this email in error, please let us know immediately by reply email
and delete it from your system. You may not use, disseminate, distribute or
copy this message nor disclose its contents to anyone.
SwitchDin Pty Ltd
(ABN 29 154893857) PO Box 1165, Newcastle NSW 2300 Australia
Re: Change column names Pyflink Table/Datastream API
Posted by Dian Fu <di...@gmail.com>.
Hi Francis,
There should be multiple ways to achieve this. Do you mean that all these
methods don't work for you? If so, could you show the sample code? Besides,
another way you may try is `inputmetrics.alias("timestamp, device, name,
value")`.
Regards,
Dian
On Wed, Feb 16, 2022 at 8:14 AM Francis Conroy <fr...@switchdin.com>
wrote:
> Hi all,
>
> I'm hoping to be able to change the column names when creating a table
> from a datastream, the flatmap function generating the stream is returning
> a Tuple4.
>
> It's currently working as follows:
>
> inputmetrics = table_env.from_data_stream(ds, Schema.new_builder()
> .column("f0", "BIGINT")
> .column("f1", "STRING")
> .column("f2", "STRING")
> .column("f3", "DOUBLE")
> .build())
>
> I'm trying to rename the columns f0, f1, f2, f3 to proper names e.g.
> timestamp, device, name, value. So far I've tried using from_fields, and
>
> column_by_expression("timestamp", "f0")
>
> I'd prefer not to change the output type of my previous flatMapFunction
> (to say a named Row) for performance purposes.
>
> Thanks,
> Francis
>
> This email and any attachments are proprietary and confidential and are
> intended solely for the use of the individual to whom it is addressed. Any
> views or opinions expressed are solely those of the author and do not
> necessarily reflect or represent those of SwitchDin Pty Ltd. If you have
> received this email in error, please let us know immediately by reply email
> and delete it from your system. You may not use, disseminate, distribute or
> copy this message nor disclose its contents to anyone.
> SwitchDin Pty Ltd (ABN 29 154893857) PO Box 1165, Newcastle NSW 2300
> Australia
>