Hello Folks, I'm new to Flink and have a specific ...
# troubleshooting
p
Hello Folks, I'm new to Flink and have a specific use case where my incoming data is in the following format and is running in streaming mode:
Copy code
{"timestamp": 1706928619000, "id": 1419, "user_id": "17ebbfd7-3e4f-4197-b504-82df1c5d06b6", "page category": 76, "url": "news.com"}
{"timestamp": 1707229698000, "id": 1412, "user_id": "124443f8-5a58-48b7-9874-779a649d7fae", "page category": 89, "url": "sports.com"}
{"timestamp": 1707229698000, "id": 1412, "user_id": "124443f8-5a58-48b7-9874-779a649d7fae", "page category": 89, "url": "sports.com"}
I want to filter out the duplicate user_id logs for a period of a month, the logs shouldn't be duplicate, and only unique user logs should sink to Kafka. The data is high volume logs. I'm considering using DataSketches library for techniques like Bloom filtering or count min sketch. I also want to backup and restore the state of the Bloom filter. Can this be achieved using Flink?
m
Yes that can be solved with Apache Flink. I can think of multiple techniques to solve that. However, the easiest one would probably to implement a
KeyedProcessFunction
with the
user_id
as your key. Add a ValueState with a TTL of one month. It could be a simple boolean. If that value state is there, then do not collect the record (like a filter). If that value state is not there, collect the record and assign the value state.
πŸ™Œ 1
p
Thank you for clearing the doubt.
m
wait, I need clarification. My solution only assures that the user_id can log something once per month. So:
Copy code
{"timestamp": 1707229698000, "id": 1412, "user_id": "124443f8-5a58-48b7-9874-779a649d7fae", "page category": 89, "url": "sports.com"}
{"timestamp": 1707229698000, "id": 1412, "user_id": "124443f8-5a58-48b7-9874-779a649d7fae", "page category": 90, "url": "movies.com"}
would only log the first entry.
Is that what you meant?
p
Yes
The solution you suggest is similar to the example mentioned at https://nightlies.apache.org/flink/flink-docs-release-1.19/docs/try-flink/datastream/#final-application, whereI don't need any approximation algorithm like Bloom filter ? I'm I correct on this ?