Skip to content

Commit 0491b6d

Browse files
authored
Merge pull request #247 from aperture-data/release-0.4.6
Release 0.4.6
2 parents 0cd15ae + 7835401 commit 0491b6d

File tree

9 files changed

+55
-11
lines changed

9 files changed

+55
-11
lines changed

aperturedb/CSVParser.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,20 @@ class CSVParser(Subscriptable):
3131
In Dask mode the CSV file is read in chunks, and the operations are performed on each chunk.
3232
The tricky bit is that the chunck size is not known till the loader is created, so the processing happens when ingest is called.
3333
So the Data CSV has another signature, where the df is passed explicitly.
34+
35+
Typically, the response_handler is application specific, and loading does not break
36+
on errors in response_handlers, so the default behaviour is to log the error and continue.
37+
If you want to break on errors, set strict_response_validation to True.
3438
"""
3539

36-
def __init__(self, filename, df=None, use_dask=False):
40+
def __init__(self,
41+
filename: str,
42+
df=None,
43+
use_dask: bool = False,
44+
strict_response_validation: bool = False):
3745
self.use_dask = use_dask
3846
self.filename = filename
47+
self.strict_response_validation = strict_response_validation
3948

4049
if not use_dask:
4150
if df is None:

aperturedb/ConnectionDataCSV.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from aperturedb.CSVParser import CSVParser, CONSTRAINTS_PREFIX
3-
from aperturedb.Query import QueryBuilder
3+
from aperturedb.Query import QueryBuilder, ObjectType
44

55
logger = logging.getLogger(__name__)
66

@@ -83,6 +83,7 @@ def getitem(self, idx):
8383
dst_value = self.df.loc[idx, self.header[2]]
8484
connection_class = self.df.loc[idx, CONNECTION_CLASS]
8585
q = []
86+
members = ["_Image", "_Blob", "_Video", "_Descriptor"]
8687

8788
try:
8889
ref_src = (2 * idx) % 100000 + 1
@@ -93,6 +94,9 @@ def getitem(self, idx):
9394
self.src_key: ["==", src_value]
9495
}
9596
}
97+
# Special case for objects with blobs
98+
if self.src_class in members:
99+
cmd_params["blobs"] = False
96100
q.append(QueryBuilder.find_command(self.src_class, cmd_params))
97101

98102
ref_dst = ref_src + 1
@@ -103,6 +107,9 @@ def getitem(self, idx):
103107
self.dst_key: ["==", dst_value]
104108
}
105109
}
110+
# Special case for objects with blobs
111+
if self.dst_class in members:
112+
cmd_params["blobs"] = False
106113
q.append(QueryBuilder.find_command(self.dst_class, cmd_params))
107114

108115
ae = self._basic_command(idx,

aperturedb/Images.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ def get_similar_images(self, set_name, n_neighbors):
418418
"k_neighbors": n_neighbors + 1,
419419
"blobs": False,
420420
"distances": True,
421-
"ids": True,
422421
"uniqueids": True,
423422
}
424423
}, {

aperturedb/ParallelQuery.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515

1616
def execute_batch(q, blobs, db, success_statuses: list[int] = [0],
17-
response_handler: Callable = None, commands_per_query: int = 1, blobs_per_query: int = 0):
17+
response_handler: Callable = None, commands_per_query: int = 1, blobs_per_query: int = 0,
18+
strict_response_validation: bool = False):
1819
"""
1920
Execute a batch of queries, doing useful logging around it.
2021
Calls the response handler if provided.
@@ -64,6 +65,8 @@ def execute_batch(q, blobs, db, success_statuses: list[int] = [0],
6465
b[blobs_returned:blobs_returned + b_count] if len(b) < blobs_returned + b_count else None)
6566
except BaseException as e:
6667
logger.exception(e)
68+
if strict_response_validation:
69+
raise e
6770
blobs_returned += b_count
6871
else:
6972
# Transaction failed entirely.
@@ -174,10 +177,20 @@ def process_responses(requests, input_blobs, responses, output_blobs):
174177
worker_stats = {}
175178
if not self.dry_run:
176179
response_handler = None
180+
strict_response_validation = False
177181
if hasattr(self.generator, "response_handler") and callable(self.generator.response_handler):
178182
response_handler = self.generator.response_handler
183+
if hasattr(self.generator, "strict_response_validation") and isinstance(self.generator.strict_response_validation, bool):
184+
strict_response_validation = self.generator.strict_response_validation
179185
result, r, b = execute_batch(
180-
q, blobs, db, ParallelQuery.success_statuses, response_handler, self.commands_per_query, self.blobs_per_query)
186+
q,
187+
blobs,
188+
db,
189+
ParallelQuery.success_statuses,
190+
response_handler,
191+
self.commands_per_query,
192+
self.blobs_per_query,
193+
strict_response_validation=strict_response_validation)
181194
if result == 0:
182195
query_time = db.get_last_query_time()
183196
worker_stats["suceeded_commands"] = len(q)

