-
Notifications
You must be signed in to change notification settings - Fork 13
schema - optional with defaults - improved behaviour (not injecting the default in the index) #246
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
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,7 +208,13 @@ std::optional<Key> Rule::findMatchingKey(const eckit::StringList& values) const | |
| return {}; | ||
| } | ||
|
|
||
| ASSERT(values.size() >= predicates_.size()); | ||
| size_t numPred = predicates_.size(); | ||
| for (const auto& p : predicates_) { | ||
| if (p->optional()) { | ||
| numPred--; | ||
| } | ||
| } | ||
| ASSERT(values.size() >= numPred); | ||
|
|
||
| TypedKey key(registry_); | ||
|
|
||
|
|
@@ -282,7 +288,6 @@ std::vector<Key> Rule::findMatchingKeys(const metkit::mars::MarsRequest& request | |
| } | ||
| } | ||
|
|
||
| /// @todo activate this | ||
| graph.canonicalise(registry_); | ||
|
|
||
| return graph.makeKeys(); | ||
|
|
@@ -295,13 +300,12 @@ std::vector<Key> Rule::findMatchingKeys(const metkit::mars::MarsRequest& request | |
| for (const auto& pred : predicates_) { | ||
|
|
||
| const auto& keyword = pred->keyword(); | ||
| const auto& type = registry_.lookupType(keyword); | ||
|
|
||
|
|
||
| const auto& values = pred->values(request); | ||
| auto values = pred->values(request); | ||
|
|
||
| /// @note do we want to allow empty values? | ||
| // if (values.empty() && pred->optional()) { values.push_back(pred->defaultValue()); } | ||
| /// if the request does not have the keyword, but the predicate is optional, then use the default value | ||
| if (values.empty() && pred->optional()) { | ||
| values.push_back(pred->defaultValue()); | ||
| } | ||
|
|
||
| auto& node = graph.push(keyword); | ||
|
|
||
|
|
@@ -311,6 +315,7 @@ std::vector<Key> Rule::findMatchingKeys(const metkit::mars::MarsRequest& request | |
| } | ||
| } | ||
|
|
||
| /// if there are no matching values for this predicate, then there are no matching keys for the rule | ||
| if (node.empty()) { | ||
| return {}; | ||
| } | ||
|
Comment on lines
+296
to
321
|
||
|
|
@@ -328,46 +333,43 @@ std::vector<Key> Rule::findMatchingKeys(const metkit::mars::MarsRequest& request | |
| for (const auto& pred : predicates_) { | ||
|
|
||
| const auto& keyword = pred->keyword(); | ||
| const auto& type = registry_.lookupType(keyword); | ||
|
|
||
| // performance optimization to avoid calling values() on visitor | ||
| if (!pred->optional() && request.countValues(keyword) == 0) { | ||
| return {}; | ||
| } | ||
|
|
||
| eckit::StringList values; | ||
| visitor.values(request, keyword, registry_, values); | ||
|
|
||
| if (values.empty() && pred->optional()) { | ||
| values.push_back(pred->defaultValue()); | ||
| if (request.countValues(keyword) == 0) { | ||
| if (pred->optional()) { | ||
| values.push_back(pred->defaultValue()); | ||
| if (!pred->defaultValue().empty()) { | ||
| values.push_back(""); | ||
| } | ||
| } | ||
| else { | ||
| return {}; | ||
| } | ||
| } | ||
| else { | ||
| visitor.values(request, keyword, registry_, values); | ||
| } | ||
|
|
||
| auto& node = graph.push(keyword); | ||
|
|
||
| for (const auto& value : values) { | ||
| if (pred->match(value)) { | ||
| node.emplace_back(value); | ||
| } | ||
| } | ||
|
|
||
| if (node.empty()) { | ||
| return {}; | ||
| if (pred->optional()) { | ||
| node.emplace_back(""); | ||
| } | ||
| else { | ||
| return {}; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| graph.canonicalise(registry_); | ||
|
|
||
| auto out = graph.makeKeys(); | ||
|
|
||
| LOG_DEBUG_LIB(LibFdb5) << "findMatchingKeys " << request << " ==> "; | ||
| std::string sep; | ||
| for (const auto& k : out) { | ||
| LOG_DEBUG_LIB(LibFdb5) << sep << k; | ||
| sep = " | "; | ||
| } | ||
| LOG_DEBUG_LIB(LibFdb5) << std::endl; | ||
|
|
||
| return out; | ||
| return graph.makeKeys(); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------------------------------------------------- | ||
|
|
@@ -399,7 +401,13 @@ bool Rule::tryFill(Key& key, const eckit::StringList& values) const { | |
| // --> HACK. | ||
| // --> Stick a plaster over the symptom. | ||
|
|
||
| ASSERT(values.size() >= predicates_.size()); // Should be equal, except for quantile (FDB-103) | ||
| size_t numPred = predicates_.size(); | ||
| for (const auto& p : predicates_) { | ||
| if (p->optional()) { | ||
| numPred--; | ||
| } | ||
| } | ||
| ASSERT(values.size() >= numPred); // Should be equal, except for quantile (FDB-103) | ||
| ASSERT(values.size() <= predicates_.size() + 1); | ||
|
|
||
| auto it_value = values.begin(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,7 +35,7 @@ int fdb_request_add1(fdb_request_t* req, const char* param, const char* value) { | |||||||||||||||||
|
|
||||||||||||||||||
| void key_compare(const std::vector<fdb5::Key>& keys, fdb_listiterator_t* it, bool checkLevel = true) { | ||||||||||||||||||
| const char* k; | ||||||||||||||||||
| const char* v; | ||||||||||||||||||
| const char* v = nullptr; | ||||||||||||||||||
| size_t l; | ||||||||||||||||||
| int err; | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -47,7 +47,12 @@ void key_compare(const std::vector<fdb5::Key>& keys, fdb_listiterator_t* it, boo | |||||||||||||||||
| size_t level = 0; | ||||||||||||||||||
| for (const auto& key : keys) { | ||||||||||||||||||
| for (const auto& k1 : key) { | ||||||||||||||||||
| int err = fdb_splitkey_next_metadata(sk, &k, &v, checkLevel ? &l : nullptr); | ||||||||||||||||||
| int err; | ||||||||||||||||||
| v = nullptr; | ||||||||||||||||||
| // skip empty values (optional metadata) | ||||||||||||||||||
| while (v == nullptr || strlen(v) == 0) { | ||||||||||||||||||
|
Comment on lines
+50
to
+53
|
||||||||||||||||||
| int err; | |
| v = nullptr; | |
| // skip empty values (optional metadata) | |
| while (v == nullptr || strlen(v) == 0) { | |
| int err = FDB_SUCCESS; | |
| v = nullptr; | |
| // skip empty values (optional metadata) | |
| while ((v == nullptr || strlen(v) == 0) && err == FDB_SUCCESS) { |
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.
fdb-patchhas been commented out from the list of built tools underHAVE_GRIB. If this is not intentional, it will remove the executable from builds/installs. If it is intentional, it would help to add a short comment explaining why the tool is being disabled (and ideally gate it behind an option) to avoid an unexpected feature regression.