加入kafka ksql(0.12.0)

hs1rzwqc  于 2021-06-04  发布在  Kafka
关注(0)|答案(0)|浏览(387)

我使用的是ksqlversion0.12.0,无法理解连接。我来自一个坚实的关系基础(postgres、oracle、mysql),最近开始使用kafka,特别是ksql。
我创建了下面的表和流,因为我的目标是理解ksql,在我的示例中,我想连接3个表,它们有一个共同的列(id)。结果并不是我所理解的join,我想要你们中的任何一个解释,我在我的理解中遗漏了什么。

create table fornecedores(id int primary key, name varchar) 
with(
  kafka_topic='fornecedores', 
  value_format='JSON', 
  partitions=1, 
  replicas=1
);
insert into fornecedores(id,name) values(1,'marcia');

create table racas(id int primary key, name varchar) 
with(
   kafka_topic='racas', 
   value_format='JSON', 
   partitions=1, 
   replicas=1
);
insert into racas(id,name) values(1,'duroc');
insert into racas(id,name) values(2,'landrace');

create table tipos(id int primary key, name varchar) 
with(
   kafka_topic='tipos', 
   value_format='JSON', 
   partitions=1, 
   replicas=1
);
insert into tipos(id,name) values(1,'suinos');
insert into tipos(id,name) values(2,'bovinos');

create stream eventos(id int key, raca_id int, fornecedor_id int, tipo_id int)
with(
   kafka_topic='eventos', 
   value_format='JSON', 
   partitions=1, 
   replicas=1
);
insert into eventos(id, raca_id, fornecedor_id, tipo_id) values(1, 1, 1, 1);
insert into eventos(id, raca_id, fornecedor_id, tipo_id) values(2, 2, 1, 1);
insert into eventos(id, raca_id, fornecedor_id, tipo_id) values(3, 1, 1, 2);

create stream eventos_racas 
as 
  select id, raca_id from eventos partition by raca_id;

create stream eventos_racas_raw 
as 
  select e.id as id, e.raca_id as raca_id, x.name as name 
  from eventos_racas e 
  inner join racas x on e.raca_id = x.id 
  partition by e.id;

create table eventos_racas_tbl(id int primary key, raca_id int, name varchar)
with(
   kafka_topic='EVENTOS_RACAS_RAW', 
   value_format='JSON'
);

create stream eventos_fornecedores 
as 
  select id, fornecedor_id 
  from eventos 
  partition by fornecedor_id;

create stream eventos_fornecedores_raw 
as 
  select e.id as id, e.fornecedor_id as fornecedor_id, x.name as name 
  from eventos_fornecedores e 
  inner join fornecedores x on e.fornecedor_id = x.id 
  partition by e.id;

create table eventos_fornecedores_tbl(id int primary key, fornecedor_id int, name varchar)
with(
  kafka_topic='EVENTOS_FORNECEDORES_RAW', 
  value_format='JSON'
);

create stream eventos_tipos 
as 
  select id, tipo_id 
  from eventos 
  partition by tipo_id;

create stream eventos_tipos_raw 
as 
  select e.id as id, e.tipo_id as tipo_id, x.name as name 
  from eventos_tipos e 
  inner join tipos x on e.tipo_id = x.id 
  partition by e.id;

create table eventos_tipos_tbl(id int primary key, tipo_id int, name varchar)
with(
   kafka_topic='EVENTOS_TIPOS_RAW', 
   value_format='JSON'
);

Finally the last select to join all 3 tables;

select * 
from eventos_racas_tbl e 
inner join eventos_fornecedores_tbl x on e.id = x.id 
inner join eventos_tipos_tbl y on e.id = y.id 
emit changes;

but the result seems to me more like a UNION than a JOIN.

你们谁能帮我理解吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题