aperturedb/Subscriptable.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ class Wrapper():
55
that will be a part of generator.
66
"""
77

8-
def __init__(self, list, response_handler):
8+
def __init__(self, list, response_handler, strict_response_validation):
99
self.list = list
1010
self.response_handler = response_handler
11+
self.strict_response_validation = strict_response_validation
1112

1213
def __len__(self):
1314
return len(self.list)
@@ -29,7 +30,11 @@ def __getitem__(self, subscript):
2930
step = subscript.step if subscript.step else 1
3031
return Wrapper(
3132
[self.getitem(i) for i in range(start, stop, step)],
32-
self.response_handler if hasattr(self, "response_handler") else None)
33+
self.response_handler if hasattr(
34+
self, "response_handler") else None,
35+
self.strict_response_validation if hasattr(
36+
self, "strict_response_validation") else None
37+
)
3338
else:
3439
if subscript < len(self):
3540
return self.getitem(subscript)

aperturedb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
logger = logging.getLogger(__name__)
99

10-
__version__ = "0.4.5"
10+
__version__ = "0.4.6"
1111

1212
# set log level
1313
logger.setLevel(logging.DEBUG)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
setuptools.setup(
2424
name="aperturedb",
25-
version="0.4.5",
25+
version="0.4.6",
2626
description="ApertureDB Client Module",
2727
install_requires=install_requires,
2828
long_description=long_description,

test/conftest.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ def db(request):
5151
return db
5252

5353

54+
def check_response_regressions(queries, input_blobs, responses, output_blobs):
55+
# Check that responses have no blobs
56+
first_command = list(responses[0].keys())[0]
57+
assert "blobs_start" not in responses[0][
58+
first_command], f"responses[0]={responses[0]}"
59+
60+
5461
@pytest.fixture()
5562
def insert_data_from_csv(db, request):
5663
"""
@@ -82,6 +89,10 @@ def insert_data_from_csv(in_csv_file, rec_count=-1, expected_error_count=0, load
8289
if hasattr(request, "param"):
8390
use_dask = request.param
8491
data = file_data_pair[in_csv_file](in_csv_file, use_dask=use_dask)
92+
93+
setattr(data, "response_handler", check_response_regressions)
94+
data.strict_response_validation = True
95+
8596
if rec_count != -1:
8697
data = data[:rec_count]
8798

@@ -106,7 +117,7 @@ def insert_data_from_csv(in_csv_file, rec_count=-1, expected_error_count=0, load
106117
if loader_result_lambda is not None:
107118
loader_result_lambda(loader, data)
108119

109-
# Preserve loader so that dask manager is not auto deleted.
120+
# Preserve loader so that dask manager is not auto deleted.
110121
# ---------------
111122
# Previously, dask's cluster and client were entirely managed in a context
112123
# insede dask manager. A change upstream broke that, and now we keep the DM

test/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3'
22

33
services:
44
aperturedb:
5-
image: aperturedata/aperturedb
5+
image: aperturedata/aperturedb:v0.15.1
66
volumes:
77
- ./aperturedb:/aperturedb
88
ports:

0 commit comments

Comments
 (0)