Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
065b11a
Add function to fetch block ids and sizes from db
hardbyte Mar 4, 2020
6f7c75c
Retrieve blocking info in create_comparison_jobs task
hardbyte Mar 4, 2020
ebcb248
WIP - identify blocks that need to be broken up further
hardbyte Mar 4, 2020
a066ccc
Query for getting encodings in a block
hardbyte Mar 6, 2020
fb550de
Split tasks into chunks using blocking information
hardbyte Mar 6, 2020
610b3bb
Refactor create comparison jobs function
hardbyte Mar 8, 2020
d838fe4
More refactoring of chunk creation
hardbyte Mar 9, 2020
ec36e8d
Add a few unit tests for chunking
hardbyte Mar 9, 2020
ddcbcc3
Add database index on encodings table
hardbyte Mar 9, 2020
4ab16e6
clknblocks not clksnblocks and other minor cleanup
hardbyte Mar 10, 2020
d66bf58
cleanup
hardbyte Mar 10, 2020
1e5151f
Add blocking concept to docs
hardbyte Mar 13, 2020
aec9b5c
Deduplicate candidate pairs before solving
hardbyte Mar 15, 2020
f30c819
Catch the empty candidate pair case
hardbyte Mar 15, 2020
9dc59e1
Simplify solver task by using anonlink's _merge_similarities function
hardbyte Mar 16, 2020
6219e44
Update celery
hardbyte Mar 16, 2020
0b6a4c2
Address code review feedback
hardbyte Mar 18, 2020
5467362
Bump version to beta2
hardbyte Mar 18, 2020
f342d5a
Celery concurrency defaults
hardbyte Mar 19, 2020
2add5ef
Add another layer of tracing into the comparison task
hardbyte Mar 19, 2020
e2ebe99
Update task names in celery routing
hardbyte Mar 19, 2020
38b624f
Faster encoding retrieval by using COPY.
hardbyte Mar 22, 2020
7ec7fef
Pass on stored size when retrieving encodings from DB
hardbyte Mar 22, 2020
24caa79
Increase time on test
hardbyte Mar 22, 2020
dc1983b
Refactor binary copy into own function for easier reuse and testing
hardbyte Mar 23, 2020
8bae410
Add more detailed tracing around binary encoding insertions.
hardbyte Mar 24, 2020
88e968d
Add tests for binary copy function
hardbyte Mar 24, 2020
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
Add tests for binary copy function
  • Loading branch information
hardbyte committed Mar 24, 2020
commit 88e968d2c2a0afbe1a05cd9e1600cddb2d150255
5 changes: 3 additions & 2 deletions backend/entityservice/database/selections.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,19 @@ def copy_binary_column_from_select_query(cur, select_query, stored_binary_size=1

:param select_query: An sql query that select's a single binary column. Include ordering the results.
:param stored_binary_size: Fixed size of each bytea data.
:raises AssertionError if the database implements an unhandled extension or the EOF is corrupt.
"""

copy_to_stream_query = """COPY ({}) TO STDOUT WITH binary""".format(select_query)
stream = io.BytesIO()
cur.copy_expert(copy_to_stream_query, stream)
# TODO: It may be more efficient to introduce a buffered binary stream instead of getting the entire stream at once

raw_data = stream.getvalue()

# Need to read/remove the Postgres Binary Header, Trailer, and the per tuple info
# https://www.postgresql.org/docs/current/sql-copy.html
_ignored_header = raw_data[:15]
header_extension = raw_data[16:20]
header_extension = raw_data[15:19]
assert header_extension == b'\x00\x00\x00\x00', "Need to implement skipping postgres binary header extension"
binary_trailer = raw_data[-2:]
assert binary_trailer == b'\xff\xff', "Corrupt COPY of binary data from postgres"
Expand Down
57 changes: 57 additions & 0 deletions backend/entityservice/integrationtests/dbtests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import pytest
import psycopg2

from entityservice.settings import Config as config


@pytest.fixture
def conn():
db = config.DATABASE
host = config.DATABASE_SERVER
user = config.DATABASE_USER
password = config.DATABASE_PASSWORD
conn = psycopg2.connect(host=host, dbname=db, user=user, password=password)
yield conn
conn.close()

@pytest.fixture
def cur(conn):
return conn.cursor()




@pytest.fixture()
def prepopulated_binary_test_data(conn, cur, num_bytes=4, num_rows=100):
creation_sql = """
DROP TABLE IF EXISTS binary_test;
CREATE TABLE binary_test
(
id integer not null,
encoding bytea not null
);"""
cur.execute(creation_sql)
conn.commit()

# Add data using execute_values
data = [(i, bytes([i % 128] * num_bytes)) for i in range(num_rows)]
psycopg2.extras.execute_values(cur, """
INSERT INTO binary_test (id, encoding) VALUES %s
""", data)

conn.commit()

# quick check data is there
cur.execute("select count(*) from binary_test")
res = cur.fetchone()[0]
assert res == num_rows

cur.execute("select encoding from binary_test where id = 1")
assert bytes(cur.fetchone()[0]) == data[1][1]

yield data

# delete test table
deletion_sql = "drop table if exists binary_test cascade;"
cur.execute(deletion_sql)
conn.commit()
28 changes: 22 additions & 6 deletions backend/entityservice/integrationtests/dbtests/test_insertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pytest import raises

from entityservice.database import insert_dataprovider, insert_encodings_into_blocks, insert_blocking_metadata, \
get_project, get_encodingblock_ids, get_block_metadata, get_chunk_of_encodings
get_project, get_encodingblock_ids, get_block_metadata, get_chunk_of_encodings, copy_binary_column_from_select_query

from entityservice.integrationtests.dbtests import _get_conn_and_cursor
from entityservice.models import Project
Expand All @@ -13,8 +13,29 @@
from entityservice.utils import generate_code


class TestBinaryCopy:

def test_copy_binary_column_from_select_query(self, conn, cur, prepopulated_binary_test_data):
query = "select encoding from binary_test where id >= 10 and id < 20"
res = list(copy_binary_column_from_select_query(cur, query, stored_binary_size=4))
assert len(res) == 10
for (i, original), stored in zip(prepopulated_binary_test_data[10:20], res):
assert original == stored

def test_copy_binary_column_from_select_query_empty(self, conn, cur, prepopulated_binary_test_data):
query = "select encoding from binary_test where id < 0"
res = list(copy_binary_column_from_select_query(cur, query, stored_binary_size=4))
assert len(res) == 0


class TestInsertions:

def _create_project(self):
project = Project('groups', {}, name='', notes='', parties=2, uses_blocking=False)
conn, cur = _get_conn_and_cursor()
dp_ids = project.save(conn)
return project, dp_ids

def _create_project_and_dp(self):
project, dp_ids = self._create_project()
dp_id = dp_ids[0]
Expand All @@ -28,11 +49,6 @@ def _create_project_and_dp(self):
assert len(dp_auth_token) == 48
return project.project_id, project.result_token, dp_id, dp_auth_token

def _create_project(self):
project = Project('groups', {}, name='', notes='', parties=2, uses_blocking=False)
conn, cur = _get_conn_and_cursor()
dp_ids = project.save(conn)
return project, dp_ids

def test_insert_project(self):
before = datetime.datetime.now()
Expand Down