Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5918b2c
move dj.config into settings.py
dimitri-yatsenko Dec 2, 2018
bc85f21
Merge branch 'dev' into attachments
dimitri-yatsenko Dec 2, 2018
92553b0
Merge branch 'master' of https://github.com/datajoint/datajoint-pytho…
dimitri-yatsenko Dec 2, 2018
c127693
Merge branch 'dev' into attachments
dimitri-yatsenko Dec 3, 2018
1b188da
Merge branch 'dev' into attachments
dimitri-yatsenko Dec 3, 2018
13573c5
Merge branch 'dev' into attachments
dimitri-yatsenko Dec 3, 2018
f3dd5b3
add properties for heading attributes for supporting configurable blo…
dimitri-yatsenko Dec 3, 2018
046291a
rename property is_supported to unsupported for heading attributes
dimitri-yatsenko Dec 3, 2018
1f5fe9d
load configurable fields
dimitri-yatsenko Dec 3, 2018
3350516
implement declaration of configurable attributes: blob- and attach.
dimitri-yatsenko Dec 3, 2018
acc07fb
prepare for saving attachments
dimitri-yatsenko Dec 3, 2018
c11bbbf
add attach.py for saving and loading attachments
dimitri-yatsenko Dec 3, 2018
390b0b7
implement inserting attachments
dimitri-yatsenko Dec 3, 2018
2c04d74
implement fetch of attachments and configurable blobs
dimitri-yatsenko Dec 3, 2018
43e9c76
fix issue #467
dimitri-yatsenko Dec 3, 2018
51336ff
further cleanup of __init__.py
dimitri-yatsenko Dec 3, 2018
cee588e
Use DEFAULT instead of NULL when the insert value is None.
dimitri-yatsenko Dec 3, 2018
c04f974
slight refactor of Table.insert
dimitri-yatsenko Dec 3, 2018
9de4782
fix for error introduced in previous commit
dimitri-yatsenko Dec 3, 2018
0c35af1
Merge branch 'master' of https://github.com/datajoint/datajoint-pytho…
dimitri-yatsenko Dec 3, 2018
1588303
Merge branch 'master' of https://github.com/datajoint/datajoint-pytho…
dimitri-yatsenko Dec 4, 2018
f265674
implement external file folding
dimitri-yatsenko Dec 7, 2018
bcebce5
Merge branch 'master' into attachments
dimitri-yatsenko Dec 11, 2018
50f17ce
remote the `keys` property from `fetch` (a warning was displayed in s…
dimitri-yatsenko Dec 11, 2018
f141aa7
add `dj.get_schema_names()`
dimitri-yatsenko Dec 11, 2018
6310c7d
stylistic improvements
dimitri-yatsenko Dec 13, 2018
7cb1d3f
Merge branch 'master' of https://github.com/datajoint/datajoint-pytho…
dimitri-yatsenko Dec 13, 2018
aa72832
Merge branch 'master' into attachments
dimitri-yatsenko Dec 13, 2018
4818bbb
Merge branch 'master' into attachments
dimitri-yatsenko Dec 19, 2018
3aa936e
complete implementation of attachments and configurable blobs with pa…
dimitri-yatsenko Jan 14, 2019
bdf8195
Merge branch 'master' of https://github.com/datajoint/datajoint-pytho…
dimitri-yatsenko Jan 14, 2019
173bf1d
add test for configurable blobs
dimitri-yatsenko Jan 14, 2019
61c2ce7
drop support of Python 3.4
dimitri-yatsenko Jan 14, 2019
aa6a2ce
add test for attachment methods
dimitri-yatsenko Jan 14, 2019
f49cf22
fix test_attach
dimitri-yatsenko Jan 15, 2019
eea3e20
fix 3.4 compatibility
dimitri-yatsenko Jan 15, 2019
7ee6134
Python 3.4 compatibility
dimitri-yatsenko Jan 15, 2019
6701abb
fix Python 3.4 compatibility
dimitri-yatsenko Jan 15, 2019
346f47f
fix Python 3.4 compatibility
dimitri-yatsenko Jan 15, 2019
b2087aa
fix Python 3.4 compatibility
dimitri-yatsenko Jan 15, 2019
332cfd6
Merge branch 'master' of https://github.com/datajoint/datajoint-pytho…
dimitri-yatsenko Jan 15, 2019
0c491e2
improve error message
dimitri-yatsenko Jan 15, 2019
7e51e4f
improve error message
dimitri-yatsenko Jan 15, 2019
0434fc8
Merge branch 'attachments' of https://github.com/dimitri-yatsenko/dat…
dimitri-yatsenko Jan 16, 2019
484e926
bugfix in S3 store
dimitri-yatsenko Jan 16, 2019
1a83fe6
bugfix in S3 store
dimitri-yatsenko Jan 16, 2019
4c8b6eb
Merge branch 'attachments' of https://github.com/dimitri-yatsenko/dat…
dimitri-yatsenko Jan 16, 2019
bf66d64
Merge branch 'master' of https://github.com/datajoint/datajoint-pytho…
dimitri-yatsenko Jan 22, 2019
8f4e8f9
Merge branch 'master' into attachments
dimitri-yatsenko Feb 4, 2019
0826d94
implement external storage cleanup with subfolding
dimitri-yatsenko Feb 6, 2019
fb14029
fix error message and release date
dimitri-yatsenko Feb 7, 2019
90cf697
improve warning messages
dimitri-yatsenko Feb 8, 2019
afeadb1
change version to 0.12.dev
dimitri-yatsenko Feb 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
implement fetch of attachments and configurable blobs
  • Loading branch information
dimitri-yatsenko committed Dec 3, 2018
commit 2c04d74df2ec1c6737cc019bb8f6adb0d71a2f37
38 changes: 23 additions & 15 deletions datajoint/fetch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import OrderedDict
from functools import partial
import numpy as np
from .blob import unpack
from . import blob, attach
from .errors import DataJointError
import warnings

Expand All @@ -24,6 +24,23 @@ def to_dicts(recarray):
yield dict(zip(recarray.dtype.names, rec.tolist()))


def _get(connection, attr, data, squeeze):
"""
:param connection:
:param attr: an attribute from the heading
:param data: literal value fetched from the table
:param squeeze: if True squeeze blobs
:return: unpacked data
"""
if attr.is_external:
data = connection.schemas[attr.database].external_table.get(data)
if attr.is_blob:
return blob.unpack(data, squeeze=squeeze)
if attr.is_attachment:
return attach.save(data)
return data


class Fetch:
"""
A fetch object that handles retrieving elements from the table expression.
Expand Down Expand Up @@ -61,23 +78,18 @@ def __call__(self, *attrs, offset=None, limit=None, order_by=None, as_dict=False
'Consider setting a limit explicitly.')
limit = 2 * len(self._expression)

get = partial(_get, self._expression.connection, squeeze=squeeze)
if not attrs:
# fetch all attributes
cur = self._expression.cursor(as_dict=as_dict, limit=limit, offset=offset, order_by=order_by)
heading = self._expression.heading
if as_dict:
ret = [OrderedDict((name, unpack(d[name], squeeze=squeeze) if heading[name].is_blob else d[name])
for name in heading.names)
for d in cur]
ret = [OrderedDict((name, get(heading[name], d[name])) for name in heading.names) for d in cur]
else:
ret = list(cur.fetchall())
ret = np.array(ret, dtype=heading.as_dtype)
for name in heading:
if heading[name].is_external:
external_table = self._expression.connection.schemas[heading[name].database].external_table
ret[name] = list(map(unpack, map(external_table.get, ret[name])))
elif heading[name].is_blob:
ret[name] = list(map(partial(unpack, squeeze=squeeze), ret[name]))
ret[name] = list(map(partial(get, heading[name]), ret[name]))
else: # if list of attributes provided
attributes = [a for a in attrs if not is_key(a)]
result = self._expression.proj(*attributes).fetch(
Expand Down Expand Up @@ -109,6 +121,7 @@ class Fetch1:
def __init__(self, relation):
self._expression = relation


def __call__(self, *attrs, squeeze=False):
"""
Fetches the expression results from the database when the expression is known to yield only one entry.
Expand All @@ -132,12 +145,7 @@ def __call__(self, *attrs, squeeze=False):
ret = cur.fetchone()
if not ret or cur.fetchone():
raise DataJointError('fetch1 should only be used for relations with exactly one tuple')

def get_external(attr, _hash):
return unpack(self._expression.connection.schemas[attr.database].external_table.get(_hash))

ret = OrderedDict((name, get_external(heading[name], ret[name])) if heading[name].is_external
else (name, unpack(ret[name], squeeze=squeeze) if heading[name].is_blob else ret[name])
ret = OrderedDict((name, _get(self._expression.connection, heading[name], ret[name], squeeze=squeeze))
for name in heading.names)
else: # fetch some attributes, return as tuple
attributes = [a for a in attrs if not is_key(a)]
Expand Down