Skip to main content
Common Reference

truncatetext.js Filter

The truncatetext filter truncates a MySQL BLOB field.

Pre-configured filter nametruncatetext
JavaScript Filter Filetungsten-replicator/support/filters-javascript/truncatetext.js
Property prefixreplicator.filter.truncatetext
Stage compatibilitybinlog-to-q, q-to-dbms
tpm Option compatibilitysvc-extractor-filters, svc-extractor-filters
Data compatibilityRow events

Parameters

ParameterTypeDefaultDescription
lengthnumeric(none)Maximum size of truncated field (bytes)

The length is determined by the length parameter in the properties:

replicator.filter.truncatetext=com.continuent.tungsten.replicator.filter.JavaScriptFilter
replicator.filter.truncatetext.script=${replicator.home.dir}/samples/extensions/javascript/truncatetext.js
replicator.filter.truncatetext.length=4000

Statement-based events are ignored, but row-based events are processed for each volume value, checking the column type, isBlob() method and then truncating the contents when they are identified as larger than the configured length. To confirm the type, it is compared against the Java class com.continuent.tungsten.replicator.extractor.mysql.SerialBlob, the class for a serialized BLOB value. These need to be processed differently as they are not exposed as a single variable.

if (value.getValue() instanceof com.continuent.tungsten.replicator.extractor.mysql.SerialBlob)
{
blob = value.getValue();
if (blob != null)
{
valueBytes = blob.getBytes(1, blob.length());
if (blob.length() > truncateTo)
{
blob.truncate(truncateTo);
}
}
}