查询模式下的kafka jdbc源连接器错误

时间:2019-06-27 07:46:45

标签: postgresql jdbc apache-kafka

我在kafka中有一个JDBCSourceConnector,它使用查询从数据库流数据。 但是我写的选择数据查询有问题。

我在Postgres psql和DBeaver中测试了查询。它工作正常,但在kafka配置中,会产生SQL语法错误

错误

  

ERROR无法运行对表TimestampIncrementingTableQuerier {name ='null'的查询,查询='选择“ Users”。*来自“ Users”的用户在“ Users”上加入“ SchoolUserPivots”。id=“ SchoolUserPivots”。user_id其中school_id = 1和role_id = 2',topicPrefix ='teacher',timestampColumn ='“ Users” .updatedAt',incrementingColumn ='id'}:{}(io.confluent.connect.jdbc.source.JdbcSourceTask:221)   org.postgresql.util.PSQLException:错误:“ WHERE”处或附近的语法错误

配置json

 {
  "connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector",
  "timestamp.column.name": "\"Users\".updatedAt",
  "incrementing.column.name": "id",
  "connection.password": "123",
  "tasks.max": "1",
  "query": "select \"Users\".* from \"Users\" join \"SchoolUserPivots\" on \"Users\".id = \"SchoolUserPivots\".user_id where school_id = 1 and role_id = 2",
  "timestamp.delay.interval.ms": "5000",
  "mode": "timestamp+incrementing",
  "topic.prefix": "teacher",
  "connection.user": "user",
  "name": "SourceTeacher",
  "connection.url": "jdbc:postgresql://ip:5432/school",
  "value.converter": "org.apache.kafka.connect.json.JsonConverter",
  "key.converter": "org.apache.kafka.connect.json.JsonConverter"
}

1 个答案:

答案 0 :(得分:2)

您不能将"mode": "timestamp+incrementing",与包含query的自定义WHERE一起使用。

有关更多详细信息,请参见https://www.confluent.io/blog/kafka-connect-deep-dive-jdbc-source-connector,以及https://github.com/confluentinc/kafka-connect-jdbc/issues/566。该github问题提出了一种解决方法,方法是对查询使用子选择。