Skip to main content
Common Reference

zerodate2null.js Filter

The zerodate2null filter looks complicated, but is very simple. It processes row data looking for date columns. If the corresponding value is zero within the column, the value is updated to NULL. This is required for MySQL to Oracle replication scenarios.

Pre-configured filter namezerodate2null
JavaScript Filter Filetungsten-replicator/support/filters-javascript/zerodate2null.js
Property prefixreplicator.filter.zerodate2null
Stage compatibilityq-to-dbms
tpm Option compatibilitysvc-applier-filters
Data compatibilityRow events

The filter works by examining the column specification using the getColumnSpec() method. Each column is then checked to see if the column type is a DATE, DATETIME or TIMESTAMP by looking the type ID using some stored values for the date type.

Because the column index and corresponding value index match, when the value is zero, the column value is explicitly set to NULL using the setValueNull() method.

for(j = 0; j < rowChanges.size(); j++)
{
oneRowChange = rowChanges.get(j);
columns = oneRowChange.getColumnSpec();
columnValues = oneRowChange.getColumnValues();
for (c = 0; c < columns.size(); c++)
{
columnSpec = columns.get(c);
type = columnSpec.getType();
if (type == TypesDATE || type == TypesTIMESTAMP)
{
for (row = 0; row < columnValues.size(); row++)
{
values = columnValues.get(row);
value = values.get(c);

if (value.getValue() == 0)
{
value.setValueNull()
}
}
}
}
}