/** * Get the name of the table. * * @return the table name; never null */ public String table() { return tableId.table(); }
@Override public String getTopicName(TableId tableId, String prefix, String delimiter) { return String.join(delimiter, prefix, tableId.schema(), tableId.table()); } },
@Override protected String getSnapshotSelect(SnapshotContext snapshotContext, TableId tableId) { return String.format("SELECT * FROM [%s].[%s]", tableId.schema(), tableId.table()); }
/** * Creates an exclusive lock for a given table. * * @param tableId to be locked * @throws SQLException */ public void lockTable(TableId tableId) throws SQLException { final String lockTableStmt = LOCK_TABLE.replace(STATEMENTS_PLACEHOLDER, tableId.table()); execute(lockTableStmt); }
private String cdcNameForTable(TableId tableId) { return tableId.schema() + '_' + tableId.table(); }
@Override public boolean isIncluded(TableId t) { return !(t.schema().toLowerCase().equals("cdc") || t.schema().toLowerCase().equals("sys") || t.table().toLowerCase().equals("systranschemas")); } }
protected List<String> readPrimaryKeyNames(DatabaseMetaData metadata, TableId id) throws SQLException { final List<String> pkColumnNames = new ArrayList<>(); try (ResultSet rs = metadata.getPrimaryKeys(id.catalog(), id.schema(), id.table())) { while (rs.next()) { String columnName = rs.getString(4); int columnIndex = rs.getInt(5); Collect.set(pkColumnNames, columnIndex - 1, columnName, null); } } return pkColumnNames; }
public static TopicSelector<TableId> defaultSelector(SqlServerConnectorConfig connectorConfig) { return TopicSelector.defaultSelector(connectorConfig, (tableId, prefix, delimiter) -> String.join(delimiter, prefix, tableId.schema(), tableId.table())); } }
/** * Get the default topic selector logic, which uses a '.' delimiter character when needed. * * @param prefix the name of the prefix to be used for all topics; may not be null and must not terminate in the * {@code delimiter} * @param heartbeatPrefix the name of the prefix to be used for all heartbeat topics; may not be null and must not terminate in the * {@code delimiter} * @return the topic selector; never null */ static TopicSelector<TableId> defaultSelector(String prefix, String heartbeatPrefix) { return TopicSelector.defaultSelector(prefix, heartbeatPrefix, ".", (t, pref, delimiter) -> String.join(delimiter, pref, t.catalog(), t.table())); } }
protected String quote(TableId id) { return quote(id.catalog()) + "." + quote(id.table()); }
protected static TableId parse(String table) { TableId tableId = TableId.parse(table, false); if (tableId == null) { return null; } return tableId.schema() == null ? new TableId(tableId.catalog(), PUBLIC_SCHEMA_NAME, tableId.table()) : tableId; }
protected static TableId tableIdFromInsertStmt(String statement) { Matcher matcher = INSERT_TABLE_MATCHING_PATTERN.matcher(statement); assertTrue("Extraction of table name from insert statement failed: " + statement, matcher.matches()); TableId id = TableId.parse(matcher.group(1), false); if (id.schema() == null) { id = new TableId(id.catalog(), "public", id.table()); } return id; }
private String validFullName(String proposedName, String suffix) { TableId id = TableId.parse(proposedName, false); return SchemaNameAdjuster.validFullname(TestHelper.TEST_SERVER + "." + id.schema() + "." + id.table() + suffix); }
@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); }
@Override public void enterDropTable(MySqlParser.DropTableContext ctx) { Interval interval = new Interval(ctx.start.getStartIndex(), ctx.tables().start.getStartIndex() - 1); String prefix = ctx.start.getInputStream().getText(interval); ctx.tables().tableName().forEach(tableNameContext -> { TableId tableId = parser.parseQualifiedTableId(tableNameContext.fullId()); parser.databaseTables().removeTable(tableId); parser.signalDropTable(tableId, prefix + tableId.table() + (ctx.dropType != null ? " " + ctx.dropType.getText() : "")); }); super.enterDropTable(ctx); } }
private void assertInsert(String statement, Integer pk, List<SchemaAndValueField> expectedSchemaAndValuesByColumn) { TableId table = tableIdFromInsertStmt(statement); String expectedTopicName = table.schema() + "." + table.table(); expectedTopicName = expectedTopicName.replaceAll("[ \"]", "_"); try { executeAndWait(statement); SourceRecord record = assertRecordInserted(expectedTopicName, pk != null ? PK_FIELD : null, pk); assertRecordOffsetAndSnapshotSource(record, false, false); assertSourceInfo(record, "postgres", table.schema(), table.table()); assertRecordSchemaAndValues(expectedSchemaAndValuesByColumn, record, Envelope.FieldName.AFTER); } catch (Exception e) { throw new RuntimeException(e); } }
public EventAssert tableNameIs( String expected) { assertThat(tableEvent().tableId().table()).isEqualTo(expected); return this; }
public SqlServerConnectorConfig(Configuration config) { super(config, config.getString(LOGICAL_NAME), new SystemTablesPredicate(), x -> x.schema() + "." + x.table()); this.databaseName = config.getString(DATABASE_NAME); this.snapshotMode = SnapshotMode.parse(config.getString(SNAPSHOT_MODE), SNAPSHOT_MODE.defaultValueAsString()); this.snapshotIsolationMode = SnapshotIsolationMode.parse(config.getString(SNAPSHOT_ISOLATION_MODE), SNAPSHOT_ISOLATION_MODE.defaultValueAsString()); this.columnFilter = Predicates.excludes(config.getString(RelationalDatabaseConnectorConfig.COLUMN_BLACKLIST), columnId -> String.format("%s.%s.%s", columnId.schema(), columnId.table(), columnId.columnName())); }
public EventAssert renamedFrom( String oldName ) { TableId previousTableId = alterTableEvent().previousTableId(); if ( oldName == null ) { assertThat(previousTableId).isNull(); } else { assertThat(previousTableId.table()).isEqualTo(oldName); } return this; } public EventAssert dropTableNamed( String tableName) {