RisingWave makes it possible to do real-time ad performance analysis in a low code manner.
psql
, is installed in your environment. For detailed instructions, see Download PostgreSQL.integration_tests/ad-ctr
directory and start the demo cluster from the docker compose file.
docker compose
. See details in the Docker docs.If you’re using Compose V1, use docker-compose
instead.impression_timestamp
is the date and time when an ad is presented to a viewer, and bid_id
is the identifier of a bid request or activity for an online ad. When we calculate click-through rates, we must make sure that the impressions and the clicks are for the same bid request / activity. Otherwise, the results will be meaningless.
impression_timestamp
should always be smaller (earlier) than click_timestamp
.
Now that we already set up these two data streams in Kafka (in JSON) using the demo cluster, we can connect to these two streams with the following SQL statements.
scan.startup.mode = 'earliest'
means the source will start streaming from the earliest entry in Kafka. Internally, RisingWave will record the consumed offset in the persistent state so that during a failure recovery, it will resume from the last consumed offset.ad_id
, and calculate CTR based on the latest impressions and clicks.
ad_ctr_5min
, to calculate the time-windowed CTR. This view will distribute the impression events into time windows and aggregate the impression count for each ad in each time window. You can replace 5 minutes with whatever time window that works for you.
ad_ctr_5min
. The CTR value is dynamically changing and every ad CTR in a given window can be drawn as a plot in the line chart. Eventually, we are able to analyze how CTR changes over time.