Bhagwat Posane
Bhagwat Posane

Reputation: 29

How to apply datetime filter on bigtable using python api

I have tried below code to filter records between two dates in two scenarios, but it fails for below range.

DurationFrom ="2018-01-9"
DurationTo = "2018-01-10"

and works as expected for

DurationFrom ="2018-01-01"
DurationTo = "2018-01-03"

>>> DurationFrom ="2018-01-9"                                                                                                                                                                                                                 
>>> DurationTo = "2018-01-10"                                                                                                                                                                                                              
>>> visit_dt_filter = ValueRangeFilter(start_value = DurationFrom, end_value = DurationTo)
>>> col1_filter = ColumnQualifierRegexFilter(b'visit_dt')
>>> chain1 = RowFilterChain(filters=[col1_filter, visit_dt_filter])
>>> partial_rows = table.read_rows(filter_=chain1)
>>> count = 0
>>> for row in partial_rows:
...     count += 1

The code ends with an error :

"Error in chained row filter #1 : Error in field 'value_range_filter' : start_value must be less than end_value"

I suspect the comparison ASCII based hence it fails.

In such scenarios how to use ValueRangefilter? There is another filter ValueRegexFilter is it useful to filter date values and how does it perform?

Upvotes: 2

Views: 369

Answers (1)

Solomon Duskis
Solomon Duskis

Reputation: 2711

This is the problem:

DurationFrom ="2018-01-9"
DurationTo = "2018-01-10"

It needs to be

DurationFrom ="2018-01-09"
DurationTo = "2018-01-10"

'9' > '1'

Upvotes: 1

Related Questions