compositie filtering of application datasets

23
Composite Filtering of Datasets - - - Simplify Data Filtering Functions & Increase Performance

Upload: richard-gwozdz

Post on 23-Jan-2017

87 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Compositie filtering of application datasets

Composite Filtering of Datasets- - -

Simplify Data Filtering Functions & Increase Performance

Page 2: Compositie filtering of application datasets

Coffee ShopsServes Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

A Simple App for filtering coffee shops on a map

With 0 filters applied, the complete set of coffee shops appear

Data points in “map-space”

Page 3: Compositie filtering of application datasets

Coffee ShopsServes Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

A Simple App for filtering coffee shops on a map

With 0 filters applied, the complete set of coffee shops appear

Data points in “data-space”

Page 4: Compositie filtering of application datasets

Coffee ShopsServes Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

A Simple App for filtering coffee shops on a map

When the Cold Brew filter applied, we get a “filtered set” of data points.

How do we translate a user-interaction (e.g., click) into a filtered-set?

Page 5: Compositie filtering of application datasets

Coffee ShopsServes Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

A Simple App for filtering coffee shops on a map

How does an application translate a user-interaction (e.g., click) into a filtered-set?

Page 6: Compositie filtering of application datasets

Coffee ShopsServes Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

“DB-centric” filtering approach

1

Adding a single filter1) User click’s on “cold brew” filter

Page 7: Compositie filtering of application datasets

Coffee ShopsServes Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

“DB-centric” filtering approach

1

{“cold brew”: true }

2

Adding a single filter1) User click’s on “cold brew” filter2) Cold Brew filter criteria sent to database

Page 8: Compositie filtering of application datasets

Coffee ShopsServes Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

“DB-centric” filtering approach

1

{“cold brew”: true }

2

3

Adding a single filter1) User click’s on “cold brew” filter2) Cold Brew filter criteria sent to database3) Filtered set of coffee shops returned

Page 9: Compositie filtering of application datasets

Coffee ShopsServes Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

1

{ “cold brew”: true “food” : sandwiches }

2

3

Adding an additional filter 1) User click’s on “food” filter2) Cold Brew and Food filter-criteria sent to database.3) Filtered set of coffee shops returned

“DB-centric” filtering approach

Page 10: Compositie filtering of application datasets

Coffee ShopsServes Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 51

{ “cold brew”: true “food” : sandwiches “reviews”: [3,5] }

2

3

Adding a 3rd filter 1) User click’s on “food” filter2) Cold Brew, Food, Review Range filter-criteria sent to database3) Filtered set of coffee shops returned

“Stateless” filtering approach

Page 11: Compositie filtering of application datasets

Coffee ShopsServes Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 51

{ “cold brew”: true “food” : sandwiches “reviews”: [3,5] }

2

3

Inefficiency identified This approach does not leverage the DB processing performed on previous

user interactions

“Stateless” filtering approach

Page 12: Compositie filtering of application datasets

Details1) Each user interaction adds single criteria, but ALL criteria sent and processed

after each interaction

2) The DB filter operation gets more expensive as the number of potentially submitted filters increases

3) “Unselecting” a filter requires another database operation, even though the application had the resultant dataset prior to toggling this filter on

Inefficiency identified This approach does not leverage the DB processing performed on

previous user clicks

“Stateless” filtering approach

Page 13: Compositie filtering of application datasets

“Stateless” filtering approach

Additional downsides of this DB-centric approach:1) A single “catch-all” DB function gets increasingly complicated as number and

types of possible filters grow

2) A single DB function has to handle “null” filter-critera - it needs to be ready to accept values for all filter types - but all might not be sent

Example: Cold-brew filter sent, but food and reviews filter values are undefined; a single DB function needs to be ready to process food and review even though they aren’t in the incoming request

Page 14: Compositie filtering of application datasets

Alternative: “Stateful” filtering approach

1) Store the result of each individual filter set on browser2) Move set intersections from DB to the browser

Page 15: Compositie filtering of application datasets

{ “coffeeShops”:{ totalSet: [1,2,3,…,n] }

}

Angular service object (Keep track of the ID set associated with each individual filter)

On App load: retrieve the total set, store it as ID array

total-set

“Stateful” filtering

Coffee ShopsServes Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

