简体   繁体   English

kafka jdbc 源连接器:时间戳模式不适用于 sqlite3

[英]kafka jdbc source connector: time stamp mode is not working for sqlite3

I tried to set up a database with a table with timestamp column .我试图建立一个带有时间戳列的表的数据库。 I am trying to implement timestamp mode to capture incremental changes in the DB.我正在尝试实施时间戳模式来捕获数据库中的增量更改。

But kafka-connect-jdbc is not reading any data from the table.但是 kafka-connect-jdbc 没有从表中读取任何数据。 Here is what I have done.这是我所做的。

Created a table.创建了一个表。

sqlite> CREATE TABLE test_timestamp(id integer primary key not null,
   ...>                   payment_type text not null,
   ...>                   Timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
   ...>                   user_id int not null);
sqlite> INSERT INTO test_timestamp (ID, PAYMENT_TYPE, USER_ID) VALUES (3,'FOO',1);
sqlite> select * from test_timestamp;
3|FOO|2019-06-18 05:31:22|1

My jdbc-source connector configuration is as follows:我的 jdbc-source 连接器配置如下:

$ curl -s "http://localhost:8083/connectors/jdbc-source/config"|jq '.'
{
  "connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector",
  "mode": "timestamp",
  "timestamp.column.name": "timestamp",
  "topic.prefix": "testdb-",
  "validate.non.null": "false",
  "tasks.max": "1",
  "name": "jdbc-source",
  "connection.url": "jdbc:sqlite:/tmp/test.db"
}

jdbc-source-connector successfully loads and topic is created jdbc-source-connector 成功加载并创建主题

$ kafka-topics --list --bootstrap-server localhost:9092
..
testdb-test_timestamp

But no data appears in the topic.但是主题中没有出现任何数据。

Any help ?有什么帮助吗?

Thanks in advance.提前致谢。

You are hitting a known issue, detailed here: https://github.com/confluentinc/kafka-connect-jdbc/issues/219您遇到了一个已知问题,详细信息如下: https : //github.com/confluentinc/kafka-connect-jdbc/issues/219

Steps to reproduce:重现步骤:

  1. Create database:创建数据库:

     $ echo 'DROP TABLE test_timestamp; CREATE TABLE test_timestamp(id integer primary key not null, payment_type text not null, Timestamp DATETIME DEFAULT CURRENT_TIMESTAMP, user_id int not null); INSERT INTO test_timestamp (ID, PAYMENT_TYPE, USER_ID) VALUES (3,\\'FOO\\',1); select * from test_timestamp;' | sqlite3 /tmp/test.db 3|FOO|2019-07-03 08:28:43|1
  2. Create connector创建连接器

    curl -X PUT "http://localhost:8083/connectors/jdbc-source/config" -H "Content-Type:application/json" -d '{ "connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector", "mode": "timestamp", "timestamp.column.name": "timestamp", "topic.prefix": "testdb-", "validate.non.null": "false", "tasks.max": "1", "name": "jdbc-source", "connection.url": "jdbc:sqlite:/tmp/test.db" }'
  3. Check status of connector检查连接器状态

    $ curl -s "http://localhost:8083/connectors"| \\ jq '.[]'| \\ xargs -I{connector_name} curl -s "http://localhost:8083/connectors/"{connector_name}"/status"| \\ jq -c -M '[.name,.connector.state,.tasks[].state]|join(":|:")'| \\ column -s : -t| sed 's/\\"//g'| sort jdbc-source | RUNNING | RUNNING
  4. Check Kafka Connect worker log, observe error parsing date, per issue 219检查 Kafka Connect 工作日志,观察错误解析日期, 每期 219

     [2019-07-03 10:40:58,260] ERROR Failed to run query for table TimestampIncrementingTableQuerier{table="test_timestamp", query='null', topicPrefix='testdb-', incrementingColumn='', timestampColumns=[timestamp]}: {} (io.confluent.connect.jdbc.source.JdbcSourceTask:332) java.sql.SQLException: Error parsing time stamp at org.sqlite.jdbc3.JDBC3ResultSet.getTimestamp(JDBC3ResultSet.java:576) at io.confluent.connect.jdbc.dialect.GenericDatabaseDialect.currentTimeOnDB(GenericDatabaseDialect.java:484) at io.confluent.connect.jdbc.source.TimestampIncrementingTableQuerier.endTimetampValue(TimestampIncrementingTableQuerier.java:203) at io.confluent.connect.jdbc.source.TimestampIncrementingCriteria.setQueryParametersTimestamp(TimestampIncrementingCriteria.java:164) at io.confluent.connect.jdbc.source.TimestampIncrementingCriteria.setQueryParameters(TimestampIncrementingCriteria.java:126) at io.confluent.connect.jdbc.source.TimestampIncrementingTableQuerier.executeQuery(TimestampIncrementingTableQuerier.java:176) at io.confluent.connect.jdbc.source.TableQuerier.maybeStartQuery(TableQuerier.java:92) at io.confluent.connect.jdbc.source.TimestampIncrementingTableQuerier.maybeStartQuery(TimestampIncrementingTableQuerier.java:60) at io.confluent.connect.jdbc.source.JdbcSourceTask.poll(JdbcSourceTask.java:310) at org.apache.kafka.connect.runtime.WorkerSourceTask.poll(WorkerSourceTask.java:245) at org.apache.kafka.connect.runtime.WorkerSourceTask.execute(WorkerSourceTask.java:221) at org.apache.kafka.connect.runtime.WorkerTask.doRun(WorkerTask.java:175) at org.apache.kafka.connect.runtime.WorkerTask.run(WorkerTask.java:219) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.text.ParseException: Unparseable date: "2019-07-03 08:40:58" does not match (\\p{Nd}++)\\Q-\\E(\\p{Nd}++)\\Q-\\E(\\p{Nd}++)\\Q \\E(\\p{Nd}++)\\Q:\\E(\\p{Nd}++)\\Q:\\E(\\p{Nd}++)\\Q.\\E(\\p{Nd}++) at org.sqlite.date.FastDateParser.parse(FastDateParser.java:299) at org.sqlite.date.FastDateFormat.parse(FastDateFormat.java:490) at org.sqlite.jdbc3.JDBC3ResultSet.getTimestamp(JDBC3ResultSet.java:573) ... 17 more

Stumbled across similar issue.偶然发现了类似的问题。 In my case, even the topic didn't create.就我而言,即使是主题也没有创建。 Found out that timezone for connect worker must be same as that of DB.发现 connect worker 的时区必须与 DB 的时区相同。 Setting db.timezone property in the connect worker's property file correctly based on thislist (under SHORT_IDS section) makes it work:根据此列表(在 SHORT_IDS 部分下)在连接工作器的属性文件中正确设置 db.timezone 属性使其工作:

db.timezone=Asia/Kolkata

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM