Really trying to understand how to use flink here,...
# troubleshooting
d
Really trying to understand how to use flink here, and so far failing. I have an existing algorithm, written in pandas code that looks at a series of data points and enriches them using pandas. It then returns a cleaned up data set which removes outliers and accounts for discontinuity among other things. I cannot seem to get this to work inline in pyFlink where I can do:
Copy code
df = table.to_pandas()
clean_up_data_(df)
clean_table = t_env.from_pandas(df)
I can't really find any documentation on this use case, and it seem like doing this in a udf might be the way to go, but even that seems to only get multiple columns of a table. Ideally i'm doing this over a time window of data and only emitting the clean data.
seems like maybe this is limited to batch mode only, and cannot be done in streaming mode
m
Hey, hopefully you find this helpful - if you’re looking at each data point as an individual element/row/object - then you can apply your time filter to “allow” the elements that fit to go “down stream.” So that’s something like: intitialDataStream.filter(thing where thing.time is < something)
Okay so now you should have handled the temporal filtering. For enrichment yeah, a udf would work and you can supply multiple columns it looks like: https://nightlies.apache.org/flink/flink-docs-release-1.17/docs/dev/table/functions/udfs/
d
But if I write a udf i'm not receiving a data frame it seems to be a single row
I need to inspect the old data to build my model
m
Generally in Java-land we may use a process function and only tell the context to collect after some “complex” logic
Yeah, so maybe that’s a bit of confusion between pandas and Flink there’s good documentation there
From what I remember when you say pandas conversion you’re basically ending the Flink stream and collecting the results (so no more multi processing is happening)
For your algorithm to be distributed by Flink you need to move the logic out of Pandas-land
And use Flink’s operators - map, process, flat map, udfs, etc
d
That would be ideal, I think there is little appetite to rewrite the legacy code
ok thanks
👍 1
Whats the recommended path when you have a legacy module like this that you need to run inline in a stream?
When I worked on kafka streams we would issue an RPC which was always error prone
m
It really depends, my past experience - enrichment would be an HTTP API call or database look up.
Things where you have logic across the “whole” dataset still fit best within the framework imo
d
Got it