Page 16: Compositie filtering of application datasets

{ “coffeeShops”:{ totalSet: [1,2,3,…,n], finalSet:[1,2,3,…,n] }

}

When no filters: total set = final set

total-set

Angular service object (Keep track of the ID set associated with each individual filter)

“Stateful” filtering

Coffee ShopsServes Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

Page 17: Compositie filtering of application datasets

{ “coffeeShops”:{ totalSet: [1,2,3,…,n], filteredSets: { coldBrew:{resultSet: [2,4, …, n] } }

}

Serves Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

Coffee Shops

Add a filter

coldbrew-set

Angular service object (Keep track of the ID set associated with each individual filter)

“Stateful” filtering

Page 18: Compositie filtering of application datasets

{ “coffeeShops”:{ totalSet: [1,2,3,…,n], filteredSets: { coldBrew:{resultSet: [2,4, …, n] } finalSet:[2,4,…,n] }

}

single filter result-set = final set

coldbrew-set

Angular service object (Keep track of the ID set associated with each individual filter)

“Stateful” filtering

Serves Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

Coffee Shops

Page 19: Compositie filtering of application datasets

{ “coffeeShops”:{ totalSet: [1,2,3,…,n], filteredSets: { coldBrew:{ resultSet: [2,4, …, n], food: { resultSet: [4,5, … n] } }

}

Add additional filter

coldbrew-set

food-set

Serves Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

Coffee Shops

Angular service object (Keep track of the ID set associated with each individual filter)

This set stored during previous user interaction

“Stateful” filtering

Page 20: Compositie filtering of application datasets

{ “coffeeShops”:{ totalSet: [1,2,3,…,n], filteredSets: { coldBrew:{ resultSet: [2,4, …, n], food: { resultSet: [4,5, … n] }, finalSet: [4,7 … n] }

}

Angular service object

coldbrew-set food-set

INTERSECT ID ARRAYS IN THE ANGULAR SERVICE!

Intersection of the two arrays = final set

“Stateful” filtering

Serves Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

Coffee Shops

Page 21: Compositie filtering of application datasets

{ “coffeeShops”:{ totalSet: [1,2,3,…,n], filteredSets: { coldBrew:{ resultSet: [2,4, …, n], food: { resultSet: [4,5, … n] }, finalSet: [2,4 … n] }

}

Angular service object

coldbrew-set food-set

Removing a filter does not require another round trip to DB

Remove a filter

“Stateful” filtering

Serves Cold Brew?

Yes NoServes what food?

Pastry Sandwiches Fruit

Reviews

0 5

Coffee Shops

Page 22: Compositie filtering of application datasets

Coffee ShopsAttributes:

Serves Cold Brew?Yes No

Serves what food?Pastry Sandwiches Fruit

Reviews

0 5

“Stateful” filtering

Angular program flow for “stateful filtering”.

1. User clicks on Cold Brew “yes”, fires an ng-click with info about the filter.

2. Controller tells service what type of filter this is (cold brew) and the value (yes)

3. Service checks a state object to see if this particular filter already has a value and a result set associated with it (e.g., previous UX had cold brew : no filter); if so it clears that value

4. Service determines which API endpoint to request a the filtered set from, and passes on the relevant request data { coldbrew: true} onto the endpoint

5. Endpoint returns a integer array of IDs meeting the filter-criteria to the service

6. The service completes the intersection of result sets from all currently toggled on filters

7. The service broadcasts the final intersected ID set to an listeners (e.g. a map controller the uses the ID array to show or hide map points).

Page 23: Compositie filtering of application datasets

“Stateful” filtering

1) Distributes processing across user interactions2) Eliminates DB trip for “filter-removal” event3) More performant - each DB operation is less complex; Intersections on the

browser are very quick (e.g, intersecting 4 10000 element integer arrays took 0.033s)

4) Simplifies DB function development5) Allows for a more customized set of DB filters.

Example Application instance “AAA”: food filter operates like an AND (pastries AND sandwiches) Application instance “BBB”: the filter operates like and OR (pastries OR sandwiches)You can easily have separate simple API endpoints/DB functions that handle each of the above cases for this type of filter instead of multiple large, complicated DB functions that handle all possible filter combinations in a simple request.

Benefits