public TableChange(TableChangeType type, Table table) { this.type = type; this.table = table; this.id = table.id(); }
protected void appendCreateTableStatement(StringBuilder sb, Table table) { sb.append("CREATE TABLE ").append(table.id()).append(';').append(System.lineSeparator()); }
/** * Get the value mapping function for the given column. * * @param table the table to which the column belongs; may not be null * @param column the column; may not be null * @return the mapping function, or null if there is no mapping function */ public ValueConverter mappingConverterFor(Table table, Column column) { return mappingConverterFor(table.id(), column); }
private String getEnvelopeSchemaName(Table table) { return topicSelector.topicNameFor(table.id()) + ".Envelope"; }
private boolean hasMissingUntoastedColumns(Table table, List<ReplicationMessage.Column> columns) { List<String> msgColumnNames = columns.stream() .map(ReplicationMessage.Column::getName) .collect(Collectors.toList()); // Compute list of table columns not present in the replication message List<String> missingColumnNames = table.columns() .stream() .filter(c -> !msgColumnNames.contains(c.name())) .map(Column::name) .collect(Collectors.toList()); List<String> toastableColumns = schema().getToastableColumnsForTableId(table.id()); logger.debug("msg columns: '{}' --- missing columns: '{}' --- toastableColumns: '{}", String.join(",", msgColumnNames), String.join(",", missingColumnNames), String.join(",", toastableColumns)); // Return `true` if we have some columns not in the replication message that are not toastable or that we do // not recognize return !toastableColumns.containsAll(missingColumnNames); }
/** * Builds up the CDC event schema for the given table and stores it in this schema. */ protected void buildAndRegisterSchema(Table table) { if (tableFilter.isIncluded(table.id())) { TableSchema schema = schemaBuilder.create(schemaPrefix, getEnvelopeSchemaName(table), table, columnFilter, columnMappers); schemasByTableId.put(table.id(), schema); } }
/** * Refreshes the schema content with a table constructed externally * * @param table constructed externally - typically from decoder metadata */ protected void refresh(Table table) { // overwrite (add or update) or views of the tables tables().overwriteTable(table); // and refresh the schema refreshSchema(table.id()); }
LOGGER.info("\t Exporting data from table '{}'", table.id()); final String selectStatement = getSnapshotSelect(snapshotContext, table.id()); LOGGER.info("\t For table '{}' using select statement: '{}'", table.id(), selectStatement); throw new InterruptedException("Interrupted while snapshotting table " + table.id()); LOGGER.info("\t Exported {} records for table '{}' after {}", rows, table.id(), Strings.duration(stop - exportStart)); snapshotProgressListener.rowsScanned(table.id(), rows); logTimer = getTableScanLogTimer(); dispatcher.dispatchSnapshotEvent(table.id(), getChangeRecordEmitter(snapshotContext, row), snapshotReceiver); table.id(), Strings.duration(clock.currentTimeInMillis() - exportStart)); snapshotProgressListener.tableSnapshotCompleted(table.id(), rows); throw new ConnectException("Snapshotting of table " + table.id() + " failed", e);
protected TableImpl(Table table) { this(table.id(), table.columns(), table.primaryKeyColumnNames(), table.defaultCharsetName()); }
@Override protected SchemaChangeEvent getCreateTableEvent(SnapshotContext snapshotContext, Table table) throws SQLException { return new SchemaChangeEvent(snapshotContext.offset.getPartition(), snapshotContext.offset.getOffset(), snapshotContext.catalogName, table.id().schema(), null, table, SchemaChangeEventType.CREATE, true); }
protected TableSchema schemaFor(String fqn) { Table table = tableFor(fqn); return table != null ? schema.schemaFor(table.id()) : null; } }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj instanceof Table) { Table that = (Table) obj; return this.id().equals(that.id()) && this.columns().equals(that.columns()) && this.primaryKeyColumnNames().equals(that.primaryKeyColumnNames()) && Strings.equalsIgnoreCase(this.defaultCharsetName(), that.defaultCharsetName()); } return false; }
/** * Parse a potentially qualified table name along with an optional alias. * * @param start the start of the statement * @param tablesByAlias the map to which this method should add the table keyed by its alias (or name if there is no alias); * may not be null */ private void parseAliasedTableInFrom(Marker start, Map<String, Table> tablesByAlias) { Table fromTable = databaseTables.forTable(parseQualifiedTableName(start)); // Aliases in JOIN clauses don't have to be preceded by AS, but can simply be the alias followed by the 'ON' clause if (tokens.matches("AS", TokenStream.ANY_VALUE, "ON") || tokens.matches(TokenStream.ANY_VALUE, "ON")) { tokens.canConsume("AS"); String alias = tokens.consume(); if (fromTable != null) { tablesByAlias.put(alias, fromTable); return; } } if (fromTable != null) tablesByAlias.put(fromTable.id().table(), fromTable); }
@Test public void shouldHaveTableId() { assertThat(table.id()).isEqualTo(id); }
if (schemaPrefix == null) schemaPrefix = ""; final TableId tableId = table.id(); final String tableIdStr = tableSchemaName(tableId); final String schemaNamePrefix = schemaPrefix + tableIdStr;
/** * Rename an existing table. * * @param existingTableId the identifier of the existing table to be renamed; may not be null * @param newTableId the new identifier for the table; may not be null * @return the previous table definition, or null if there was no prior table definition */ public Table renameTable(TableId existingTableId, TableId newTableId) { return lock.write(() -> { Table existing = forTable(existingTableId); if (existing == null) return null; tablesByTableId.remove(existing.id()); TableImpl updated = new TableImpl(newTableId, existing.columns(), existing.primaryKeyColumnNames(), existing.defaultCharsetName()); try { return tablesByTableId.put(updated.id(), updated); } finally { changes.add(existingTableId); changes.add(updated.id()); } }); }
if (renamed != null) { oldTableId = tableId; tableId = renamed.id();
public TableChange(TableChangeType type, Table table) { this.type = type; this.table = table; this.id = table.id(); }
protected TableSchema schemaFor(String fqn) { Table table = tableFor(fqn); return table != null ? schema.schemaFor(table.id()) : null; } }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj instanceof Table) { Table that = (Table) obj; return this.id().equals(that.id()) && this.columns().equals(that.columns()) && this.primaryKeyColumnNames().equals(that.primaryKeyColumnNames()) && Strings.equalsIgnoreCase(this.defaultCharsetName(), that.defaultCharsetName()); } return false; }