简体   繁体   English

如何使用 JDBC 接收器连接器将表名转换为大写

[英]How to convert table name to uppercase using JDBC sink connector

I am implementing CDC based replication between Postgres and Oracle databases.我正在 Postgres 和 Oracle 数据库之间实现基于 CDC 的复制。 For the source connector I am using Debezium's Postgres Connector and for the sink connector Confluent's JDBC Sink Connector.对于源连接器,我使用 Debezium 的 Postgres 连接器和接收器连接器 Confluent 的 JDBC 接收器连接器。

In the Postgres database, all tables are created in lowercase, but in the Oracle database tables are in uppercase.在 Postgres 数据库中,所有表都以小写字母创建,但在 Oracle 数据库中,表都是大写字母。 How can I dynamically set config in the JDBC sink connector, so that I don't need to set a hardcoded uppercase table name in transforms.route.replacement ?如何在 JDBC 接收器连接器中动态设置配置,这样我就不需要在transforms.route.replacement中设置硬编码的大写表名? Currently if I don't set the destination table name in uppercase manually in the config, double quotes are being added by the connector.目前,如果我没有在配置中手动将目标表名称设置为大写,则连接器会添加双引号。 Then, I receive the following error:然后,我收到以下错误:

Caused by: org.apache.kafka.connect.errors.ConnectException: Table "TEST"."dummy_table" is missing and auto-creation is disabled原因:org.apache.kafka.connect.errors.ConnectException:表“TEST”.“dummy_table”丢失并且自动创建被禁用

I have disabled auto-creation, because I don't need it.我禁用了自动创建,因为我不需要它。

Below is an example of my JDBC sink connector config.下面是我的 JDBC 接收器连接器配置的示例。 I have omitted some fields like connection url etc. If I leave the config like this, every time I need to add a new table, I would need to create a new JDBC sink connector.我省略了一些字段,如连接 url 等。如果我离开这样的配置,每次我需要添加一个新表时,我都需要创建一个新的 JDBC 接收器连接器。

{
    "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
    "tasks.max": "1",
    "topics": "test.public.dummy_table",
    "transforms": "route,unwrap",
    "transforms.route.type": "org.apache.kafka.connect.transforms.RegexRouter",
    "transforms.route.regex": "([^.]+)\\.([^.]+)\\.([^.]+)",
    "transforms.route.replacement": "TEST.DUMMY_TABLE", // I want to use TEST.$3 here, but apply uppercase. Is it possible?
    "transforms.unwrap.drop.tombstones": "false",
    "transforms.unwrap.type": "io.debezium.transforms.ExtractNewRecordState",
    "value.converter": "io.confluent.connect.avro.AvroConverter",
    "pk.mode": "record_key",
    "key.converter": "io.confluent.connect.avro.AvroConverter",
    "pk.fields": "id",
    "quote.sql.identifiers": "never"
}

Is it possible to achieve table name uppercase transformation using transforms.route.replacement or to tell the sink connector not to add double quotes?是否可以使用 transforms.route.replacement 实现表名大写转换或告诉接收器连接器不要添加双引号? If not, could you please suggest how to implement it?如果没有,您能否建议如何实施? Thank you in advance.先感谢您。

I know almost nothing about what you described.我对你所描述的几乎一无所知。

However : as far as Oracle is concerned, table names are stored in uppercase in data dictionary, but Oracle lets you access them using any letter case you want (upper, lower, mixed):但是:就 Oracle 而言,表名以大写形式存储在数据字典中,但 Oracle 允许您使用任何您想要的字母大小写(大写、小写、混合)访问它们:

SQL> select count(*) from emp union all       --> lower
  2  select count(*) from EMP union all       --> upper
  3  select count(*) from EmP;                --> mixed

  COUNT(*)
----------
        14
        14
        14

SQL>

That stands as long as you didn't use double quotes while creating the table;只要您在创建表格时不使用双引号,就可以了; in that case, you must use the same letter case and enclose table name into double quotes every time you access it:在这种情况下,每次访问时都必须使用相同的字母大小写并将表名括在双引号中:

SQL> create table "teST" (id number);

Table created.

SQL> select * from test;
select * from test
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from TEST;
select * from TEST
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from teST;
select * from teST
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from "teST";

no rows selected

SQL>

So: if you weren't that unfortunate to use double quotes, perhaps you don't have to bother (as my first example shows).所以:如果你不那么不幸地使用双引号,也许你不必费心(正如我的第一个例子所示)。 Just don't use double quotes while referencing the table and you're fine.只是在引用表格时不要使用双引号就可以了。

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

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