Skip to content

Commit

Permalink
Fix support for Timestamp
Browse files Browse the repository at this point in the history
Change-Id: I3354eebcd03e4578da92ce9a137bb13e2ea48579
  • Loading branch information
jedelbo committed Oct 22, 2019
1 parent 65b6de8 commit 5b81529
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/realm/column_binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class BinaryColumn : public ColumnBaseSimple {
void find_all(IntegerColumn&, BinaryData, size_t, size_t) const
{
// Dummy implementation
REALM_ASSERT(false);
}


Expand Down
8 changes: 6 additions & 2 deletions src/realm/column_timestamp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,13 @@ class TimestampColumn : public ColumnBaseSimple {
return npos;
}

void find_all(IntegerColumn&, Timestamp, size_t, size_t) const
void find_all(IntegerColumn& result, Timestamp value, size_t begin, size_t end) const
{
// Dummy implementation
if (m_search_index && begin == 0 && end == npos) {
m_search_index->find_all(result, value); // Throws
return;
}
REALM_ASSERT(false);
}

typedef Timestamp value_type;
Expand Down
18 changes: 14 additions & 4 deletions test/test_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12224,7 +12224,9 @@ TEST(Query_LinksWithIndex)

TableRef target = g.add_table("target");
auto col_value = target->add_column(type_String, "value");
auto col_date = target->add_column(type_Timestamp, "date");
target->add_search_index(col_value);
target->add_search_index(col_date);

TableRef foo = g.add_table("foo");
auto col_foo = foo->add_column_link(type_LinkList, "linklist", *target);
Expand All @@ -12240,8 +12242,13 @@ TEST(Query_LinksWithIndex)
auto col_linklist = origin->add_column_link(type_LinkList, "linklist", *middle);

std::string strings[] = {"Copenhagen", "Aarhus", "Odense", "Aalborg", "Faaborg"};
auto now = std::chrono::system_clock::now();
std::chrono::seconds d{0};
for (auto& str : strings) {
target->set_string(col_value, target->add_empty_row(), str);
auto ndx = target->add_empty_row();
target->set_string(col_value, ndx, str);
target->set_timestamp(col_date, ndx, Timestamp(now + d));
d = d + std::chrono::seconds{1};
}

middle->add_empty_row(5);
Expand All @@ -12259,7 +12266,7 @@ TEST(Query_LinksWithIndex)
origin->get_linklist(col_linklist, 1)->add(2);
origin->get_linklist(col_linklist, 2)->add(4);
origin->get_linklist(col_linklist, 3)->add(3);
origin->get_linklist(col_linklist, 4)->add(4);
origin->get_linklist(col_linklist, 4)->add(0);

Query q = origin->link(col_linklist).link(col_link).column<String>(col_value) == "Odense";
CHECK_EQUAL(q.find(), 0);
Expand All @@ -12275,13 +12282,16 @@ TEST(Query_LinksWithIndex)

Query q1 =
origin->link(col_linklist).link(col_link).backlink(*foo, col_foo).column<String>(col_location) == "Fyn";
CHECK_EQUAL(q.find(), 0);
CHECK_EQUAL(q1.find(), 0);
Query q2 = origin->link(col_linklist).link(col_link).backlink(*foo, col_foo).column<Int>(col_score) == 5;
CHECK_EQUAL(q.find(), 0);
CHECK_EQUAL(q2.find(), 0);

// Make sure that changes in the table are reflected in the query result
middle->set_link(col_link, 3, 1);
CHECK_EQUAL(q.find(), 1);

q = origin->link(col_linklist).link(col_link).column<Timestamp>(col_date) == Timestamp(now);
CHECK_EQUAL(q.find(), 4);
}


Expand Down

0 comments on commit 5b81529

Please sign in to comment.