【问题标题】:How to write Kafka Connect query to query data between two specific dates using timestamp mode如何编写 Kafka Connect 查询以使用时间戳模式查询两个特定日期之间的数据
【发布时间】:2021-03-04 11:11:11
【问题描述】:

我正在编写一个 Kakfa JDBC 源连接器来查询 Postgres 表中的两个日期(开始日期和结束日期),并希望连接器从结束日期到开始日期每天运行查询。这可能吗? select * from table where date is between '2020-08-01' and ending_date='2020-10-31'

【问题讨论】:

  • 你是自己写的,还是配置现有的??当前向连接器提供此查询时会发生什么?

标签: jdbc apache-kafka apache-kafka-connect confluent-platform


【解决方案1】:

您可以通过定义filter.condition 来使用Confluent Filter SMT。

链接中提供了一个示例,如下所示:

transforms=filterDateExample
# Use the 'io.confluent.connect.transforms.Filter$Value' as the source (record 'value') on which
# 'filter.condition' shall be applied.
transforms.filterDateExample.type=io.confluent.connect.transforms.Filter$Value
transforms.filterDateExample.filter.condition=$.key[?(@.date >= "2020-08-01" && @.date <= "2020-10-31")]
# Use 'include' to pass through all records that match the predicate.
transforms.filterDateExample.filter.type=include
# Use the 'fail' behavior to throw an exception and fail the connector task when the record does
# not have the field(s) used in the 'filter.condition'.
transforms.filterDateExample.missing.or.null.behavior=fail

它似乎无法识别日期类型,因此您可能还想查看Timestamp Converter。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 2020-02-29
    • 2014-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多