Skip to content

Commit

Permalink
DBZ-8325 Remove converters from mysql parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
twthorn committed Oct 16, 2024
1 parent 9c1b598 commit 557214e
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public abstract class BinlogAntlrDdlParserTest<V extends BinlogValueConverters,
private TableSchemaBuilder tableSchemaBuilder;
private Properties properties;

protected abstract P getParser(SimpleDdlParserListener listener, V converters);
protected abstract P getParser(SimpleDdlParserListener listener);

protected abstract P getParser(SimpleDdlParserListener listener, V converters, boolean includeViews);
protected abstract P getParser(SimpleDdlParserListener listener, boolean includeViews);

protected abstract P getParser(SimpleDdlParserListener listener, V converters, TableFilter tableFilter);
protected abstract P getParser(SimpleDdlParserListener listener, TableFilter tableFilter);

protected abstract P getParser(SimpleDdlParserListener listener, V converters, boolean includeViews, boolean includeComments);
protected abstract P getParser(SimpleDdlParserListener listener, boolean includeViews, boolean includeComments);

protected abstract V getValueConverters();

Expand All @@ -86,7 +86,7 @@ public abstract class BinlogAntlrDdlParserTest<V extends BinlogValueConverters,
public void beforeEach() {
listener = new SimpleDdlParserListener();
converters = getValueConverters();
parser = getParser(listener, converters);
parser = getParser(listener);
tables = new Tables();
tableSchemaBuilder = new TableSchemaBuilder(
converters,
Expand Down Expand Up @@ -370,7 +370,7 @@ public void shouldProcessDefaultCharsetForTable() {
@Test
@FixFor("DBZ-4000")
public void shouldProcessCommentForTable() {
parser = getParser(listener, converters, false, true);
parser = getParser(listener, false, true);
parser.parse("CREATE TABLE table1(\n"
+ "id INT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY COMMENT 'pk',\n"
+ "bin_volume DECIMAL(20, 4) COMMENT 'decimal column'\n"
Expand Down Expand Up @@ -1364,7 +1364,7 @@ public void shouldParseCreateViewStatementStartSelect() {
+ "); " + System.lineSeparator();
String ddl2 = "CREATE VIEW fooView AS (SELECT * FROM foo)" + System.lineSeparator();

parser = getParser(listener, converters, true);
parser = getParser(listener, true);
parser.parse(ddl, tables);
parser.parse(ddl2, tables);
assertThat(tables.size()).isEqualTo(2);
Expand All @@ -1384,7 +1384,7 @@ public void shouldParseDropView() {
+ "); " + System.lineSeparator();
String ddl2 = "CREATE VIEW fooView AS (SELECT * FROM foo)" + System.lineSeparator();
String ddl3 = "DROP VIEW fooView";
parser = getParser(listener, converters, true);
parser = getParser(listener, true);
parser.parse(ddl, tables);
parser.parse(ddl2, tables);
parser.parse(ddl3, tables);
Expand All @@ -1400,7 +1400,7 @@ public void shouldParseAlterTableRename() {
+ "CREATE TABLE db.t1 (ID INTEGER PRIMARY KEY);"
+ "ALTER TABLE `t1` RENAME TO `t2`;"
+ "ALTER TABLE `db`.`t2` RENAME TO `db`.`t3`;";
parser = getParser(listener, converters, true);
parser = getParser(listener, true);
parser.parse(ddl, tables);
assertThat(tables.size()).isEqualTo(1);
final Table table = tables.forTable(new TableId(null, "db", "t3"));
Expand All @@ -1416,7 +1416,7 @@ public void shouldParseCreateViewStatementColumnAlias() {
+ "); " + System.lineSeparator();
String ddl2 = "CREATE VIEW fooView(w1) AS (SELECT c2 as w1 FROM foo)" + System.lineSeparator();

parser = getParser(listener, converters, true);
parser = getParser(listener, true);
parser.parse(ddl, tables);
parser.parse(ddl2, tables);
assertThat(tables.size()).isEqualTo(2);
Expand All @@ -1435,7 +1435,7 @@ public void shouldParseCreateViewStatementColumnAliasInnerSelect() {
+ "); " + System.lineSeparator();
String ddl2 = "CREATE VIEW fooView(w1) AS (SELECT foo2.c2 as w1 FROM (SELECT c1 as c2 FROM foo) AS foo2)" + System.lineSeparator();

parser = getParser(listener, converters, true);
parser = getParser(listener, true);
parser.parse(ddl, tables);
parser.parse(ddl2, tables);
assertThat(tables.size()).isEqualTo(2);
Expand All @@ -1454,7 +1454,7 @@ public void shouldParseAlterViewStatementColumnAliasInnerSelect() {
+ "); " + System.lineSeparator();
String ddl2 = "CREATE VIEW fooView(w1) AS (SELECT foo2.c2 as w1 FROM (SELECT c1 as c2 FROM foo) AS foo2)" + System.lineSeparator();
String ddl3 = "ALTER VIEW fooView AS (SELECT c2 FROM foo)";
parser = getParser(listener, converters, true);
parser = getParser(listener, true);
parser.parse(ddl, tables);
parser.parse(ddl2, tables);
parser.parse(ddl3, tables);
Expand All @@ -1469,7 +1469,7 @@ public void shouldParseAlterViewStatementColumnAliasInnerSelect() {

@Test
public void shouldUseFiltersForAlterTable() {
parser = getParser(listener, converters, TableFilter.fromPredicate(x -> !x.table().contains("ignored")));
parser = getParser(listener, TableFilter.fromPredicate(x -> !x.table().contains("ignored")));

final String ddl = "CREATE TABLE ok (id int primary key, val smallint);" + System.lineSeparator()
+ "ALTER TABLE ignored ADD COLUMN(x tinyint)" + System.lineSeparator()
Expand All @@ -1495,7 +1495,7 @@ public void shouldUseFiltersForAlterTable() {
@Test
@FixFor("DBZ-903")
public void shouldParseFunctionNamedDatabase() {
parser = getParser(listener, converters, TableFilter.fromPredicate(x -> !x.table().contains("ignored")));
parser = getParser(listener, TableFilter.fromPredicate(x -> !x.table().contains("ignored")));

final String ddl = "SELECT `table_name` FROM `information_schema`.`TABLES` WHERE `table_schema` = DATABASE()";
parser.parse(ddl, tables);
Expand All @@ -1504,7 +1504,7 @@ public void shouldParseFunctionNamedDatabase() {
@Test
@FixFor("DBZ-910")
public void shouldParseConstraintCheck() {
parser = getParser(listener, converters, true);
parser = getParser(listener, true);

final String ddl = "CREATE TABLE t1 (c1 INTEGER NOT NULL,c2 VARCHAR(22),CHECK (c2 IN ('A', 'B', 'C')));"
+ "CREATE TABLE t2 (c1 INTEGER NOT NULL,c2 VARCHAR(22),CONSTRAINT c1 CHECK (c2 IN ('A', 'B', 'C')));"
Expand Down Expand Up @@ -1543,7 +1543,7 @@ public void shouldParseCommentWithEngineName() {
@Test
@FixFor("DBZ-780")
public void shouldRenameColumnWithoutDefinition() {
parser = getParser(listener, converters, TableFilter.fromPredicate(x -> !x.table().contains("ignored")));
parser = getParser(listener, TableFilter.fromPredicate(x -> !x.table().contains("ignored")));

final String ddl = "CREATE TABLE foo (id int primary key, old INT);" + System.lineSeparator()
+ "ALTER TABLE foo RENAME COLUMN old to new ";
Expand Down Expand Up @@ -2675,7 +2675,7 @@ public void shouldParseAlterTableWithIndex() {
final String ddl = "USE db;"
+ "CREATE TABLE db.t1 (ID INTEGER PRIMARY KEY, val INTEGER, INDEX myidx(val));"
+ "ALTER TABLE db.t1 RENAME INDEX myidx to myidx2;";
parser = getParser(listener, converters, true);
parser = getParser(listener, true);
parser.parse(ddl, tables);
assertThat(tables.size()).isEqualTo(1);
final Table table = tables.forTable(new TableId(null, "db", "t1"));
Expand All @@ -2690,7 +2690,7 @@ public void shouldParseIndex() {
+ "CREATE TABLE db.t1 (ID INTEGER PRIMARY KEY, val INTEGER, INDEX myidx(val));";
final String ddl2 = "USE db;"
+ "CREATE OR REPLACE INDEX myidx on db.t1(val);";
parser = getParser(listener, converters, true);
parser = getParser(listener, true);
parser.parse(ddl1, tables);
assertThat(tables.size()).isEqualTo(1);
final Table table = tables.forTable(new TableId(null, "db", "t1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.debezium.connector.binlog.charset.BinlogCharsetRegistry;
import io.debezium.connector.binlog.jdbc.BinlogSystemVariables;
import io.debezium.connector.mariadb.antlr.listener.MariaDbAntlrDdlParserListener;
import io.debezium.connector.mariadb.jdbc.MariaDbValueConverters;
import io.debezium.ddl.parser.mariadb.generated.MariaDBLexer;
import io.debezium.ddl.parser.mariadb.generated.MariaDBParser;
import io.debezium.ddl.parser.mariadb.generated.MariaDBParser.CharsetNameContext;
Expand All @@ -47,30 +46,23 @@
public class MariaDbAntlrDdlParser extends AntlrDdlParser<MariaDBLexer, MariaDBParser> {

private final ConcurrentHashMap<String, String> charsetNameForDatabase = new ConcurrentHashMap<>();
private final MariaDbValueConverters converters;
private final Tables.TableFilter tableFilter;
private final BinlogCharsetRegistry charsetRegistry;

@VisibleForTesting
public MariaDbAntlrDdlParser() {
this(null, Tables.TableFilter.includeAll());
this(Tables.TableFilter.includeAll());
}

@VisibleForTesting
public MariaDbAntlrDdlParser(MariaDbValueConverters valueConverters) {
this(valueConverters, Tables.TableFilter.includeAll());
}

@VisibleForTesting
public MariaDbAntlrDdlParser(MariaDbValueConverters valueConverters, Tables.TableFilter tableFilter) {
this(true, false, true, valueConverters, tableFilter, null);
public MariaDbAntlrDdlParser(Tables.TableFilter tableFilter) {
this(true, false, true, tableFilter, null);
}

public MariaDbAntlrDdlParser(boolean throwWerrorsFromTreeWalk, boolean includeViews, boolean includeComments,
MariaDbValueConverters valueConverters, Tables.TableFilter tableFilter, BinlogCharsetRegistry charsetRegistry) {
Tables.TableFilter tableFilter, BinlogCharsetRegistry charsetRegistry) {
super(throwWerrorsFromTreeWalk, includeViews, includeComments);
systemVariables = new BinlogSystemVariables();
this.converters = valueConverters;
this.tableFilter = tableFilter;
this.charsetRegistry = charsetRegistry;
}
Expand Down Expand Up @@ -453,10 +445,6 @@ public static String escapeOption(String option) {
return option.replaceAll(",", "\\\\,").replaceAll("\\\\'", "'").replace("''", "'");
}

public MariaDbValueConverters getConverters() {
return converters;
}

public Tables.TableFilter getTableFilter() {
return tableFilter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@
*/
public class MariaDbAntlrDdlParserTest extends BinlogAntlrDdlParserTest<MariaDbValueConverters, MariaDbDefaultValueConverter, MariaDbAntlrDdlParser> {
@Override
protected MariaDbAntlrDdlParser getParser(SimpleDdlParserListener listener, MariaDbValueConverters converters) {
return new MariaDbDdlParserWithSimpleTestListener(listener, converters);
protected MariaDbAntlrDdlParser getParser(SimpleDdlParserListener listener) {
return new MariaDbDdlParserWithSimpleTestListener(listener);
}

@Override
protected MariaDbAntlrDdlParser getParser(SimpleDdlParserListener listener, MariaDbValueConverters converters, boolean includeViews) {
return new MariaDbDdlParserWithSimpleTestListener(listener, includeViews, converters);
protected MariaDbAntlrDdlParser getParser(SimpleDdlParserListener listener, boolean includeViews) {
return new MariaDbDdlParserWithSimpleTestListener(listener, includeViews);
}

@Override
protected MariaDbAntlrDdlParser getParser(SimpleDdlParserListener listener, MariaDbValueConverters converters, Tables.TableFilter tableFilter) {
return new MariaDbDdlParserWithSimpleTestListener(listener, tableFilter, converters);
protected MariaDbAntlrDdlParser getParser(SimpleDdlParserListener listener, Tables.TableFilter tableFilter) {
return new MariaDbDdlParserWithSimpleTestListener(listener, tableFilter);
}

@Override
protected MariaDbAntlrDdlParser getParser(SimpleDdlParserListener listener, MariaDbValueConverters converters, boolean includeViews, boolean includeComments) {
return new MariaDbDdlParserWithSimpleTestListener(listener, includeViews, includeComments, converters);
protected MariaDbAntlrDdlParser getParser(SimpleDdlParserListener listener, boolean includeViews, boolean includeComments) {
return new MariaDbDdlParserWithSimpleTestListener(listener, includeViews, includeComments);
}

@Override
Expand All @@ -66,25 +66,24 @@ protected List<String> extractEnumAndSetOptions(List<String> enumValues) {
}

public static class MariaDbDdlParserWithSimpleTestListener extends MariaDbAntlrDdlParser {
public MariaDbDdlParserWithSimpleTestListener(DdlChanges listener, MariaDbValueConverters converters) {
this(listener, false, converters);
public MariaDbDdlParserWithSimpleTestListener(DdlChanges listener) {
this(listener, false);
}

public MariaDbDdlParserWithSimpleTestListener(DdlChanges listener, Tables.TableFilter tableFilter, MariaDbValueConverters converters) {
this(listener, false, false, tableFilter, converters);
public MariaDbDdlParserWithSimpleTestListener(DdlChanges listener, Tables.TableFilter tableFilter) {
this(listener, false, false, tableFilter);
}

public MariaDbDdlParserWithSimpleTestListener(DdlChanges listener, boolean includeViews, MariaDbValueConverters converters) {
this(listener, includeViews, false, Tables.TableFilter.includeAll(), converters);
public MariaDbDdlParserWithSimpleTestListener(DdlChanges listener, boolean includeViews) {
this(listener, includeViews, false, Tables.TableFilter.includeAll());
}

public MariaDbDdlParserWithSimpleTestListener(DdlChanges listener, boolean includeViews, boolean includeComments, MariaDbValueConverters converters) {
this(listener, includeViews, includeComments, Tables.TableFilter.includeAll(), converters);
public MariaDbDdlParserWithSimpleTestListener(DdlChanges listener, boolean includeViews, boolean includeComments) {
this(listener, includeViews, includeComments, Tables.TableFilter.includeAll());
}

public MariaDbDdlParserWithSimpleTestListener(DdlChanges listener, boolean includeViews, boolean includeComments, Tables.TableFilter tableFilter,
MariaDbValueConverters converters) {
super(false, includeViews, includeComments, converters, tableFilter, new MariaDbCharsetRegistry());
public MariaDbDdlParserWithSimpleTestListener(DdlChanges listener, boolean includeViews, boolean includeComments, Tables.TableFilter tableFilter) {
super(false, includeViews, includeComments, tableFilter, new MariaDbCharsetRegistry());
this.ddlChanges = listener;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ protected DdlParser createDdlParser(BinlogConnectorConfig connectorConfig, MySql
true,
false,
connectorConfig.isSchemaCommentsHistoryEnabled(),
valueConverter,
getTableFilter(),
connectorConfig.getServiceRegistry().getService(BinlogCharsetRegistry.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.debezium.connector.binlog.charset.BinlogCharsetRegistry;
import io.debezium.connector.binlog.jdbc.BinlogSystemVariables;
import io.debezium.connector.mysql.antlr.listener.MySqlAntlrDdlParserListener;
import io.debezium.connector.mysql.jdbc.MySqlValueConverters;
import io.debezium.ddl.parser.mysql.generated.MySqlLexer;
import io.debezium.ddl.parser.mysql.generated.MySqlParser;
import io.debezium.ddl.parser.mysql.generated.MySqlParser.CharsetNameContext;
Expand All @@ -49,30 +48,23 @@
public class MySqlAntlrDdlParser extends AntlrDdlParser<MySqlLexer, MySqlParser> {

private final ConcurrentMap<String, String> charsetNameForDatabase = new ConcurrentHashMap<>();
private final MySqlValueConverters converters;
private final TableFilter tableFilter;
private final BinlogCharsetRegistry charsetRegistry;

@VisibleForTesting
public MySqlAntlrDdlParser() {
this(null, TableFilter.includeAll());
this(TableFilter.includeAll());
}

@VisibleForTesting
public MySqlAntlrDdlParser(MySqlValueConverters converters) {
this(converters, TableFilter.includeAll());
}

@VisibleForTesting
public MySqlAntlrDdlParser(MySqlValueConverters converters, TableFilter tableFilter) {
this(true, false, false, converters, tableFilter, null);
public MySqlAntlrDdlParser(TableFilter tableFilter) {
this(true, false, false, tableFilter, null);
}

public MySqlAntlrDdlParser(boolean throwErrorsFromTreeWalk, boolean includeViews, boolean includeComments,
MySqlValueConverters converters, TableFilter tableFilter, BinlogCharsetRegistry charsetRegistry) {
TableFilter tableFilter, BinlogCharsetRegistry charsetRegistry) {
super(throwErrorsFromTreeWalk, includeViews, includeComments);
systemVariables = new BinlogSystemVariables();
this.converters = converters;
this.tableFilter = tableFilter;
this.charsetRegistry = charsetRegistry;
}
Expand Down Expand Up @@ -441,10 +433,6 @@ public static String escapeOption(String option) {
return option.replaceAll(",", "\\\\,").replaceAll("\\\\'", "'").replace("''", "'");
}

public MySqlValueConverters getConverters() {
return converters;
}

public TableFilter getTableFilter() {
return tableFilter;
}
Expand Down
Loading

0 comments on commit 557214e

Please sign in to comment.