Skip to main content

Extraction, splitting, filtering, and transformation

warning

After parsing, use extraction, splitting, filtering, and transformation rules to adjust field contents, scope, and types to target requirements. After adding each rule, preview samples that should be retained and excluded again. Missing segments, extra segments, and type mismatches may not raise errors, and filtered records are not automatically recovered.

Where to operate: taosExplorer → Data Ingestion → a connector supporting message parsing → extraction, filtering, and mapping settings in Payload parsing.

Extraction takes content from existing fields; splitting divides one field into multiple columns; filtering determines which records continue to writing; transformation adjusts field types or values. Preview each new rule first. Do not change the source connection, consumer position, and target model together.

1. Prepare a baseline sample​

{"id":2,"message":"zoneA-line1","ts":1795132800000,"temperature":"23.5"}

Select JSON parsing first and confirm that the preview produces id, message, ts, and temperature. Temperature is deliberately a string to verify later conversion. Time is a millisecond Unix timestamp corresponding to 2026-11-20T00:00:00Z.

2. Extraction and splitting​

In Extract or Split from Column, select message, choose extractor split, set separator to - and number to 2. Preview this step. Expect message_0=zoneA and message_1=line1.

split extractor, delimiter, column count, and preview button

SettingMeaning and checks
Input fieldSelect an existing parsed field, not a source topic or target table name.
separatorSplits on a hyphen in this example. If source values can contain this character, first confirm that the format is unambiguous.
numberExpected output column count, 2 here; not input message count or collection batch size.
Output columnsUsed by later filtering and mapping. Use the actual preview column names.

Also test message=zoneA and message=zoneA-line1-extra. With this two-column configuration, the former produces message_0=zoneA and empty message_1; the latter still produces only zoneA and line1, discarding the third segment extra. Missing or extra segments do not necessarily cause a message error. If the business requires exactly two segments, validate input format first; a two-column configuration does not replace format validation. To retain three segments, reconfigure and check all three columns.

To process another source column, click Add Extraction/Split and configure and preview each input column separately. Remove unneeded rules with their row's delete button. After deletion, check downstream filtering and mapping and fix references to removed output columns.

View an interface example of splitting results

The image below uses the separate message="hello-word" example, with input id values 1 and 2. Splitting on the hyphen produces message_0 equal to hello and message_1 equal to word for both, while id still distinguishes the records. It illustrates preview columns and row counts, not actual output of the zoneA-line1 sample above.

Two split messages retain id and generate message_0 and message_1

Check retained columns, generated columns, and record count together. hello and word in the image are source text splitting results, not constants to enter into the extractor.

For nested JSON, select the corresponding field and JSON extraction rule. For formatted text, use Parsing (JSON, Regex, UDT). Whether extracted and original columns coexist depends on the rule's retention settings and preview. Avoid downstream references to fields that have been replaced.

2.1 Extract a numeric value and unit from a voltage string​

This is a separate smart meter sample. Do not layer it onto the message splitting rule above. Replace the sample and select JSON parsing first:

[
{"groupid":170001,"voltage":"221V","current":12.3,"ts":"2026-11-20T00:00:00Z","inuse":true,"location":"beijing.chaoyang.datun"},
{"groupid":170001,"voltage":"220V","current":12.2,"ts":"2026-11-20T00:00:02Z","inuse":true,"location":"beijing.chaoyang.datun"},
{"groupid":170001,"voltage":"216V","current":12.5,"ts":"2026-11-20T00:00:04Z","inuse":false,"location":"beijing.chaoyang.datun"}
]

In Extract or Split from Column, select voltage, choose extractor regex, and enter this named capture group expression:

^(?<voltage>[0-9]+)(?<voltage_unit>[a-zA-Z]+)$

Preview this step. Confirm string voltage values 221, 220, and 216, voltage_unit equal to V for all, and numeric current values 12.3, 12.2, and 12.5 unchanged. Named groups determine output field names. Removing units does not automatically turn captures into integers. In later mapping, explicitly convert voltage to INT and use a type retaining decimals for current, such as DOUBLE. Do not also convert current to an integer and lose its decimal part.

This expression matches only nonnegative integers immediately followed by English letters; it does not accept negatives, decimals, or intervening spaces. Capturing a unit does not validate that it is volts. If other units such as mV may occur, validate units and normalize the measurement scale under business rules before writing; do not merely remove units. Preview actual possible nonmatching inputs separately and inspect results. Do not assume empty columns or error archives will always be produced.

