For the complete documentation index, see llms.txt. This page is also available as Markdown.

Conditions

Conditional operations in DataVec — filtering and transforming data based on conditions

A Condition is a predicate over a record (or sequence) that returns true or false. Conditions are the building blocks of two things in DataVec:

  1. Filters — remove records where a condition is true

  2. Conditional transforms — replace or copy values in a column when a condition is met

Most conditions are column-level: they inspect the value of a specific column and compare it against a threshold, set, or pattern.

The Condition Interface

All conditions implement Condition:

public interface Condition {
    boolean condition(Object input);             // evaluate on a full record
    boolean conditionSequence(Object sequence); // evaluate on a sequence
    Schema transform(Schema inputSchema);        // schema is unchanged for conditions
}

When used in a filter, a record is removed if condition(record) returns true. Keep this direction in mind when writing conditions — it is the opposite of what some filter libraries use.

Column Conditions

Column conditions apply to a specific named column, using a ConditionOp to specify the comparison.

ConditionOp Values

ConditionOp
Meaning

Equal

value == threshold

NotEqual

value != threshold

LessThan

value < threshold

LessThanOrEqual

value <= threshold

GreaterThan

value > threshold

GreaterThanOrEqual

value >= threshold

InSet

value is in a set

NotInSet

value is not in a set

DoubleColumnCondition

Checks a double-precision column against a threshold:

IntegerColumnCondition

LongColumnCondition

StringColumnCondition

Supports only Equal and NotEqual operators on string columns:

CategoricalColumnCondition

Applies to categorical columns. Supports Equal, NotEqual, InSet, and NotInSet:

TimeColumnCondition

Compares a Time column (stored as epoch milliseconds) against a threshold:

BooleanColumnCondition

Null and Invalid Value Conditions

NullWritableColumnCondition

True when the value in the specified column is a NullWritable (the DataVec representation of a missing value):

NaNColumnCondition

True when a floating-point column contains NaN:

InfiniteColumnCondition

True when a floating-point column contains positive or negative infinity:

InvalidValueColumnCondition

True whenever a column's value cannot be parsed as its declared type (e.g., a string where a Long is expected, or a value outside the declared min/max range):

This is particularly useful with FilterInvalidValues when you want to remove rather than fix bad records.

Regex Condition

StringRegexColumnCondition

True if the string value in a column matches (or does not match) a regex:

Sequence Length Condition

SequenceLengthCondition

True when a sequence's length satisfies a comparison:

Boolean Logic: AND, OR, NOT, XOR

BooleanCondition provides static factory methods to combine conditions:

AND

True only if all component conditions are true:

OR

True if any component condition is true:

NOT

Inverts a condition:

XOR

True when exactly one of the two conditions is true:

Nesting

Boolean conditions can be nested to arbitrary depth:

Sequence Condition Mode

For single-column conditions applied to sequences, you can control how the condition is evaluated across all time steps:

  • SequenceConditionMode.And — the condition is true for the sequence only if it is true at every time step

  • SequenceConditionMode.Or — the condition is true for the sequence if it is true at any time step

  • SequenceConditionMode.NoSequenceMode — applying this condition to a sequence throws an error

Most column condition constructors accept an optional SequenceConditionMode parameter:

Using Conditions in a TransformProcess

As a Filter

In a Conditional Replace

Conditions are evaluated at runtime for every record. Constructing complex nested conditions has essentially no overhead compared to the I/O of reading the data itself.

Last updated

Was this helpful?