This question evaluates event-stream processing, stateful per-user counting, and time-window filtering competencies, requiring correctness with ordered inputs and enforcement of per-offer redemption constraints.
You are given a set of promotional offers and a CSV event stream read from standard input.
Each Offer has the following fields:
name
: string
start_at
: timestamp
end_at
: timestamp
user_max_redemption_count
: integer
Each OfferEvent row has:
user_id
: string
offer_name
: string
event_time
: timestamp
Each event represents one redemption attempt by a user for an offer.
Process the events in the order they appear. An event should be counted only if all of the following are true:
start_at <= event_time <= end_at
,
user_max_redemption_count
times.
You are also given a PROCESSING_DATE.
After all events are processed, compute the offers that are still available to each user. An offer is available to a user on PROCESSING_DATE if:
start_at <= PROCESSING_DATE <= end_at
, and
user_max_redemption_count
.
Return a mapping from each user to the list of currently available offer names. If a user appears in the input but has no available offers, return an empty list for that user.
Example output:
{
'user1': ['Offer_1', 'Offer_2'],
'user2': ['Offer_1']
}
For deterministic output, sort each user's offer list lexicographically.