To split time text into date and time columns, add another split rule for ts, with separator T and column count 2. The first record should produce ts_0="2026-11-20" and ts_1="00:00:00Z". This is text splitting only: the final Z remains in the time field. It is not a time zone conversion, and the date column alone is not a complete primary timestamp. If the target needs the full business time, retain and map the complete value with its time zone. Do not substitute the current time.

View voltage extraction, time splitting, and site conversion

Smart meter preview with named voltage and unit captures, time splitting, and site conversion

The image uses a historical date and time text without a time zone. It only shows field-processing controls, not expected times for this page's UTC sample. The convert lookup for location appears in the next section: its keys match original location values, not current. All three site texts in the image are replaced with beijing.chaoyang.datunludong. Verify each of the three rule categories separately before checking combined record counts, fields, types, and time zones. Copying the entire image first can obscure which step failed.

2.2 Lookup value conversion​

convert replaces strings using a lookup table. It is not Regex replacement or numeric calculation. Select this rule on original field location and enter this JSON lookup:

{"beijing.chaoyang.datun":"beijing.chaoyang.datunludong","__taosx_default":"unknown"}

An input exactly equal to beijing.chaoyang.datun becomes beijing.chaoyang.datunludong. Unmatched non-null strings become unknown. __taosx_default is optional; without it, unmatched values remain unchanged. Existing nulls do not become the default string. With a new field name, output adds a converted column and retains the original; without one, it replaces the original field. Check matched, unmatched, and null samples before updating downstream mapping.

3. Filter records​

Start with a single condition in Filter:

id != 1

Preview the id=2 sample and expect one retained record. Change only id to 1 and preview again; expect no retained records. Filtering acts on records, not merely a hidden column. Excluded data is not automatically recovered because the task remains running.

Filter condition and result preview button

Before combining conditions or rule blocks, test the combined behavior with samples that should be retained and excluded. For different message structures, also check matching for each rule block. Distinguish block matching conditions from filters within a block.

Use Add Filter to add conditions and the corresponding row's delete button to remove them. Change only one item at a time, then preview the full processing result with the same positive and negative samples. Confirm that rule combinations do not accidentally exclude records that should be kept.

View records that should remain after filtering

Applying id != 1 to the two hello-word messages above should retain only the id=2 row, with split columns still hello and word. Filtering does not clear the id=1 row or merely hide it in the preview. During actual operation, these records do not continue to the target.

Only the message with id 2 remains after filtering

If two rows remain or all disappear, check the actual id type, whether rules were saved, and the current rule block. Do not try to fix expressions by restarting tasks or changing consumer groups.

3.1 Write conditions for field types​

In JSON, true is Boolean, 220 an integer, 12.3 a float, and "220" a string. Regex and split extractions produce strings. Check preview types before writing filters. A displayed number does not establish a numeric field type.

Comparison operators include ==, !=, >, >=, <, and <=. Check both operands' types and business meaning first. Direct string comparison differs from comparison after numeric conversion.

PurposeExpression exampleInput and expectation
Boolean conditioninuse or !inuseWith inuse=true, the first retains and the second excludes.
Numeric comparisonvoltage > 200Numeric 220 is retained and 190 excluded.
String equalitylocation == "beijing.chaoyang.datun"Matching site text is retained; location="other" is excluded. Do not treat text comparison of "220" and "30" as numeric voltage comparison.
String to integer comparisonparse_int(voltage) > 200String "220" is retained. Test invalid string failure behavior separately.
String to float comparisonparse_float(temperature) >= 23.5String "23.5" is retained.
Empty string checklocation.is_empty()Checks only whether a string is empty, not missing fields or nulls.
String contents or prefix/suffixlocation.contains("chaoyang"), location.starts_with("beijing"), location.ends_with("datun")Each uses the actual string; case matters.
String lengthdevice.len == 4True for device="d001". Counts characters, not UTF-8 bytes; "设备一".len is 3. len is a property, not len().
Combined conditionslocation.starts_with("beijing") && voltage > 200Retains only if both are true; || is OR and ! negation.

Expressions must produce Boolean results; empty results do not match. Evaluation failures such as numeric parsing may become empty results and be filtered out without preview errors or error archives. For invalid numbers, check both input and output counts. A successful preview with no data does not establish correct processing. Correct source values or rules first, then confirm handling of these write errors under Write errors and abnormal data. Do not hide issues with defaults.

