Flink动态表和流连接

时间:2018-08-18 08:37:18

标签: apache-flink flink-streaming

我正在尝试根据某些字段从动态表和流中派生新表。

有人可以指导执行此操作的最佳方法。我是flink尝试事物的新手。

//Dynamic Table

Table books = tEnv.sqlQuery("SELECT bookId, instrument, sum(tradedQuanity) as totalQuantity FROM tradeStreamTable group by bookId, instrument");

tEnv.registerTable("books", books);

===========================
图书编号,工具,数量
Book1,Goog,100
Book2,Vod,10
图书1,应用,50
Book2,Goog,60
Book1,Vod,130
Book3,Appl,110

//My Stream

tEnv.registerDataStream("allInstrumentsTable", allInstruments, "timeStampMs, instrument, instrumentValue ");

allInstrumentsTable

=======================================
“ timeStampMs,工具,工具Value(价格)
流......

=======================================

每当我在书本表中获得新的更改或流中乐器的新instrumentValue时,我都试图派生新表(动态)。加入仪器,InstrumentValue * totalQuantity。

预订-最新价格(新表)

====================================
BookId,工具,数量,工具价值* totalQuantity
Book1,Goog,100,1203
Book1,Appl,50,...
Book1,Vod,130,...
Book2,Vod,10,...
Book2,Goog,60,...
Book3,Appl,110,...

1 个答案:

答案 0 :(得分:0)

您不能从外部“更新”表。流中的表就像RDBMS中的物化视图。它们是在特定时间点上对流状态的派生视图。

您可以做的是从这两个表中派生一个新表

SELECT instrument, instrumentValue * totalQuantity FROM allInstrumentsTable aJOIN books b ON a.instrument = b.instrument;

由于这是非窗口联接,因此您还应该考虑一些保留policies,以确保状态不会无限期增长。