Skip to content

Feature/inheritance #85

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

Open
wants to merge 31 commits into
base: develop
Choose a base branch
from
Open

Feature/inheritance #85

wants to merge 31 commits into from

Conversation

danovaro
Copy link
Member

@danovaro danovaro commented May 14, 2025

This PR introduces:

  • strict validation is enforced by default
  • introduced aliases for the verbs
  • ability to specify subtypes and a context to asses which subtype has to be used (to handle tigge)
  • metadata validation order is based on the canonical axis order, so that metadata used to match the context are already validated
  • improved date parsing
  • many tests derived from the mars-client migration suite (@tbkr)

@codecov-commenter
Copy link

codecov-commenter commented May 14, 2025

Codecov Report

Attention: Patch coverage is 91.13924% with 56 lines in your changes missing coverage. Please review.

Project coverage is 66.95%. Comparing base (6b41e2f) to head (11d1550).

Files with missing lines Patch % Lines
src/metkit/mars/Type.cc 74.57% 15 Missing ⚠️
tests/test_expand.cc 93.61% 15 Missing ⚠️
src/metkit/mars/MarsLanguage.cc 87.27% 7 Missing ⚠️
src/metkit/mars/TypeDate.cc 83.33% 6 Missing ⚠️
tests/test_request.cc 88.00% 3 Missing ⚠️
src/metkit/mars/Type.h 92.59% 2 Missing ⚠️
src/metkit/mars/TypeEnum.cc 90.00% 2 Missing ⚠️
tests/test_date.cc 91.30% 2 Missing ⚠️
src/metkit/mars/MarsRequest.cc 95.23% 1 Missing ⚠️
src/metkit/mars/Parameter.cc 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #85      +/-   ##
===========================================
+ Coverage    65.90%   66.95%   +1.04%     
===========================================
  Files          122      123       +1     
  Lines         6983     7244     +261     
  Branches       667      707      +40     
===========================================
+ Hits          4602     4850     +248     
- Misses        2381     2394      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


//----------------------------------------------------------------------------------------------------------------------

ContextRule::ContextRule(const std::string& k) : key_(k) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its confusing that ContextRule is defined in Type.h and the ContextRule CTor in ContextRule.h


//----------------------------------------------------------------------------------------------------------------------

class Include : public ContextRule {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add one sentence explaining what this class represents.

std::set<std::string> vals_;
};

class Exclude : public ContextRule {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add one sentence explaining what this class represents.

std::set<std::string> vals_;
};

class Undef : public ContextRule {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add one sentence explaining what this class represents.

void print(std::ostream& out) const override { out << "Undef[key=" << key_ << "]"; }
};

class Def : public ContextRule {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add one sentence explaining what this class represents.

for (const auto& request : requests) {
auto& lang = language(request, request.verb());
result.emplace_back(lang.expand(request, request, inherit_, strict_));
for (size_t i = 0; i < requests.size(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I am not mistaken this could still be a range based for loop

@@ -183,7 +193,8 @@ std::string MarsLanguage::bestMatch(const MarsExpandContext& ctx, const std::str
size_t score = (fullMatch ? name.length() : 1);
std::vector<std::string> best;

static bool strict = eckit::Resource<bool>("$METKIT_LANGUAGE_STRICT_MODE", false);

static bool strict = eckit::Resource<bool>("$METKIT_LANGUAGE_STRICT_MODE", true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have downstream impact? If not, why not remove the whole option and always be strict?

Comment on lines 750 to 758
// {
// const char* text = "retrieve,class=d1,dataset=extreme-dt,date=-1";
// ExpectedVals expected{{"class", {"d1"}}, {"dataset", {"extremes-dt"}},
// {"expver", {"0001"}}, {"levelist", {"1000", "850", "700", "500", "400", "300"}},
// {"levtype", {"pl"}}, {"param", {"129"}},
// {"step", {"0"}}, {"stream", {"oper"}},
// {"time", {"1200"}}, {"type", {"an"}}};
// expand(text, "retrieve", expected, {-1});
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix or remove

@@ -34,6 +34,8 @@ ecbuild_get_test_multidata( TARGET metkit_get_odb_data
# TEST_DEPENDS grib_get_data
# )

file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/expand" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a softlink instead. Use

add_custom_command(soft_link_expand_test_data ALL
                  COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/expand")

Comment on lines 430 to 432
// for (std::vector<std::string>::const_iterator k = params.begin(); k != params.end(); ++k) {
// type(*k)->finalise(ctx, result, strict);
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented out code

@@ -0,0 +1,105 @@
/*
* (C) Copyright 1996- ECMWF.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be (C) Copyright 2025- ECMWF.

@@ -0,0 +1,57 @@
/*
* (C) Copyright 1996- ECMWF.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be 2025

EXPECT_EQUAL(e.second.size(), vv.size());
ExpectedRequest() = default;

ExpectedRequest(std::string vrb, ExpectedVals vv, std::vector<std::string> dd) : verb(vrb), vals(vv), dates(dd) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is just test code but all 3 arguments should be moved

- [kwbc]
- [none]
- [hrm]
- [ifs, IFS with no ocean model]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason 'IFS' and the other all capital letter aliases has been removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We aim to handle all requests on a case-insensitive basis, so the code is already handling the enum values disregarding their case.


# verify
# refdate

hdate:
category: data
multiple: true
type: integer
# type: integer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be removed

@@ -13,3 +13,4 @@ wind:
# list of tables used by ParamID normalisation to limit the param-table expansion to wind, ocean and reanalysis
drop-tables: [140,150,151,160,162,170,180,190]
full-table-dropping: true
ml-params-single-level: [22, 127, 128, 129, 152]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if I understand the purpose but from MarsRequest::count I transcribed that this list of parameters can be used in the presence of a levelist keyword but still result in only a single field. Isn't that a violation of our mars tree design?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, you are right. This violates the assumption that the hypercube is a dense set.
There are a few parameters that are only encoded at levelist=1 for levtype=ml (which is even more odd, since levelist=1 is in the stratosphere).

We suggested encoding those parameters as levtype=sfc or sol, but we have been told that users need to retrieve those parameters together with the 3D of the atmosphere... and we cannot mix different levtypes in a single request.

size_t levels = 1;
size_t params = 0;
size_t paramsSingleLevel = 0;

for (std::list<Parameter>::const_iterator i = params_.begin(); i != params_.end(); ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you rework this anyway you can turn this into a range base do loop as well

@@ -326,8 +327,47 @@ void MarsRequest::getParams(std::vector<std::string>& p) const {

size_t MarsRequest::count() const {
size_t result = 1;

std::set<std::string> paramidsSingleLevel = ParamID::getMlParamsSingleLevel();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be const and a reference.

Comment on lines 348 to 349
if (paramidsSingleLevel.find(v) != paramidsSingleLevel.end()) {
paramsSingleLevel++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use paramsSingleLevel += parmaIdsSingleLevel.count(v);

}
else {
if (i->name() == "param") {
for (auto v : i->values()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const auto&

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants