-
Notifications
You must be signed in to change notification settings - Fork 165
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
Support querying with @type on nested collections #7288
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4812,6 +4812,8 @@ TEST(Parser_TypeOfValue) | |
} | ||
std::string bin_data("String2Binary"); | ||
table->get_object(15).set(col_any, Mixed()); | ||
table->get_object(17).set_collection(col_any, CollectionType::Dictionary); | ||
table->get_object(19).set<Mixed>(col_any, table->begin()->get_link()); | ||
table->get_object(75).set(col_any, Mixed(75.)); | ||
table->get_object(28).set(col_any, Mixed(BinaryData(bin_data))); | ||
nb_strings--; | ||
|
@@ -4837,7 +4839,8 @@ TEST(Parser_TypeOfValue) | |
++it; | ||
} | ||
} | ||
size_t nb_ints = 71; | ||
size_t nb_ints = 69; | ||
size_t nb_numerics = nb_ints + 3; | ||
verify_query(test_context, table, "mixed.@type == 'string'", nb_strings); | ||
verify_query(test_context, table, "mixed.@type == 'double'", 2); | ||
verify_query(test_context, table, "mixed.@type == 'float'", 0); | ||
|
@@ -4861,26 +4864,28 @@ TEST(Parser_TypeOfValue) | |
verify_query(test_context, table, "mixed.@type == 'char'", nb_ints); | ||
verify_query(test_context, table, "mixed.@type == 'timestamp'", 0); | ||
verify_query(test_context, table, "mixed.@type == 'datetimeoffset'", 0); | ||
verify_query(test_context, table, "mixed.@type == 'object'", 0); | ||
verify_query(test_context, table, "mixed.@type == 'object'", 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you add a test for "objectlink" as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
verify_query(test_context, table, "mixed.@type == 'objectlink'", 1); | ||
|
||
verify_query(test_context, table, | ||
"mixed.@type == 'binary' || mixed.@type == 'DECIMAL' || mixed.@type == 'Double'", 4); | ||
verify_query(test_context, table, "mixed.@type == 'null'", 1); | ||
verify_query(test_context, table, "mixed.@type == 'numeric'", table->size() - nb_strings - 2); | ||
verify_query( | ||
test_context, table, | ||
"mixed.@type == 'numeric' || mixed.@type == 'string' || mixed.@type == 'binary' || mixed.@type == 'null'", | ||
table->size()); | ||
verify_query(test_context, table, "mixed.@type == 'numeric'", nb_numerics); | ||
verify_query(test_context, table, | ||
"mixed.@type == 'numeric' || mixed.@type == 'string' || mixed.@type == 'objectlink' || mixed.@type " | ||
"== 'binary' || mixed.@type == " | ||
"'object' || mixed.@type == 'null'", | ||
table->size()); | ||
verify_query(test_context, table, "mixed.@type == mixed.@type", table->size()); | ||
verify_query(test_context, origin, "link.mixed.@type == 'numeric' || link.mixed.@type == 'string'", | ||
origin->size()); | ||
verify_query(test_context, origin, "links.mixed.@type == 'numeric' || links.mixed.@type == 'string'", | ||
origin->size()); | ||
verify_query(test_context, origin, "ANY links.mixed.@type IN ANY {'numeric', 'string'}", origin->size()); | ||
|
||
verify_query(test_context, table, "mixed.@type == int.@type", table->size() - nb_strings - 5); | ||
verify_query(test_context, table, "mixed.@type == int.@type", nb_ints); | ||
verify_query(test_context, origin, "link.@type == link.mixed.@type", 0); | ||
verify_query(test_context, origin, "links.@type == links.mixed.@type", 0); | ||
verify_query(test_context, origin, "links.@type == links.mixed.@type", 1); // Object 19 | ||
|
||
verify_query(test_context, table, "mixed > 50", int_over_50); | ||
verify_query(test_context, table, "mixed > 50 && mixed.@type == 'double'", 1); | ||
|
@@ -4934,10 +4939,11 @@ TEST(Parser_TypeOfValue) | |
CHECK_THROW_EX(verify_query(test_context, table, "int.@type == 'int'", 1), query_parser::InvalidQueryError, | ||
std::string(e.what()).find("Comparison between two constants is not supported") != | ||
std::string::npos); | ||
CHECK_THROW_EX(verify_query(test_context, origin, "link.@type == 'object'", 1), query_parser::InvalidQueryError, | ||
CHECK(std::string(e.what()).find( | ||
"Comparison between two constants is not supported ('\"object\"' and '\"object\"')") != | ||
std::string::npos)); | ||
CHECK_THROW_EX( | ||
verify_query(test_context, origin, "link.@type == 'objectlink'", 1), query_parser::InvalidQueryError, | ||
CHECK(std::string(e.what()).find( | ||
"Comparison between two constants is not supported ('\"objectlink\"' and '\"objectlink\"')") != | ||
std::string::npos)); | ||
CHECK_THROW_EX(verify_query(test_context, table, "mixed.@type =[c] 'string'", 1), query_parser::InvalidQueryError, | ||
CHECK_EQUAL(std::string(e.what()), "Unsupported comparison operator '=[c]' against type '@type', " | ||
"right side must be a string or binary type")); | ||
|
@@ -5284,6 +5290,10 @@ TEST(Parser_NestedMixedDictionaryList) | |
snake->insert("age", 20); | ||
} | ||
|
||
Obj george = persons->create_object_with_primary_key("George"); | ||
george.set(col_self, george.get_key()); | ||
george.set_collection(col, CollectionType::List); | ||
|
||
auto q = persons->column<Mixed>(col).path({"instruments", 0, "strings"}) == 6; | ||
CHECK_EQUAL(q.count(), 1); | ||
|
||
|
@@ -5300,6 +5310,9 @@ TEST(Parser_NestedMixedDictionaryList) | |
verify_query(test_context, persons, "properties.@keys == 'tickets'", 1); | ||
verify_query(test_context, persons, "properties.@size == 3", 1); | ||
verify_query(test_context, persons, "properties.instruments.@size == 2", 1); | ||
verify_query(test_context, persons, "properties.@type == 'object'", 2); | ||
verify_query(test_context, persons, "properties.@type == 'array'", 1); | ||
verify_query(test_context, persons, "properties.@type == 'collection'", 3); | ||
} | ||
|
||
TEST(Parser_NestedDictionaryDeep) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When doing the query string in the JS SDK, this will likely be ambiguous since our
"object"
data type means "Realm object".