Filtering¶
The Field object¶
In order to express filters, you’ll need to import Field, in addition to
Query:
from montage import Query, Field
import {Query, Field} from 'montagedata';
Comparison filters¶
Note
The Python library supports native syntax for comparison operations
where possible. This syntax uses comparison operators directly instead
of calling a method on Field. Operators include ==, <,
>, <=, and >=. Examples for both will be given when
available.
Equal¶
Query('movies').filter(
Field('year') == 2009
)
Query('movies').filter(
Field('year').eq(2009)
)
new Query('movies').filter(
new Field('year').eq(2009)
)
Case-insensitive equals¶
Query('movies').filter(
Field('name').ieq('star wars')
)
new Query('movies').filter(
new Field('name').ieq('star wars')
)
Not equal¶
Query('movies').filter(
Field('year') != 2009
)
Query('movies').filter(
Field('year').ne(2009)
)
new Query('movies').filter(
new Field('year').ne(2009)
)
Less than¶
Query('movies').filter(
Field('year') < 1990
)
Query('movies').filter(
Field('year').lt(1990)
)
new Query('movies').filter(
new Field('year').lt(1990)
)
Less or equal¶
Query('movies').filter(
Field('year') <= 1990
)
Query('movies').filter(
Field('year').le(1990)
)
new Query('movies').filter(
new Field('year').le(1990)
)
Greater than¶
Query('movies').filter(
Field('year') > 2000
)
Query('movies').filter(
Field('year').gt(2000)
)
new Query('movies').filter(
new Field('year').gt(2000)
)
Greater or equal¶
Query('movies').filter(
Field('year') >= 2000
)
Query('movies').filter(
Field('year').ge(2000)
)
new Query('movies').filter(
new Field('year').ge(2000)
)
In¶
Query('movies').filter(
Field('year').in_([2000, 2001, 2002])
)
new Query('movies').filter(
new Field('year').in([2000, 2001, 2002])
)
Contains¶
Query('movies').filter(
Field('name').contains('the')
)
new Query('movies').filter(
new Field('year').contains('the')
)
Regular expression¶
Accepts RE2 syntax.
Query('users').filter(
Field('zipcode').regex('\d{5}')
)
new Query('user').filter(
new Field('zipcode').regex('\d{5}')
)
Date and time filters¶
Date¶
Query('games').filter(
Field('timestamp').date() == '2016-02-17'
)
new Query('games').filter(
new Field('timestamp').date().eq('2016-02-17')
)
Time¶
Query('games').filter(
Field('timestamp').time() == '16:20'
)
new Query('games').filter(
new Field('timestamp').time().eq('16:20')
)
Year¶
Query('users').filter(
Field('birthday').year() == 1987
)
new Query('users').filter(
new Field('birthday').year().eq(1987)
)
Month¶
Query('users').filter(
Field('birthday').month() == 7
)
new Query('users').filter(
new Field('birthday').month().eq(7)
)
Day¶
Query('users').filter(
Field('birthday').day() == 24
)
new Query('users').filter(
new Field('birthday').day().eq(24)
)
Hours¶
Query('games').filter(
Field('timestamp').hours() == 12
)
new Query('games').filter(
new Field('timestamp').hours().eq(12)
)
Minutes¶
Query('games').filter(
Field('timestamp').minutes() == 4
)
new Query('games').filter(
new Field('timestamp').minutes().eq(4)
)
Seconds¶
Query('games').filter(
Field('timestamp').seconds() == 0
)
new Query('games').filter(
new Field('timestamp').seconds().eq(0)
)
Day of month¶
Query('games').filter(
Field('timestamp').day_of_month() == 2
)
new Query('games').filter(
new Field('timestamp').day_of_month().eq(2)
)
Day of year¶
Query('games').filter(
Field('timestamp').day_of_year() == 52
)
new Query('games').filter(
new Field('timestamp').day_of_year().eq(52)
)
Geospatial filters¶
Intersects¶
Query('movies').filter(
Field('location').intersects({
'type': 'Polygon',
'coordinates': [
[
[-119.92675781249999, 36.82357691815722],
[-119.7509765625, 36.6739263393281],
[-119.57382202148439, 36.80598611937673],
[-119.73724365234375, 36.914764288955936],
[-119.92675781249999, 36.82357691815722]
]
]
})
)
new Query('movies').filter(
new Field('location').intersects({
'type': 'Polygon',
'coordinates': [
[
[-119.92675781249999, 36.82357691815722],
[-119.7509765625, 36.6739263393281],
[-119.57382202148439, 36.80598611937673],
[-119.73724365234375, 36.914764288955936],
[-119.92675781249999, 36.82357691815722]
]
]
})
)
Includes¶
Query('movies').filter(
Field('location').intersects({
'type': 'Point',
'coordinates': [-118.35399627685547, 34.13759651725404]
})
)
new Query('movies').filter(
new Field('location').intersects({
'type': 'Point',
'coordinates': [-118.35399627685547, 34.13759651725404]
})
)