datajoint / datajoint-python

Relational data pipelines for the science lab
https://datajoint.com/docs
GNU Lesser General Public License v2.1
163 stars 84 forks source link

Implement `farfetch` #242

Open dimitri-yatsenko opened 7 years ago

dimitri-yatsenko commented 7 years ago

Within _make_tuples functions, it may be possible to automate query formation for fetching data that can be uniquely identified by its attribute name.

For example,

nslices = (preprocess.Prepare.Galvo() & key).fetch1['nslices'] 
traces  = (preprocess.ExractTraces.Traces() & key).fetch['trace']  

would be replaced with

nslices, traces = dj.get('nslices', 'traces')

This is intended to work from _make_tuples only since it will need to know its place in the data hierarchy and the value of key.

eywalker commented 7 years ago

An alternative suggestion for the syntax.

search = self.search(key)     # create the search object
nslices = search['nslices']      # fetch nslices

# tables containing the attributes are joined if they are in the same search call
traces, rois = search['trace', 'roi']      # fetch matched traces and ROIs from different tables
dimitri-yatsenko commented 7 years ago

I like it. This will allow more portable code that relies on descriptive attribute names and survives changes in the schema design.

dimitri-yatsenko commented 7 years ago

Another discussion and a different syntax.

nslices = (self & key).search1['nslices']      # fetch nslices as a scalar.

# tables containing the attributes are joined if they are in the same search call
traces, rois = (self & key).search['trace', 'roi']      # fetch matched traces and ROIs from different tables
dimitri-yatsenko commented 7 years ago

Another syntax

search = self.search(key)
nslices = search.fetch1['nslices']      # fetch nslices as a scalar.

# tables containing the attributes are joined if they are in the same search call
traces, rois =  search.fetch['trace', 'roi']  
dimitri-yatsenko commented 7 years ago

Another syntax

nslices = self.get1(key, ['nslices'])      # fetch nslices as a scalar.

# tables containing the attributes are joined if they are in the same search call
traces, rois =  self.get(key, ['trace', 'roi']) 
eywalker commented 7 years ago

Between the last two, I'd prefer the search.fetch1 and search.fetch syntax, allowing us to not repeat key argument.

fabiansinz commented 7 years ago

I agree with @eywalker although I'd still prefer to rename search into something else.

eywalker commented 7 years ago

Do we have running candidates on what to rename search to?

dimitri-yatsenko commented 7 years ago

I propose farfetch. It's catchy and conveys its unusual power.

nslices = (rel & key).farfetch1['nslices']
traces = (rel & key).farfetch['traces']