3.2 Filter by relative time​

If ts is an RFC 3339 date-time string with a time zone, use:

between_time_range(ts, -604800, 0)

Both offsets are in seconds. This example retains only data within seven days before processing time, excluding both bounds. It uses the parsing host's clock, not the source messages' maximum time. Do not pass a millisecond integer as the function's date-text input. Do not replace a fixed historical migration range with it: retrying the same old record at different times may produce different results.

Preview time-zone-qualified text for one hour ago, eight days ago, and one hour in the future. Expect retained, excluded, and excluded, respectively. Correct invalid dates during parsing; this filter is not date validity checking.

4. Convert types and field values​

In mapping, convert string temperature to target DOUBLE and ts to a millisecond timestamp. Expect numeric 23.5, not text. Do not substitute collection time for business time.

For value calculations, reference parsed numeric fields in an expression mapping interface. For example, numeric columns a=1 and b=2 should produce 3 with a + b. Confirm types before calculating; do not depend on automatic string concatenation or implicit conversion for business values. Time offsets have separate time expression rules. Do not apply ordinary numeric arithmetic examples directly to all time types.

tip

Test missing fields, nulls, and invalid numbers separately. Set defaults only when explicitly allowed by the business and document them in verification records. Do not automatically fill missing temperatures with zero or missing times with the current time.

4.1 Complete missing years, parse, then filter logs in order​

A batch of historical logs records only month, day, and time. For example, earlier Regex parsing produces time_text="02/01 20:49:40.813763", module="RPC", and device="d001". The business confirms that these logs belong to 2026 and use Asia/Shanghai. The target needs millisecond timestamps and only RPC records. In parsing configuration passed through taosx run -p, the mutate fragment can be:

{
"mutate": [
{
"map": {
"event_time_text": {"format": "2026/${time_text}"}
}
},
{
"extract": {
"event_time_text": {
"as": "timestamp(ms)",
"with": "%Y/%m/%d %H:%M:%S%.f",
"tz": "Asia/Shanghai",
"alias": "ts"
}
}
},
{
"filter": ["module == \"RPC\""]
}
]
}

The first step generates event_time_text="2026/02/01 20:49:40.813763". The second uses an explicit format and time zone to generate millisecond timestamp ts, which maps to the target primary timestamp. The third retains only module="RPC" records. Year completion must precede this time conversion. Filtering does not depend on time conversion and may be moved for troubleshooting, but repreview after every change. This is not complete task configuration; preceding parsing and the target model must still be supplied separately.

Check normal RPC, non-RPC, invalid-date, and missing-field samples one at a time. The source text represents 2026-02-01T20:49:40.813763+08:00. After millisecond conversion, target ts represents 2026-02-01T20:49:40.813+08:00; the trailing microsecond part is not retained. Non-RPC samples must be filtered out and absent from the target. If logs span years or their year is unknown, do not prepend fixed 2026 or substitute the current year or collection time. If the time is outside target retention, choose another confirmed test window. Also check invalid values and nulls against the actual error policy. Preview output or a running task alone does not mean success.

5. Verify the complete processing result​

Prepare a test table following Target table modeling and field mapping, mapping device or business object identifiers stably to child tables. Send one id=2 message and one id=1 message to the actual source using different recorded timestamps.

Query the target for both timestamps in the taosExplorer Data Browser or taos CLI. The retained record must have correct split fields and numeric temperature; the excluded record must not exist for this test object and time. Use another new timestamp to confirm continuous writing. Comparing only whole-database row counts cannot establish correct filtering or overwriting.

6. Troubleshooting and recovery​

SymptomNext step
Empty columns after adding splittingCompare actual input delimiters and segment counts, starting with the split preview.
All data disappears after adding filtersPreview positive and negative samples separately and check types and conditions. Do not change consumer groups first.
Temperature conversion becomes null or failsCheck strings for units, whitespace, or nonnumeric content, and confirm the null policy.
History remains missing after configuration rollbackFiltering or discarding already occurred. Check source retention and reread positions, and define a reingestion range.

Before changing an existing task, save its original configuration and stop it if necessary. For recovery, start the original task and send new test messages. Whether downtime data can be reread depends on the connector. See Restarts, checkpoints, and store-and-forward.

7. Limitations​

This page does not describe a general SQL computing engine. Not all functions supported by taos CLI are available in message expressions. Input columns and parsing interfaces differ by connector. Follow the respective guides for PI and OPC point models and TDengine migration renaming.