Skip to content

Commit

Permalink
Add MQL query sceleton
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed Nov 13, 2023
1 parent c82be46 commit 554d7bc
Show file tree
Hide file tree
Showing 13 changed files with 531 additions and 134 deletions.
12 changes: 11 additions & 1 deletion src/realm/object-store/results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <realm/object-store/schema.hpp>
#include <realm/object-store/class.hpp>
#include <realm/object-store/sectioned_results.hpp>

#include <realm/util/bson/bson.hpp>
#include <realm/set.hpp>

#include <stdexcept>
Expand Down Expand Up @@ -56,6 +56,16 @@ Results::Results(SharedRealm r, Query q, DescriptorOrdering o)
{
}

Results::Results(SharedRealm r, ConstTableRef table, const bson::BsonDocument& document)
: Results(r, table->query(document))
{
}

Results::Results(SharedRealm r, ConstTableRef table, const std::string& document)
: Results(r, table->query(static_cast<bson::BsonDocument>(bson::parse(document))))
{
}

Results::Results(const Class& cls)
: Results(cls.get_realm(), cls.get_table())
{
Expand Down
5 changes: 5 additions & 0 deletions src/realm/object-store/results.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Results {
Results();
Results(const Class&);
Results(std::shared_ptr<Realm> r, ConstTableRef table);
Results(std::shared_ptr<Realm> r, ConstTableRef, const bson::BsonDocument& document);
Results(std::shared_ptr<Realm> r, ConstTableRef, const std::string& document);
Results(std::shared_ptr<Realm> r, Query q, DescriptorOrdering o = {});
Results(std::shared_ptr<Realm> r, TableView tv, DescriptorOrdering o = {});
Results(std::shared_ptr<Realm> r, const Obj& obj, TableKey src_table, ColKey src_col_key)
Expand Down Expand Up @@ -152,6 +154,9 @@ class Results {

// Create a new Results by further filtering or sorting this Results
Results filter(Query&& q) const REQUIRES(!m_mutex);
Results find(const bson::BsonDocument& document) const REQUIRES(!m_mutex);
Results find(const std::string& document) const REQUIRES(!m_mutex);

// Create a new Results by sorting this Result.
Results sort(SortDescriptor&& sort) const REQUIRES(!m_mutex);
// Create a new Results by sorting this Result based on the specified key paths.
Expand Down
5 changes: 3 additions & 2 deletions src/realm/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ if(NOT REALM_CORE_SUBMODULE_BUILD)
endif()

set(REALM_PARSER_SOURCES
driver.cpp
query_ast.cpp
query_bson.cpp
keypath_mapping.cpp
) # REALM_PARSER_SOURCES

Expand All @@ -41,7 +42,7 @@ set(REALM_PARSER_GENERATED
) # REALM_PARSER_SOURCES

set(REALM_PARSER_HEADERS
driver.hpp
query_ast.hpp
keypath_mapping.hpp
query_parser.hpp
generated/query_bison.hpp
Expand Down
102 changes: 51 additions & 51 deletions src/realm/parser/generated/query_bison.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

// Unqualified %code blocks.

#include <realm/parser/driver.hpp>
#include <realm/parser/query_ast.hpp>
#include <realm/table.hpp>
using namespace realm;
using namespace realm::query_parser;
Expand Down Expand Up @@ -204,11 +204,6 @@ namespace yy {
value.YY_MOVE_OR_COPY< CompareType > (YY_MOVE (that.value));
break;

case symbol_kind::SYM_constant: // constant
case symbol_kind::SYM_primary_key: // primary_key
value.YY_MOVE_OR_COPY< ConstantNode* > (YY_MOVE (that.value));
break;

case symbol_kind::SYM_distinct: // distinct
case symbol_kind::SYM_distinct_param: // distinct_param
case symbol_kind::SYM_sort: // sort
Expand Down Expand Up @@ -259,6 +254,11 @@ namespace yy {
value.YY_MOVE_OR_COPY< QueryNode* > (YY_MOVE (that.value));
break;

case symbol_kind::SYM_constant: // constant
case symbol_kind::SYM_primary_key: // primary_key
value.YY_MOVE_OR_COPY< StringConstantNode* > (YY_MOVE (that.value));
break;

case symbol_kind::SYM_subquery: // subquery
value.YY_MOVE_OR_COPY< SubqueryNode* > (YY_MOVE (that.value));
break;
Expand Down Expand Up @@ -348,11 +348,6 @@ namespace yy {
value.move< CompareType > (YY_MOVE (that.value));
break;

case symbol_kind::SYM_constant: // constant
case symbol_kind::SYM_primary_key: // primary_key
value.move< ConstantNode* > (YY_MOVE (that.value));
break;

case symbol_kind::SYM_distinct: // distinct
case symbol_kind::SYM_distinct_param: // distinct_param
case symbol_kind::SYM_sort: // sort
Expand Down Expand Up @@ -403,6 +398,11 @@ namespace yy {
value.move< QueryNode* > (YY_MOVE (that.value));
break;

case symbol_kind::SYM_constant: // constant
case symbol_kind::SYM_primary_key: // primary_key
value.move< StringConstantNode* > (YY_MOVE (that.value));
break;

case symbol_kind::SYM_subquery: // subquery
value.move< SubqueryNode* > (YY_MOVE (that.value));
break;
Expand Down Expand Up @@ -492,11 +492,6 @@ namespace yy {
value.copy< CompareType > (that.value);
break;

case symbol_kind::SYM_constant: // constant
case symbol_kind::SYM_primary_key: // primary_key
value.copy< ConstantNode* > (that.value);
break;

case symbol_kind::SYM_distinct: // distinct
case symbol_kind::SYM_distinct_param: // distinct_param
case symbol_kind::SYM_sort: // sort
Expand Down Expand Up @@ -547,6 +542,11 @@ namespace yy {
value.copy< QueryNode* > (that.value);
break;

case symbol_kind::SYM_constant: // constant
case symbol_kind::SYM_primary_key: // primary_key
value.copy< StringConstantNode* > (that.value);
break;

case symbol_kind::SYM_subquery: // subquery
value.copy< SubqueryNode* > (that.value);
break;
Expand Down Expand Up @@ -634,11 +634,6 @@ namespace yy {
value.move< CompareType > (that.value);
break;

case symbol_kind::SYM_constant: // constant
case symbol_kind::SYM_primary_key: // primary_key
value.move< ConstantNode* > (that.value);
break;

case symbol_kind::SYM_distinct: // distinct
case symbol_kind::SYM_distinct_param: // distinct_param
case symbol_kind::SYM_sort: // sort
Expand Down Expand Up @@ -689,6 +684,11 @@ namespace yy {
value.move< QueryNode* > (that.value);
break;

case symbol_kind::SYM_constant: // constant
case symbol_kind::SYM_primary_key: // primary_key
value.move< StringConstantNode* > (that.value);
break;

case symbol_kind::SYM_subquery: // subquery
value.move< SubqueryNode* > (that.value);
break;
Expand Down Expand Up @@ -1175,11 +1175,11 @@ namespace yy {
break;

case symbol_kind::SYM_constant: // constant
{ yyo << yysym.value.template as < ConstantNode* > (); }
{ yyo << yysym.value.template as < StringConstantNode* > (); }
break;

case symbol_kind::SYM_primary_key: // primary_key
{ yyo << yysym.value.template as < ConstantNode* > (); }
{ yyo << yysym.value.template as < StringConstantNode* > (); }
break;

case symbol_kind::SYM_boolexpr: // boolexpr
Expand Down Expand Up @@ -1456,11 +1456,6 @@ namespace yy {
yylhs.value.emplace< CompareType > ();
break;

case symbol_kind::SYM_constant: // constant
case symbol_kind::SYM_primary_key: // primary_key
yylhs.value.emplace< ConstantNode* > ();
break;

case symbol_kind::SYM_distinct: // distinct
case symbol_kind::SYM_distinct_param: // distinct_param
case symbol_kind::SYM_sort: // sort
Expand Down Expand Up @@ -1511,6 +1506,11 @@ namespace yy {
yylhs.value.emplace< QueryNode* > ();
break;

case symbol_kind::SYM_constant: // constant
case symbol_kind::SYM_primary_key: // primary_key
yylhs.value.emplace< StringConstantNode* > ();
break;

case symbol_kind::SYM_subquery: // subquery
yylhs.value.emplace< SubqueryNode* > ();
break;
Expand Down Expand Up @@ -1686,7 +1686,7 @@ namespace yy {
break;

case 24: // value: constant
{ yylhs.value.as < ValueNode* > () = yystack_[0].value.as < ConstantNode* > ();}
{ yylhs.value.as < ValueNode* > () = yystack_[0].value.as < StringConstantNode* > ();}
break;

case 25: // value: prop
Expand Down Expand Up @@ -1848,95 +1848,95 @@ namespace yy {
break;

case 63: // list_content: constant
{ yylhs.value.as < ListNode* > () = drv.m_parse_nodes.create<ListNode>(yystack_[0].value.as < ConstantNode* > ()); }
{ yylhs.value.as < ListNode* > () = drv.m_parse_nodes.create<ListNode>(yystack_[0].value.as < StringConstantNode* > ()); }
break;

case 64: // list_content: %empty
{ yylhs.value.as < ListNode* > () = drv.m_parse_nodes.create<ListNode>(); }
break;

case 65: // list_content: list_content ',' constant
{ yystack_[2].value.as < ListNode* > ()->add_element(yystack_[0].value.as < ConstantNode* > ()); yylhs.value.as < ListNode* > () = yystack_[2].value.as < ListNode* > (); }
{ yystack_[2].value.as < ListNode* > ()->add_element(yystack_[0].value.as < StringConstantNode* > ()); yylhs.value.as < ListNode* > () = yystack_[2].value.as < ListNode* > (); }
break;

case 66: // constant: primary_key
{ yylhs.value.as < ConstantNode* > () = yystack_[0].value.as < ConstantNode* > (); }
{ yylhs.value.as < StringConstantNode* > () = yystack_[0].value.as < StringConstantNode* > (); }
break;

case 67: // constant: "infinity"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::INFINITY_VAL, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::INFINITY_VAL, yystack_[0].value.as < std::string > ()); }
break;

case 68: // constant: "NaN"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::NAN_VAL, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::NAN_VAL, yystack_[0].value.as < std::string > ()); }
break;

case 69: // constant: "base64"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::BASE64, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::BASE64, yystack_[0].value.as < std::string > ()); }
break;

case 70: // constant: "float"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::FLOAT, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::FLOAT, yystack_[0].value.as < std::string > ()); }
break;

case 71: // constant: "date"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::TIMESTAMP, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::TIMESTAMP, yystack_[0].value.as < std::string > ()); }
break;

case 72: // constant: "link"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::LINK, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::LINK, yystack_[0].value.as < std::string > ()); }
break;

case 73: // constant: "typed link"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::TYPED_LINK, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::TYPED_LINK, yystack_[0].value.as < std::string > ()); }
break;

case 74: // constant: "true"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::TRUE, ""); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::TRUE, ""); }
break;

case 75: // constant: "false"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::FALSE, ""); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::FALSE, ""); }
break;

case 76: // constant: "null"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::NULL_VAL, ""); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::NULL_VAL, ""); }
break;

case 77: // constant: "argument"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::ARG, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::ARG, yystack_[0].value.as < std::string > ()); }
break;

case 78: // constant: comp_type "argument"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ExpressionComparisonType(yystack_[1].value.as < int > ()), yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(ExpressionComparisonType(yystack_[1].value.as < int > ()), yystack_[0].value.as < std::string > ()); }
break;

case 79: // constant: "obj" '(' "string" ',' primary_key ')'
{
auto tmp = yystack_[1].value.as < ConstantNode* > ();
auto tmp = yystack_[1].value.as < StringConstantNode* > ();
tmp->add_table(yystack_[3].value.as < std::string > ());
yylhs.value.as < ConstantNode* > () = tmp;
yylhs.value.as < StringConstantNode* > () = tmp;
}
break;

case 80: // primary_key: "natural0"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::NUMBER, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::NUMBER, yystack_[0].value.as < std::string > ()); }
break;

case 81: // primary_key: "number"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::NUMBER, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::NUMBER, yystack_[0].value.as < std::string > ()); }
break;

case 82: // primary_key: "string"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::STRING, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::STRING, yystack_[0].value.as < std::string > ()); }
break;

case 83: // primary_key: "UUID"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::UUID_T, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::UUID_T, yystack_[0].value.as < std::string > ()); }
break;

case 84: // primary_key: "ObjectId"
{ yylhs.value.as < ConstantNode* > () = drv.m_parse_nodes.create<ConstantNode>(ConstantNode::OID, yystack_[0].value.as < std::string > ()); }
{ yylhs.value.as < StringConstantNode* > () = drv.m_parse_nodes.create<StringConstantNode>(StringConstantNode::OID, yystack_[0].value.as < std::string > ()); }
break;

case 85: // boolexpr: "truepredicate"
Expand Down
Loading

0 comments on commit 554d7bc

Please sign in to comment.