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

Encode links in a way the server can understand #5835

Merged
merged 9 commits into from
Sep 15, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* If a SyncSession outlived the parent Realm and then was adopted by a new Realm for the same file, other processes would not get notified for sync writes on that file.
* Fix one cause of QoS inversion warnings when performing writes on the main thread on Apple platforms. Waiting for async notifications to be ready is now done in a QoS-aware ways.
* `Realm::refresh()` did not actually advance to the latest version in some cases. If there was a version newer than the current version which did not require blocking it would advance to that instead, contrary to the documented behavior.
* If you set a subscription on a link in flexible sync, the server would not know how to handle it ([#5409](https://github.com/realm/realm-core/issues/5409))
* Fixed `realm_query_parse_for_results` ignoring query for `query_result_t` passed as parameter ([#5841](https://github.com/realm/realm-core/pull/5841)).
* Fixed `realm_query_parse_for_list` ignoring existing query ([#5850](https://github.com/realm/realm-core/pull/5850)).

Expand Down
29 changes: 25 additions & 4 deletions src/realm/parser/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ std::unique_ptr<Subexpr> OperationNode::visit(ParserDriver* drv, DataType type)
}
}
if (!Mixed::is_numeric(left->get_type(), right->get_type())) {
util::serializer::SerialisationState state("");
util::serializer::SerialisationState state("", nullptr);
std::string op(&m_op, 1);
throw std::invalid_argument(util::format("Cannot perform '%1' operation on '%2' and '%3'", op,
left->description(state), right->description(state)));
Expand Down Expand Up @@ -490,8 +490,9 @@ Query EqualityNode::visit(ParserDriver* drv)
}
else if (left_type == type_Link) {
auto link_column = dynamic_cast<const Columns<Link>*>(left.get());
if (link_column && link_column->link_map().get_nb_hops() == 1 && link_column->get_comparison_type() &&
*link_column->get_comparison_type() == ExpressionComparisonType::Any) {
if (link_column && link_column->link_map().get_nb_hops() == 1 &&
link_column->get_comparison_type().value_or(ExpressionComparisonType::Any) ==
ExpressionComparisonType::Any) {
// We can use equal/not_equal and get a LinksToNode based query
if (op == CompareNode::EQUAL) {
return drv->m_base_table->where().equal(link_column->link_map().get_first_column_key(), val);
Expand Down Expand Up @@ -939,6 +940,26 @@ std::unique_ptr<Subexpr> ConstantNode::visit(ParserDriver* drv, DataType hint)
{
std::unique_ptr<Subexpr> ret;
std::string explain_value_message = text;
if (target_table.length()) {
const Group* g = drv->m_base_table->get_parent_group();
TableKey table_key;
ObjKey obj_key;
auto table = g->get_table(target_table);
if (!table) {
// Perhaps class prefix is missing
Group::TableNameBuffer buffer;
table = g->get_table(Group::class_name_to_table_name(target_table, buffer));
}
if (!table) {
throw InvalidQueryError(util::format("Unknown object type '%1'", target_table));
}
table_key = table->get_key();
target_table = "";
auto pk_val_node = visit(drv, hint); // call recursively
auto pk_val = pk_val_node->get_mixed();
obj_key = table->find_primary_key(pk_val);
return std::make_unique<Value<ObjLink>>(ObjLink(table_key, ObjKey(obj_key)));
}
switch (type) {
case Type::NUMBER: {
if (hint == type_Decimal) {
Expand Down Expand Up @@ -1403,7 +1424,7 @@ static void verify_conditions(Subexpr* left, Subexpr* right, util::serializer::S
}

ParserDriver::ParserDriver(TableRef t, Arguments& args, const query_parser::KeyPathMapping& mapping)
: m_serializer_state(mapping.get_backlink_class_prefix())
: m_serializer_state(mapping.get_backlink_class_prefix(), nullptr)
, m_base_table(t)
, m_args(args)
, m_mapping(mapping)
Expand Down
5 changes: 5 additions & 0 deletions src/realm/parser/driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,13 @@ class ConstantNode : public ParserNode {
, m_comp_type(comp_type)
{
}
void add_table(std::string table_name)
{
target_table = table_name.substr(1, table_name.size() - 2);
}
std::unique_ptr<Subexpr> visit(ParserDriver*, DataType);
util::Optional<ExpressionComparisonType> m_comp_type;
std::string target_table;
};

class ListNode : public ParserNode {
Expand Down
Loading