You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Andres Angel <in...@gmail.com> on 2019/07/24 12:44:08 UTC
Accessing variables build within a map/flatmap function within a DS
Hello everyone,
I was wondering if there is a way how to read the content of a varible
build within a map/flatmap function out of the DS method.
example:
DataStream<String> dsString = env.fromElements("1,a,1.1|2,b,2.2,-2",
"3,c|4,d,4.4");
DataStream<Object> dsTuple = dsString.flatMap(new
FlatMapFunction<String, Object>() {
@Override
public void flatMap(String value, Collector<Object> out) throws
Exception {
String var1 = "dummy";
}
});
System.out.print(var1);
thanks so much
Re: Accessing variables build within a map/flatmap function within a DS
Posted by Andres Angel <in...@gmail.com>.
Sure guys thanks for the support.
I need to create an register a table based on the content of a DS<>, the
point is that within the content I need to parse it somehow and get the
part which is the values and the headers. I already tried to create a DS
and register the new DS as table with headers and values catch within the
anonymous function.
However the anonymous function can not reach my env and tenv. therefore I
can yes create the DS with values but I need to store the headers to be
accessed out from the anonymous and register the tenv with the content of
the new DS and the headers from my variable. I bit weird maybe I know but
this is what we need :).
AU
On Wed, Jul 24, 2019 at 9:01 AM Chesnay Schepler <ch...@apache.org> wrote:
> Note that this will only work when running the the application in the IDE;
> specifically it will not work when running on an actual cluster, since your
> function isn't executed on the same machine as your (presumably) main[]
> function.
>
> We can give you better advice if you tell us what exactly you're trying to
> achieve.
>
> On 24/07/2019 14:53, Caizhi Weng wrote:
>
> Hi Andres,
>
> Just define a variable outside and modify it in the anonymous class.
>
> Andres Angel <in...@gmail.com> 于2019年7月24日周三 下午8:44写道:
>
>> Hello everyone,
>>
>> I was wondering if there is a way how to read the content of a varible
>> build within a map/flatmap function out of the DS method.
>>
>> example:
>>
>> DataStream<String> dsString = env.fromElements("1,a,1.1|2,b,2.2,-2",
>> "3,c|4,d,4.4");
>> DataStream<Object> dsTuple = dsString.flatMap(new
>> FlatMapFunction<String, Object>() {
>> @Override
>> public void flatMap(String value, Collector<Object> out) throws
>> Exception {
>> String var1 = "dummy";
>>
>> }
>> });
>>
>> System.out.print(var1);
>>
>> thanks so much
>>
>
>
Re: Accessing variables build within a map/flatmap function within a
DS
Posted by Chesnay Schepler <ch...@apache.org>.
Note that this will only work when running the the application in the
IDE; specifically it will not work when running on an actual cluster,
since your function isn't executed on the same machine as your
(presumably) main[] function.
We can give you better advice if you tell us what exactly you're trying
to achieve.
On 24/07/2019 14:53, Caizhi Weng wrote:
> Hi Andres,
>
> Just define a variable outside and modify it in the anonymous class.
>
> Andres Angel <ingenieroandresangel@gmail.com
> <ma...@gmail.com>> 于2019年7月24日周三
> 下午8:44写道:
>
> Hello everyone,
>
> I was wondering if there is a way how to read the content of a
> varible build within a map/flatmap function out of the DS method.
>
> example:
>
> DataStream<String> dsString =
> env.fromElements("1,a,1.1|2,b,2.2,-2", "3,c|4,d,4.4");
> DataStream<Object> dsTuple = dsString.flatMap(new
> FlatMapFunction<String, Object>() {
> @Override
> public void flatMap(String value, Collector<Object> out)
> throws Exception {
> String var1 = "dummy";
>
> }
> });
>
> System.out.print(var1);
>
> thanks so much
>
Re: Accessing variables build within a map/flatmap function within a DS
Posted by Caizhi Weng <ts...@gmail.com>.
Hi Andres,
Just define a variable outside and modify it in the anonymous class.
Andres Angel <in...@gmail.com> 于2019年7月24日周三 下午8:44写道:
> Hello everyone,
>
> I was wondering if there is a way how to read the content of a varible
> build within a map/flatmap function out of the DS method.
>
> example:
>
> DataStream<String> dsString = env.fromElements("1,a,1.1|2,b,2.2,-2",
> "3,c|4,d,4.4");
> DataStream<Object> dsTuple = dsString.flatMap(new
> FlatMapFunction<String, Object>() {
> @Override
> public void flatMap(String value, Collector<Object> out) throws
> Exception {
> String var1 = "dummy";
>
> }
> });
>
> System.out.print(var1);
>
> thanks so much
>