Skip to content

Commit 3b74cb4

Browse files
committed
Add MQL query sceleton
1 parent c82be46 commit 3b74cb4

13 files changed

+511
-134
lines changed

src/realm/object-store/results.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <realm/object-store/schema.hpp>
2727
#include <realm/object-store/class.hpp>
2828
#include <realm/object-store/sectioned_results.hpp>
29-
29+
#include <realm/util/bson/bson.hpp>
3030
#include <realm/set.hpp>
3131

3232
#include <stdexcept>
@@ -56,6 +56,16 @@ Results::Results(SharedRealm r, Query q, DescriptorOrdering o)
5656
{
5757
}
5858

59+
Results::Results(SharedRealm r, ConstTableRef table, const bson::BsonDocument& document)
60+
: Results(r, table->query(document))
61+
{
62+
}
63+
64+
Results::Results(SharedRealm r, ConstTableRef table, const std::string& document)
65+
: Results(r, table->query(static_cast<bson::BsonDocument>(bson::parse(document))))
66+
{
67+
}
68+
5969
Results::Results(const Class& cls)
6070
: Results(cls.get_realm(), cls.get_table())
6171
{

src/realm/object-store/results.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class Results {
5151
Results();
5252
Results(const Class&);
5353
Results(std::shared_ptr<Realm> r, ConstTableRef table);
54+
Results(std::shared_ptr<Realm> r, ConstTableRef, const bson::BsonDocument& document);
55+
Results(std::shared_ptr<Realm> r, ConstTableRef, const std::string& document);
5456
Results(std::shared_ptr<Realm> r, Query q, DescriptorOrdering o = {});
5557
Results(std::shared_ptr<Realm> r, TableView tv, DescriptorOrdering o = {});
5658
Results(std::shared_ptr<Realm> r, const Obj& obj, TableKey src_table, ColKey src_col_key)
@@ -152,6 +154,9 @@ class Results {
152154

153155
// Create a new Results by further filtering or sorting this Results
154156
Results filter(Query&& q) const REQUIRES(!m_mutex);
157+
Results find(const bson::BsonDocument& document) const REQUIRES(!m_mutex);
158+
Results find(const std::string& document) const REQUIRES(!m_mutex);
159+
155160
// Create a new Results by sorting this Result.
156161
Results sort(SortDescriptor&& sort) const REQUIRES(!m_mutex);
157162
// Create a new Results by sorting this Result based on the specified key paths.

src/realm/parser/CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ if(NOT REALM_CORE_SUBMODULE_BUILD)
3131
endif()
3232

3333
set(REALM_PARSER_SOURCES
34-
driver.cpp
34+
query_ast.cpp
35+
query_bson.cpp
3536
keypath_mapping.cpp
3637
) # REALM_PARSER_SOURCES
3738

@@ -41,7 +42,7 @@ set(REALM_PARSER_GENERATED
4142
) # REALM_PARSER_SOURCES
4243

4344
set(REALM_PARSER_HEADERS
44-
driver.hpp
45+
query_ast.hpp
4546
keypath_mapping.hpp
4647
query_parser.hpp
4748
generated/query_bison.hpp

src/realm/parser/generated/query_bison.cpp

+51-51
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
// Unqualified %code blocks.
4545

46-
#include <realm/parser/driver.hpp>
46+
#include <realm/parser/query_ast.hpp>
4747
#include <realm/table.hpp>
4848
using namespace realm;
4949
using namespace realm::query_parser;
@@ -204,11 +204,6 @@ namespace yy {
204204
value.YY_MOVE_OR_COPY< CompareType > (YY_MOVE (that.value));
205205
break;
206206

207-
case symbol_kind::SYM_constant: // constant
208-
case symbol_kind::SYM_primary_key: // primary_key
209-
value.YY_MOVE_OR_COPY< ConstantNode* > (YY_MOVE (that.value));
210-
break;
211-
212207
case symbol_kind::SYM_distinct: // distinct
213208
case symbol_kind::SYM_distinct_param: // distinct_param
214209
case symbol_kind::SYM_sort: // sort
@@ -259,6 +254,11 @@ namespace yy {
259254
value.YY_MOVE_OR_COPY< QueryNode* > (YY_MOVE (that.value));
260255
break;
261256

257+
case symbol_kind::SYM_constant: // constant
258+
case symbol_kind::SYM_primary_key: // primary_key
259+
value.YY_MOVE_OR_COPY< StringConstantNode* > (YY_MOVE (that.value));
260+
break;
261+
262262
case symbol_kind::SYM_subquery: // subquery
263263
value.YY_MOVE_OR_COPY< SubqueryNode* > (YY_MOVE (that.value));
264264
break;
@@ -348,11 +348,6 @@ namespace yy {
348348
value.move< CompareType > (YY_MOVE (that.value));
349349
break;
350350

351-
case symbol_kind::SYM_constant: // constant
352-
case symbol_kind::SYM_primary_key: // primary_key
353-
value.move< ConstantNode* > (YY_MOVE (that.value));
354-
break;
355-
356351
case symbol_kind::SYM_distinct: // distinct
357352
case symbol_kind::SYM_distinct_param: // distinct_param
358353
case symbol_kind::SYM_sort: // sort
@@ -403,6 +398,11 @@ namespace yy {
403398
value.move< QueryNode* > (YY_MOVE (that.value));
404399
break;
405400

401+
case symbol_kind::SYM_constant: // constant
402+
case symbol_kind::SYM_primary_key: // primary_key
403+
value.move< StringConstantNode* > (YY_MOVE (that.value));
404+
break;
405+
406406
case symbol_kind::SYM_subquery: // subquery
407407
value.move< SubqueryNode* > (YY_MOVE (that.value));
408408
break;
@@ -492,11 +492,6 @@ namespace yy {
492492
value.copy< CompareType > (that.value);
493493
break;
494494

495-
case symbol_kind::SYM_constant: // constant
496-
case symbol_kind::SYM_primary_key: // primary_key
497-
value.copy< ConstantNode* > (that.value);
498-
break;
499-
500495
case symbol_kind::SYM_distinct: // distinct
501496
case symbol_kind::SYM_distinct_param: // distinct_param
502497
case symbol_kind::SYM_sort: // sort
@@ -547,6 +542,11 @@ namespace yy {
547542
value.copy< QueryNode* > (that.value);
548543
break;
549544

545+
case symbol_kind::SYM_constant: // constant
546+
case symbol_kind::SYM_primary_key: // primary_key
547+
value.copy< StringConstantNode* > (that.value);
548+
break;
549+
550550
case symbol_kind::SYM_subquery: // subquery
551551
value.copy< SubqueryNode* > (that.value);
552552
break;
@@ -634,11 +634,6 @@ namespace yy {
634634
value.move< CompareType > (that.value);
635635
break;
636636

637-
case symbol_kind::SYM_constant: // constant
638-
case symbol_kind::SYM_primary_key: // primary_key
639-
value.move< ConstantNode* > (that.value);
640-
break;
641-
642637
case symbol_kind::SYM_distinct: // distinct
643638
case symbol_kind::SYM_distinct_param: // distinct_param
644639
case symbol_kind::SYM_sort: // sort
@@ -689,6 +684,11 @@ namespace yy {
689684
value.move< QueryNode* > (that.value);
690685
break;
691686

687+
case symbol_kind::SYM_constant: // constant
688+
case symbol_kind::SYM_primary_key: // primary_key
689+
value.move< StringConstantNode* > (that.value);
690+
break;
691+
692692
case symbol_kind::SYM_subquery: // subquery
693693
value.move< SubqueryNode* > (that.value);
694694
break;
@@ -1175,11 +1175,11 @@ namespace yy {
11751175
break;
11761176

11771177
case symbol_kind::SYM_constant: // constant
1178-
{ yyo << yysym.value.template as < ConstantNode* > (); }
1178+
{ yyo << yysym.value.template as < StringConstantNode* > (); }
11791179
break;
11801180

11811181
case symbol_kind::SYM_primary_key: // primary_key
1182-
{ yyo << yysym.value.template as < ConstantNode* > (); }
1182+
{ yyo << yysym.value.template as < StringConstantNode* > (); }
11831183
break;
11841184

11851185
case symbol_kind::SYM_boolexpr: // boolexpr
@@ -1456,11 +1456,6 @@ namespace yy {
14561456
yylhs.value.emplace< CompareType > ();
14571457
break;
14581458

1459-
case symbol_kind::SYM_constant: // constant
1460-
case symbol_kind::SYM_primary_key: // primary_key
1461-
yylhs.value.emplace< ConstantNode* > ();
1462-
break;
1463-
14641459
case symbol_kind::SYM_distinct: // distinct
14651460
case symbol_kind::SYM_distinct_param: // distinct_param
14661461
case symbol_kind::SYM_sort: // sort
@@ -1511,6 +1506,11 @@ namespace yy {
15111506
yylhs.value.emplace< QueryNode* > ();
15121507
break;
15131508

1509+
case symbol_kind::SYM_constant: // constant
1510+
case symbol_kind::SYM_primary_key: // primary_key
1511+
yylhs.value.emplace< StringConstantNode* > ();
1512+
break;
1513+
15141514
case symbol_kind::SYM_subquery: // subquery
15151515
yylhs.value.emplace< SubqueryNode* > ();
15161516
break;
@@ -1686,7 +1686,7 @@ namespace yy {
16861686
break;
16871687

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

16921692
case 25: // value: prop
@@ -1848,95 +1848,95 @@ namespace yy {
18481848
break;
18491849

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

19421942
case 85: // boolexpr: "truepredicate"

0 commit comments

Comments
 (0)