Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in Cmake schema handling code, add test for 1:1 relationship in EDC expressions. #780

Merged
merged 2 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 29 additions & 1 deletion production/direct_access/tests/test_expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <ctime>

#include <iostream>
#include <string>

#include <gtest/gtest.h>

Expand Down Expand Up @@ -41,6 +40,7 @@ class test_expressions : public db_catalog_test_base_t
employee_t simone, dax, bill, laurentiu, wayne, yiwen, mihir, tobin;
phone_t landline, mobile;
customer_t hooli, pied_piper;
internet_contract_t simone_att, bill_comcast;
const vector<int32_t> hooli_sales{3, 1, 4, 1, 5};
const vector<int32_t> pied_piper_sales{1, 1, 2, 3, 5};

Expand Down Expand Up @@ -74,6 +74,9 @@ class test_expressions : public db_catalog_test_base_t
hooli = create_customer("Hooli", hooli_sales);
pied_piper = create_customer("Pied Piper", pied_piper_sales);

simone_att = create_internet_contract("AT&T", kissimmee, simone);
bill_comcast = create_internet_contract("Comcast", tyngsborough, bill);

commit_transaction();
}

Expand Down Expand Up @@ -117,6 +120,16 @@ class test_expressions : public db_catalog_test_base_t
return customer_t::get(customer_t::insert_row(name, sales_by_quarter));
}

internet_contract_t create_internet_contract(const char* provider, address_t address, employee_t owner)
{
internet_contract_t internet_contract = internet_contract_t::get(
internet_contract_t::insert_row(provider));

address.internet_contract().connect(internet_contract);
owner.internet_contract().connect(internet_contract);
return internet_contract;
}

/**
* Return the given date in milliseconds since epoch.
*/
Expand Down Expand Up @@ -545,3 +558,18 @@ TEST_F(test_expressions, array)
return c.sales_by_quarter()[0] == -1;
}));
}

TEST_F(test_expressions, one_to_one)
{
auto_transaction_t txn;

assert_contains(
employee_t::list()
.where(employee_expr::internet_contract == simone_att),
simone);

assert_contains(
internet_contract_t::list()
.where(internet_contract_expr::owner == bill),
bill_comcast);
}
7 changes: 3 additions & 4 deletions production/schemas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ file(GLOB SCHEMA_FILES

# Copies the .dll files into a known location in the Cmake build folder
# to allow schema_loader to find them.
file(
COPY ${SCHEMA_FILES}
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/"
)
foreach(SCHEMA_FILE ${SCHEMA_FILES})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the bug that was fixed? From the title, it sounded like the bug was in the code, not in the build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, updated the title.

configure_file(${SCHEMA_FILE} ${CMAKE_CURRENT_BINARY_DIR})
endforeach()

add_subdirectory(loader)
add_subdirectory(system)
Expand Down
14 changes: 14 additions & 0 deletions production/schemas/test/addr_book/addr_book.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ create relationship if not exists phone_owner (
phone.owner -> employee
);

create table if not exists internet_contract (
provider string
);

create relationship if not exists internet_contract_address (
address.internet_contract -> internet_contract,
internet_contract.address -> address
);

create relationship if not exists internet_contract_owner (
employee.internet_contract -> internet_contract,
internet_contract.owner -> employee
);

create table if not exists customer (
name string,
sales_by_quarter int32[]
Expand Down