From 74fa89e7ff14f14cfae62001d60cc5a0ce9fd4f1 Mon Sep 17 00:00:00 2001 From: Yeva Byzek Date: Mon, 2 Oct 2017 21:26:16 -0400 Subject: [PATCH] KSQL-378: content-based routing --- docs/examples.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/examples.md b/docs/examples.md index 3e01b24e7ac2..f97d684679bf 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -129,6 +129,36 @@ CREATE STREAM pageviews_transformed \ PARTITION BY userid; ``` +Use a `[ WHERE condition ]` clause to select a subset of data. If you want to route streams with different criteria to different streams backed by different underlying Kafka topics, e.g. content-based routing, write multiple KSQL statements as follows: + +```sql +CREATE STREAM pageviews_transformed_priority_1 \ + WITH (timestamp='viewtime', \ + partitions=5, \ + value_format='JSON') AS \ + SELECT viewtime, \ + userid, \ + pageid, \ + TIMESTAMPTOSTRING(viewtime, 'yyyy-MM-dd HH:mm:ss.SSS') AS timestring \ + FROM pageviews \ + WHERE userid='User_1' OR userid='User_2' \ + PARTITION BY userid; +``` + +```sql +CREATE STREAM pageviews_transformed_priority_2 \ + WITH (timestamp='viewtime', \ + partitions=5, \ + value_format='JSON') AS \ + SELECT viewtime, \ + userid, \ + pageid, \ + TIMESTAMPTOSTRING(viewtime, 'yyyy-MM-dd HH:mm:ss.SSS') AS timestring \ + FROM pageviews \ + WHERE userid<>'User_1' AND userid<>'User_2' \ + PARTITION BY userid; +``` + ### Joining