The dbrename JavaScript filter
renames database (schemas) using two parameters from the properties file,
the dbsource and
dbtarget. Each event is then
processed, and the statement or row based schema information is updated to
dbtarget when the
dbsource schema is identified.
| Pre-configured filter name |
dbrename
| ||
| JavaScript Filter File |
tungsten-replicator/support/filters-javascript/dbrename.js
| ||
| Property prefix |
replicator.filter.dbrename
| ||
| Stage compatibility |
binlog-to-q
| ||
| tpm Option compatibility |
--svc-extractor-filters
| ||
| Data compatibility | Any event | ||
| Parameters | |||
| Parameter | Type | Default | Description |
dbsource
|
string
| (none) | Source table name (database/table to be renamed) |
dbtarget
|
string
| (none) | New database/table name |
To configure the filter you would add the following to your properties:
replicator.filter.dbrename=com.continuent.tungsten.replicator.filter.JavaScriptFilter
replicator.filter.dbrename.script=${replicator.home.dir}/samples/extensions/javascript/dbrename.js
replicator.filter.dbrename.dbsource=SOURCE
replicator.filter.dbrename.dbtarget=TESTThe operation of the filter is straightforward, because the schema name is exposed and settable within the statement and row change objects:
function filter(event)
{
sourceName = filterProperties.getString("dbsource");
targetName = filterProperties.getString("dbtarget");
data = event.getData();
for(i=0;i<data.size();i++)
{
d = data.get(i);
if(d instanceof
com.continuent.tungsten.replicator.dbms.StatementData)
{
if(d.getDefaultSchema() != null &&
d.getDefaultSchema().compareTo(sourceName)==0)
{
d.setDefaultSchema(targetName);
}
}
else if(d instanceof
com.continuent.tungsten.replicator.dbms.RowChangeData)
{
rowChanges = data.get(i).getRowChanges();
for(j=0;j<rowChanges.size();j++)
{
oneRowChange = rowChanges.get(j);
if(oneRowChange.getSchemaName().compareTo(sourceName)==0)
{
oneRowChange.setSchemaName(targetName);
}
}
}
}
}