@Test @FixFor("DBZ-903") public void shouldParseFunctionNamedDatabase() { parser = new MysqlDdlParserWithSimpleTestListener(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); }
@Test public void shouldUseFiltersForAlterTable() { parser = new MysqlDdlParserWithSimpleTestListener(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() + "ALTER TABLE ok ADD COLUMN(y tinyint)"; parser.parse(ddl, tables); assertThat(((MysqlDdlParserWithSimpleTestListener)parser).getParsingExceptionsFromWalker()).isEmpty(); assertThat(tables.size()).isEqualTo(1); final Table t1 = tables.forTable(null, null, "ok"); assertThat(t1.columns()).hasSize(3); final Column c1 = t1.columns().get(0); final Column c2 = t1.columns().get(1); final Column c3 = t1.columns().get(2); assertThat(c1.name()).isEqualTo("id"); assertThat(c1.typeName()).isEqualTo("INT"); assertThat(c2.name()).isEqualTo("val"); assertThat(c2.typeName()).isEqualTo("SMALLINT"); assertThat(c3.name()).isEqualTo("y"); assertThat(c3.typeName()).isEqualTo("TINYINT"); }
@Test @FixFor("DBZ-780") public void shouldRenameColumnWithoutDefinition() { parser = new MysqlDdlParserWithSimpleTestListener(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 "; parser.parse(ddl, tables); assertThat(((MysqlDdlParserWithSimpleTestListener)parser).getParsingExceptionsFromWalker()).isEmpty(); assertThat(tables.size()).isEqualTo(1); final Table t1 = tables.forTable(null, null, "foo"); assertThat(t1.columns()).hasSize(2); final Column c1 = t1.columns().get(0); final Column c2 = t1.columns().get(1); assertThat(c1.name()).isEqualTo("id"); assertThat(c1.typeName()).isEqualTo("INT"); assertThat(c2.name()).isEqualTo("new"); assertThat(c2.typeName()).isEqualTo("INT"); }
/** * @param config the configuration; may not be null */ public Filters(PostgresConnectorConfig config) { // we always want to exclude PG system schemas as they are never part of logical decoding events String schemaBlacklist = config.schemaBlacklist(); if (schemaBlacklist != null) { schemaBlacklist = schemaBlacklist + "," + SYSTEM_SCHEMA_BLACKLIST; } else { schemaBlacklist = SYSTEM_SCHEMA_BLACKLIST; } String tableBlacklist = config.tableBlacklist(); if (tableBlacklist != null) { tableBlacklist = tableBlacklist + "," + TEMP_TABLE_BLACKLIST; } else { tableBlacklist = TEMP_TABLE_BLACKLIST; } // Define the filter using the whitelists and blacklists for table names ... this.tableFilter = TableFilter.fromPredicate(Selectors.tableSelector() .includeTables(config.tableWhitelist()) .excludeTables(tableBlacklist) .includeSchemas(config.schemaWhitelist()) .excludeSchemas(schemaBlacklist) .build()); // Define the filter that excludes blacklisted columns, truncated columns, and masked columns ... this.columnFilter = Selectors.excludeColumns(config.columnBlacklist()); }
@Test public void shouldUseFiltersForAlterTable() { parser = new MysqlDdlParserWithSimpleTestListener(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() + "ALTER TABLE ok ADD COLUMN(y tinyint)"; parser.parse(ddl, tables); assertThat(((MysqlDdlParserWithSimpleTestListener)parser).getParsingExceptionsFromWalker()).isEmpty(); assertThat(tables.size()).isEqualTo(1); final Table t1 = tables.forTable(null, null, "ok"); assertThat(t1.columns()).hasSize(3); final Column c1 = t1.columns().get(0); final Column c2 = t1.columns().get(1); final Column c3 = t1.columns().get(2); assertThat(c1.name()).isEqualTo("id"); assertThat(c1.typeName()).isEqualTo("INT"); assertThat(c2.name()).isEqualTo("val"); assertThat(c2.typeName()).isEqualTo("SMALLINT"); assertThat(c3.name()).isEqualTo("y"); assertThat(c3.typeName()).isEqualTo("TINYINT"); }
@Test @FixFor("DBZ-780") public void shouldRenameColumnWithoutDefinition() { parser = new MysqlDdlParserWithSimpleTestListener(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 "; parser.parse(ddl, tables); assertThat(((MysqlDdlParserWithSimpleTestListener)parser).getParsingExceptionsFromWalker()).isEmpty(); assertThat(tables.size()).isEqualTo(1); final Table t1 = tables.forTable(null, null, "foo"); assertThat(t1.columns()).hasSize(2); final Column c1 = t1.columns().get(0); final Column c2 = t1.columns().get(1); assertThat(c1.name()).isEqualTo("id"); assertThat(c1.typeName()).isEqualTo("INT"); assertThat(c2.name()).isEqualTo("new"); assertThat(c2.typeName()).isEqualTo("INT"); }
@Test @FixFor("DBZ-903") public void shouldParseFunctionNamedDatabase() { parser = new MysqlDdlParserWithSimpleTestListener(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); }
configuration, topicSelector, TableFilter.fromPredicate(tableFilters.tableFilter()), tableFilters.columnFilter(), new TableSchemaBuilder(
/** * @param config the configuration; may not be null */ public Filters(PostgresConnectorConfig config) { // we always want to exclude PG system schemas as they are never part of logical decoding events String schemaBlacklist = config.schemaBlacklist(); if (schemaBlacklist != null) { schemaBlacklist = schemaBlacklist + "," + SYSTEM_SCHEMA_BLACKLIST; } else { schemaBlacklist = SYSTEM_SCHEMA_BLACKLIST; } String tableBlacklist = config.tableBlacklist(); if (tableBlacklist != null) { tableBlacklist = tableBlacklist + "," + TEMP_TABLE_BLACKLIST; } else { tableBlacklist = TEMP_TABLE_BLACKLIST; } // Define the filter using the whitelists and blacklists for table names ... this.tableFilter = TableFilter.fromPredicate(Selectors.tableSelector() .includeTables(config.tableWhitelist()) .excludeTables(tableBlacklist) .includeSchemas(config.schemaWhitelist()) .excludeSchemas(schemaBlacklist) .build()); // Define the filter that excludes blacklisted columns, truncated columns, and masked columns ... this.columnFilter = Selectors.excludeColumns(config.columnBlacklist()); }