A filter is an object describing a predicate on a dataset records. Given a list of filters, the goal of the exercise is to generate a tree, representing those filters in another format.
Each filter has properties :
- type : string
- colId : string that represents an id
- args : object that can contain any argument that the filter needs. This is optional.
There are 4 types of filters.
{
type: CONTAINS,
colId: '0001',
args: {phrase: 'toto'}
}
The tree representation is
{
contains: {
field: '0001',
value: 'toto'
}
}
{
type: INVALID_RECORDS,
colId: '0001'
}
The tree representation is
{
invalid: {
field: '0001'
}
}
{
type: EMPTY_RECORDS,
colId: '0001'
}
The tree representation is
{
empty: {
field: '0001'
}
}
{
type: INSIDE_RANGE,
colId: '0001',
args: {
min: 5,
max: 20
}
}
The tree representation is
{
range: {
field: '0001',
start: 5,
end: 20
}
}
An array of filters means that all filters should apply on the records. To represent the composition, we have the and
operator.
{
and: [
leftFilter,
rightFilter
]
}
An and
tree has and array of 2 children. A child can be a single filter tree or another and
tree.