This question follows this one.
The main task is to make joins on KSQL side. Example below will illustrate it. Incidents messages arrive In Kafka topic. The structure of that messages:
[
{
"name": "from_ts",
"type": "bigint"
},
{
"name": "to_ts",
"type": "bigint"
},
{
"name": "rulenode_id",
"type": "int"
}
]
And there is a Postgres table rulenode:
id | name | description
Data from both sources need to be joined by fields rulenode_id = rulenode.id so as to get single record with fields from_ts, to_ts, rulenode_id, rulenode_name, rulenode_description.
I want to do this by means of KSQL but not backend as it is now.
Right now data from Postgres table transferred to Kafka by JdbcSourceConnector. But there is one little problem - as you could guess data in Postgres table may be changed. And of course these changes should be in KSQL stream OR table too.
Below I've been asked why KTable and not Kstream. Well, please, visit this page and look at the first GIF. There records of table are being updated when new data arrive. I thought such behaviour is what I need (where instead of names Alice, Bob I have primary key id of Postgres table rulenode). That's why I chose KTable.
Bulk mode of JdbcSourceConnect copies all of the table. And as you know all rows arrive into Kafka table to previous Postgres table snapshots.
As suggested I created a connector with configs:
{
"name": "from-pg",
"connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector",
"errors.log.enable": "true",
"connection.url": "connection.url",
"connection.user": "postgres",
"connection.password": "*************",
"table.whitelist": "rulenode",
"mode": "bulk",
"poll.interval.ms": "5000",
"topic.prefix": "pg."
}
Then created a stream:
create stream rulenodes
with (kafka_topic='pg.rules_rulenode', value_format='avro', key='id');
and now trying to create a table:
create table rulenodes_unique
as select * from rulenodes;
but that didn't work with error:
Invalid result type. Your SELECT query produces a STREAM. Please use CREATE STREAM AS SELECT statement instead.
I read that tables are used when to store aggregated info. For example to store aggregated with COUNT function:
create table rulenodes_unique
as select id, count(*) from rulenodes order by id;
Can you say please how to handle that error?