-
Notifications
You must be signed in to change notification settings - Fork 171
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
Query serialisation part 3 #2989
Conversation
Check the performance result here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2989/1/Performance_Report |
Does this also cover the simplified shortcut syntax ( |
Currently only the full subquery syntax is supported here |
Serialization of Cocoa queries that use No bindings support the equivalent of
|
|
For JS queries we could potentially support these shortcuts without native core query support by getting the parser to make the following mappings:
|
Yes, I think it is worth supporting them all, even if the initial mapping means that the performance is less than what we could get with a native implementation. |
Ah, yes. But again, serializing Please also keep in mind that adding support for parsing additional query features is outside of the scope of the current query serialization work. It needs to be evaluated and prioritized against other work. |
Codecov Report
@@ Coverage Diff @@
## master #2989 +/- ##
==========================================
+ Coverage 93.17% 93.22% +0.05%
==========================================
Files 266 270 +4
Lines 77914 78627 +713
==========================================
+ Hits 72594 73302 +708
- Misses 5320 5325 +5
Continue to review full report at Codecov.
|
Check the performance result here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2989/2/Performance_Report |
Check the performance result here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2989/5/Performance_Report |
Check the performance result here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2989/6/Performance_Report |
Check the performance result here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2989/7/Performance_Report |
src/realm/util/serializer.cpp
Outdated
std::string guess = guess_prefix + add_char; | ||
bool found_duplicate = false; | ||
for (size_t i = 0; i < subquery_prefix_list.size(); ++i) { | ||
if (guess.compare(subquery_prefix_list[i]) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think guess == subquery_prefix_list[i]
is more well known and thus easier to read (I had to look-up how compare() worked to check if there was any special reason why it was called)
} | ||
}; | ||
|
||
while (true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing assert or other handling if the column is never found (should be there even if it by design can't happen)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By design it will loop endlessly until a unique name is found. I assume there must be a finite number of column names to search through and a finite number of subquery nestings with different variable names. In practice though it'll find a match on the first pass. Would you suggest putting an upper limit on the number of loop iterations we allow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh okay, I misread the code and thought it would loop until it had somehow found a specific column :) no worries then
src/realm/util/serializer.cpp
Outdated
char add_char = start_char; | ||
|
||
auto next_guess = [&]() { | ||
add_char = (((add_char + 1) - 'a') % 26) + 'a'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
% ('z' - 'a' + 1) is easier to read I think
template <typename RetType> | ||
struct SubqueryGetter<RetType, | ||
typename std::enable_if_t< | ||
std::is_same<RetType, Int>::value || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have realm::is_any
:)
} else { | ||
list_property_name = pre_link_table->get_column_name(pe.get_dest_ndx()); | ||
} | ||
precondition(pe.get_dest_type() == type_LinkList || pe.dest_type_is_backlink(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this precondition
macro is defined in a .hpp file (parser_utils.hpp), so it must be prefixed with REALM_ in order not to pollute users´ name spaces
src/realm/parser/keypath_mapping.cpp
Outdated
|
||
// This may be premature optimisation, but it'll be super fast and it doesn't | ||
// bother dragging in anything locale specific for case insensitive comparisons. | ||
bool is_backlinks_prefix(std::string s) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's super fast, maybe also pass a reference instead of a value :D
src/realm/parser/keypath_mapping.hpp
Outdated
static Table* table_getter(TableRef table, const std::vector<KeyPathElement>& links); | ||
protected: | ||
bool m_allow_backlinks; | ||
std::map<std::pair<ConstTableRef, std::string>, std::string> m_mapping; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an unordered_map might be alot faster (and has same API)
src/realm/parser/keypath_mapping.cpp
Outdated
|
||
void KeyPathMapping::add_mapping(ConstTableRef table, std::string name, std::string alias) | ||
{ | ||
m_mapping[{table, name}] = alias; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error handling if the table already exists?
Check the performance result here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2989/8/Performance_Report |
Check the performance result here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2989/9/Performance_Report |
Check the performance result here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2989/10/Performance_Report |
Check the performance result here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2989/11/Performance_Report |
This adds support for subquery expressions and backlinks to the query serialiser and parser.
It also sets up the architecture for key path aliasing which could be useful for querying over named backlinks or when bindings allow referencing properties by other user defined names.
This is part of #2943