flinkSql join redis的hash結構維表簡單實現

wppwpp1發表於2020-11-20


CREATE TABLE source_table (
  --必須和Kafka源表中的5個欄位的順序保持一致。
  messageKey VARBINARY,
  `message` VARBINARY,
  `topic` VARCHAR,
  `partition` INT,
  `offset` BIGINT
) WITH (
  `type` = 'kafka011',
  `topic` = 'kafka_test',
  `group.id` = 'kafka_test_wpp',
  `bootstrap.servers` = 'xx.xx.xx:9092'
 -- `startupMode` = 'TIMESTAMP'
);



create table redis_dim (
    id VARCHAR,
    name VARCHAR,
    PRIMARY KEY (id), 
    PERIOD FOR SYSTEM_TIME
  ) with (
  type = 'redis',
  host = '127.0.0.1',
  port = '6379',
  dbNum = '0',
  password = 'pass',
  hashName='hashtest'
);


create table sink_print2(
    mes varchar,
    name VARCHAR
)with(
    type='print'
);



insert into sink_print2 
SELECT 
cast (e.`message` as varchar),
 w.name
from source_table as e left join redis_dim FOR SYSTEM_TIME AS OF PROCTIME() AS w
on cast(e.message as varchar )  = w.id
; 

維表join相關測試案例

相關文章