refactor filter code in sql backend

refactor filter TODO tasks in sqlalchemy backend

Change-Id: Ia7f39b553bdbb861966b0f4d5fca1820af1c7082
Merge "refactor filter code in sql backend"