This post deals with using rethinkdb with python repl
Do your installations
Note: in every python example, I have intended it wrongly for easy reading. Please make it into a single line, before pasting in the Repl. Try typing.
Get the Conn
[]
create your table
[]
Understand the Data. Nested Data. We need to fetch multiple kinds of results from this data.
[]
Insert the Data
[]
Concat Map:
Used to collect arrays of data inside various documents, under a same key. Map, can be used for the same, but that would give a nested array kind result. While Concat Map gives plain array.
Sample command sets the limit of results to be displayed.
[gist file="3-concat_map-single.py"]https://gist.github.com/sumitasok/086792d3814ad229b3cb[/gist]
lambda calls each row in the document, as attendees and returns the value of key "attendee" inside each row into the result array.
The Result would be
[gist file="3-concat_map-single_result.js"]https://gist.github.com/sumitasok/086792d3814ad229b3cb[/gist]
To further collect the list of attendee details alone nested inside the order/report, do one more Concat Map on the resulting data.
[gist file="3-concat_map.py"]https://gist.github.com/sumitasok/086792d3814ad229b3cb[/gist]
The Result would be
[gist file="3-concat_map_result.js"]https://gist.github.com/sumitasok/086792d3814ad229b3cb[/gist]
Filters:
Let us fetch the data with some conditions, so that, only data with a particular ticketId is displayed in result.
[gist file="4-concat_map_filter.py"]https://gist.github.com/sumitasok/086792d3814ad229b3cb[/gist]
The result would be like this
[gist file="4-concat_map_filter_result.js"]https://gist.github.com/sumitasok/086792d3814ad229b3cb[/gist]
To further reduce the list to have more conditions attach a filter to the resulting data. Try doing a count on this to see how many records have same email ID.
[gist file="5-concat_twice-filter.py"]https://gist.github.com/sumitasok/086792d3814ad229b3cb[/gist]
Now try fetching Attendees list who has bought a particular ticket
[gist file="6-fetch_by_ticketId.py"]https://gist.github.com/sumitasok/086792d3814ad229b3cb[/gist]
Result:
Only Sumit has bought one ticket of ID ticket-id-4321
[gist file="6-fetch_by_ticketId-result.js"]https://gist.github.com/sumitasok/086792d3814ad229b3cb[/gist]
Now you must be clear about how concat_map works and how to do a simple filter on data.
Do a filter on Date. So any record which was updated between "2012-01-01" and "2015-01-01" will be the result.
[gist file="7-filter_by_date.py"]https://gist.github.com/sumitasok/086792d3814ad229b3cb[/gist]
Now attach the same filter before all our other pipelines. So that first time, the filter is run, then on the resulting data concat_map is run, which return an array of tickets type and attendees on which run the filter to find out the particular ticketID you are looking for, and concat_map the attendees
[gist file="7-filter_by_date-concat.py"]https://gist.github.com/sumitasok/086792d3814ad229b3cb[/gist]
The result would be, the array of users who has done booking ticket "ticket-id-4321" in the specified time interval.
[gist file="7-filter_by_date-concat_result.json"]https://gist.github.com/sumitasok/086792d3814ad229b3cb[/gist]