有没有一种方法可以使用JDBC接收器连接器使用出口字段值进行更新?

发布于 2025-02-03 09:38:50 字数 113 浏览 3 评论 0 原文

我想实现页面视图计数。每次访问该页面时,将发布一个事件给Kafka。该事件包括pageID和日期。 我想使用JDBC连接器来增加页面计数与页面和日期相对。

JDBC接收器连接器是否可以?如何进行?

I want to implement the page view count. On each visit to the page, an event will be published to Kafka. The event includes pageId and Date.
I want to use the JDBC connector to increase the page count against the pageId and date.

Is it possible with JDBC Sink connector? How to proceed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空宴 2025-02-10 09:38:50

是的,您可以将 insert.mode 设置为 upSert update> update 而不是默认值。

请记住,数据库查询将 oftrite count字段,而不是增加它(因为这不是更新查询的工作方式),因此您必须运行其他一些过程在写入数据库之前总计总数。

您还可以从KAFKA数据中完全删除计数,并且只有一个“页面视图日志”的表,然后运行选择日期,页面,计数(*)组按日期,页面; 直接在数据库中。

Yes, you can set insert.mode to upsert or update 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文