有没有一种方法可以使用JDBC接收器连接器使用出口字段值进行更新?
我想实现页面视图计数。每次访问该页面时,将发布一个事件给Kafka。该事件包括pageID和日期。 我想使用JDBC连接器来增加页面计数与页面和日期相对。
JDBC接收器连接器是否可以?如何进行?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以将
insert.mode
设置为upSert
或update> update
而不是默认值。请记住,数据库查询将 oftrite count字段,而不是增加它(因为这不是
更新
查询的工作方式),因此您必须运行其他一些过程在写入数据库之前总计总数。您还可以从KAFKA数据中完全删除计数,并且只有一个“页面视图日志”的表,然后运行
选择日期,页面,计数(*)组按日期,页面;
直接在数据库中。Yes, you can set
insert.mode
toupsert
orupdate
rather than the default.Keep in mind that the database query will overwrite the count field, not increase it (as this is not how
UPDATE
queries work), so you must run some other process that will sum the total counts before writing to the database.https://docs.confluent.io/kafka-connect-jdbc/current/sink-connector/sink_config_options.html#writes
https://rmoff.net/2021/03/12/kafka-connect-jdbc-sink-deep-dive-working-with-primary-keys/
You could also remove the count completely from the Kafka data, and just have a table of "page view logs", then run
SELECT date, page, COUNT(*) GROUP BY date, page;
in the database directly.