From 6eb2f84e2dd2ecb483dc11917a47461609aaaa5e Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Fri, 21 Jun 2024 12:15:02 +0100 Subject: [PATCH] refactored to address PR comments --- src/fdb5/api/FDB.cc | 7 +- src/fdb5/api/local/AxesVisitor.h | 2 +- src/fdb5/api/local/ControlVisitor.h | 2 +- src/fdb5/api/local/DumpVisitor.h | 2 +- src/fdb5/api/local/ListVisitor.h | 2 +- src/fdb5/api/local/MoveVisitor.h | 2 +- src/fdb5/api/local/PurgeVisitor.cc | 2 - src/fdb5/api/local/PurgeVisitor.h | 2 +- src/fdb5/api/local/StatsVisitor.cc | 2 - src/fdb5/api/local/StatsVisitor.h | 2 +- src/fdb5/api/local/StatusVisitor.h | 2 +- src/fdb5/api/local/WipeVisitor.h | 2 +- src/fdb5/daos/DaosCatalogueReader.cc | 2 +- src/fdb5/daos/DaosCatalogueReader.h | 2 +- src/fdb5/daos/DaosEngine.h | 2 +- src/fdb5/daos/DaosIndex.cc | 2 +- src/fdb5/daos/DaosIndex.h | 2 +- src/fdb5/daos/DaosStore.cc | 2 +- src/fdb5/daos/DaosStore.h | 2 +- src/fdb5/database/ArchiveVisitor.cc | 12 +- src/fdb5/database/ArchiveVisitor.h | 2 +- src/fdb5/database/Archiver.cc | 1 - src/fdb5/database/BaseArchiveVisitor.cc | 14 +- src/fdb5/database/BaseArchiveVisitor.h | 10 +- src/fdb5/database/Catalogue.h | 6 +- src/fdb5/database/DB.cc | 8 +- src/fdb5/database/DB.h | 8 +- src/fdb5/database/Engine.h | 2 +- src/fdb5/database/EntryVisitMechanism.cc | 2 +- src/fdb5/database/EntryVisitMechanism.h | 3 +- src/fdb5/database/Index.cc | 10 +- src/fdb5/database/Index.h | 16 +- src/fdb5/database/IndexAxis.cc | 9 +- src/fdb5/database/IndexAxis.h | 3 +- src/fdb5/database/Key.cc | 209 ++++++++++++---------- src/fdb5/database/Key.h | 69 +++---- src/fdb5/database/Manager.cc | 24 +-- src/fdb5/database/Manager.h | 2 +- src/fdb5/database/MoveVisitor.h | 2 +- src/fdb5/database/MultiRetrieveVisitor.cc | 14 +- src/fdb5/database/MultiRetrieveVisitor.h | 6 +- src/fdb5/database/ReadVisitor.h | 8 +- src/fdb5/database/RetrieveVisitor.cc | 10 +- src/fdb5/database/RetrieveVisitor.h | 6 +- src/fdb5/database/Store.h | 2 +- src/fdb5/database/WipeVisitor.h | 2 +- src/fdb5/database/WriteVisitor.h | 6 +- src/fdb5/pmem/PMemDB.cc | 4 +- src/fdb5/pmem/PMemDB.h | 2 +- src/fdb5/pmem/PMemDBReader.cc | 2 +- src/fdb5/pmem/PMemDBReader.h | 2 +- src/fdb5/pmem/PMemEngine.cc | 8 +- src/fdb5/pmem/PMemEngine.h | 2 +- src/fdb5/pmem/PMemIndex.cc | 2 +- src/fdb5/pmem/PMemIndex.h | 2 +- src/fdb5/pmem/PMemStats.h | 2 +- src/fdb5/pmem/PoolManager.cc | 2 +- src/fdb5/rules/MatchAny.cc | 2 +- src/fdb5/rules/MatchOptional.cc | 2 +- src/fdb5/rules/MatchOptional.h | 2 +- src/fdb5/rules/MatchValue.cc | 2 +- src/fdb5/rules/Matcher.cc | 2 +- src/fdb5/rules/Matcher.h | 3 +- src/fdb5/rules/Predicate.cc | 7 +- src/fdb5/rules/Predicate.h | 3 +- src/fdb5/rules/Rule.cc | 111 ++++++------ src/fdb5/rules/Rule.h | 32 ++-- src/fdb5/rules/Schema.cc | 57 +++--- src/fdb5/rules/Schema.h | 4 +- src/fdb5/toc/AdoptVisitor.cc | 10 +- src/fdb5/toc/AdoptVisitor.h | 4 +- src/fdb5/toc/RootManager.cc | 22 +-- src/fdb5/toc/RootManager.h | 2 +- src/fdb5/toc/TocCatalogueReader.cc | 2 +- src/fdb5/toc/TocCatalogueReader.h | 2 +- src/fdb5/toc/TocCatalogueWriter.cc | 6 +- src/fdb5/toc/TocCatalogueWriter.h | 4 +- src/fdb5/toc/TocEngine.cc | 8 +- src/fdb5/toc/TocEngine.h | 2 +- src/fdb5/toc/TocIndex.cc | 4 +- src/fdb5/toc/TocIndex.h | 4 +- src/fdb5/toc/TocStats.h | 2 +- src/fdb5/toc/TocStore.cc | 4 +- src/fdb5/toc/TocStore.h | 2 +- src/fdb5/tools/fdb-hide.cc | 6 +- src/fdb5/tools/fdb-overlay.cc | 12 +- src/fdb5/tools/fdb-root.cc | 6 +- tests/fdb/test_fdb5_service.cc | 15 +- tests/fdb/type/test_toKey.cc | 12 +- 89 files changed, 455 insertions(+), 438 deletions(-) diff --git a/src/fdb5/api/FDB.cc b/src/fdb5/api/FDB.cc index 97501b9d9..9edcdea1f 100644 --- a/src/fdb5/api/FDB.cc +++ b/src/fdb5/api/FDB.cc @@ -19,6 +19,7 @@ #include "eckit/log/Log.h" #include "eckit/message/Message.h" #include "eckit/message/Reader.h" +#include "eckit/utils/StringTools.h" #include "metkit/hypercube/HyperCubePayloaded.h" @@ -104,15 +105,15 @@ void FDB::archive(const CanonicalKey& key, const void* data, size_t length) { // This is the API entrypoint. Keys supplied by the user may not have type registry info attached (so // serialisation won't work properly...) CanonicalKey keyInternal(key); - keyInternal.registry(config().schema().registry()); // step in archival requests from the model is just an integer. We need to include the stepunit auto stepunit = keyInternal.find("stepunits"); if (stepunit != keyInternal.end()) { - if (stepunit->second.size()>0 && stepunit->second[0]!='h') { + if (stepunit->second.size()>0 && static_cast(tolower(stepunit->second[0])) != 'h') { auto step = keyInternal.find("step"); if (step != keyInternal.end()) { - std::string canonicalStep = keyInternal.registry().lookupType("step").toKey("step", step->second+stepunit->second); + std::string canonicalStep = config().schema().registry()->lookupType("step").toKey("step", step->second + static_cast(tolower(stepunit->second[0]))); + keyInternal.set("step", canonicalStep); } } keyInternal.unset("stepunits"); diff --git a/src/fdb5/api/local/AxesVisitor.h b/src/fdb5/api/local/AxesVisitor.h index 9dc9a4747..f6b46628a 100644 --- a/src/fdb5/api/local/AxesVisitor.h +++ b/src/fdb5/api/local/AxesVisitor.h @@ -40,7 +40,7 @@ class AxesVisitor : public QueryVisitor { // bool preVisitDatabase(const eckit::URI& uri) override; bool visitDatabase(const Catalogue& catalogue, const Store& store) override; bool visitIndex(const Index&) override; - void visitDatum(const Field&, const ApiKey&) override { NOTIMP; } + void visitDatum(const Field&, const TypedKey&) override { NOTIMP; } private: // members diff --git a/src/fdb5/api/local/ControlVisitor.h b/src/fdb5/api/local/ControlVisitor.h index cf4af7000..54b214a3c 100644 --- a/src/fdb5/api/local/ControlVisitor.h +++ b/src/fdb5/api/local/ControlVisitor.h @@ -39,7 +39,7 @@ class ControlVisitor : public QueryVisitor { bool visitDatabase(const Catalogue& catalogue, const Store& store) override; bool visitIndex(const Index&) override { NOTIMP; } - void visitDatum(const Field&, const ApiKey&) override { NOTIMP; } + void visitDatum(const Field&, const TypedKey&) override { NOTIMP; } private: // members diff --git a/src/fdb5/api/local/DumpVisitor.h b/src/fdb5/api/local/DumpVisitor.h index d36bd22f8..d93466dbc 100644 --- a/src/fdb5/api/local/DumpVisitor.h +++ b/src/fdb5/api/local/DumpVisitor.h @@ -49,7 +49,7 @@ class DumpVisitor : public QueryVisitor { return true; } bool visitIndex(const Index&) override { NOTIMP; } - void visitDatum(const Field&, const ApiKey&) override { NOTIMP; } + void visitDatum(const Field&, const TypedKey&) override { NOTIMP; } void visitDatum(const Field& field, const std::string& keyFingerprint) override { EntryVisitor::visitDatum(field, keyFingerprint); diff --git a/src/fdb5/api/local/ListVisitor.h b/src/fdb5/api/local/ListVisitor.h index 66056a20c..f4e84c77f 100644 --- a/src/fdb5/api/local/ListVisitor.h +++ b/src/fdb5/api/local/ListVisitor.h @@ -80,7 +80,7 @@ struct ListVisitor : public QueryVisitor { } /// Test if entry matches the current request. If so, add to the output queue. - void visitDatum(const Field& field, const ApiKey& datumKey) override { + void visitDatum(const Field& field, const TypedKey& datumKey) override { ASSERT(currentCatalogue_); ASSERT(currentIndex_); diff --git a/src/fdb5/api/local/MoveVisitor.h b/src/fdb5/api/local/MoveVisitor.h index b446646bf..a1f91fbf0 100644 --- a/src/fdb5/api/local/MoveVisitor.h +++ b/src/fdb5/api/local/MoveVisitor.h @@ -44,7 +44,7 @@ class MoveVisitor : public QueryVisitor { bool visitDatabase(const Catalogue& catalogue, const Store& store) override; bool visitIndex(const Index&) override { NOTIMP; } - void visitDatum(const Field&, const ApiKey&) override { NOTIMP; } + void visitDatum(const Field&, const TypedKey&) override { NOTIMP; } void visitDatum(const Field& field, const std::string& keyFingerprint) override { NOTIMP; } private: // members diff --git a/src/fdb5/api/local/PurgeVisitor.cc b/src/fdb5/api/local/PurgeVisitor.cc index 4ec46848c..d0c9d9f84 100644 --- a/src/fdb5/api/local/PurgeVisitor.cc +++ b/src/fdb5/api/local/PurgeVisitor.cc @@ -82,8 +82,6 @@ void PurgeVisitor::visitDatum(const Field& field, const std::string& keyFingerpr internalVisitor_->visitDatum(field, keyFingerprint); } -void PurgeVisitor::visitDatum(const Field&, const ApiKey&) { NOTIMP; } - void PurgeVisitor::catalogueComplete(const Catalogue& catalogue) { internalVisitor_->catalogueComplete(catalogue); diff --git a/src/fdb5/api/local/PurgeVisitor.h b/src/fdb5/api/local/PurgeVisitor.h index 057dbde45..227b1519c 100644 --- a/src/fdb5/api/local/PurgeVisitor.h +++ b/src/fdb5/api/local/PurgeVisitor.h @@ -48,7 +48,7 @@ class PurgeVisitor : public QueryVisitor { bool visitIndex(const Index& index) override; void catalogueComplete(const Catalogue& catalogue) override; void visitDatum(const Field& field, const std::string& keyFingerprint) override; - void visitDatum(const Field&, const ApiKey&) override; + void visitDatum(const Field&, const TypedKey&) override { NOTIMP; } private: // members diff --git a/src/fdb5/api/local/StatsVisitor.cc b/src/fdb5/api/local/StatsVisitor.cc index 076e83b3e..b198a3223 100644 --- a/src/fdb5/api/local/StatsVisitor.cc +++ b/src/fdb5/api/local/StatsVisitor.cc @@ -47,8 +47,6 @@ void StatsVisitor::visitDatum(const Field& field, const std::string& keyFingerpr internalVisitor_->visitDatum(field, keyFingerprint); } -void StatsVisitor::visitDatum(const Field&, const ApiKey&) { NOTIMP; } - void StatsVisitor::catalogueComplete(const Catalogue& catalogue) { internalVisitor_->catalogueComplete(catalogue); diff --git a/src/fdb5/api/local/StatsVisitor.h b/src/fdb5/api/local/StatsVisitor.h index 80082f915..dc354d076 100644 --- a/src/fdb5/api/local/StatsVisitor.h +++ b/src/fdb5/api/local/StatsVisitor.h @@ -42,7 +42,7 @@ class StatsVisitor : public QueryVisitor { bool visitIndex(const Index& index) override; void catalogueComplete(const Catalogue& catalogue) override; void visitDatum(const Field& field, const std::string& keyFingerprint) override; - void visitDatum(const Field&, const ApiKey&) override; + void visitDatum(const Field&, const TypedKey&) override { NOTIMP; } private: // members diff --git a/src/fdb5/api/local/StatusVisitor.h b/src/fdb5/api/local/StatusVisitor.h index 6af346b21..3845ee9c8 100644 --- a/src/fdb5/api/local/StatusVisitor.h +++ b/src/fdb5/api/local/StatusVisitor.h @@ -38,7 +38,7 @@ class StatusVisitor : public QueryVisitor { bool visitEntries() override { return false; } bool visitDatabase(const Catalogue& catalogue, const Store& store) override { queue_.emplace(catalogue); return true; } bool visitIndex(const Index&) override { NOTIMP; } - void visitDatum(const Field&, const ApiKey&) override { NOTIMP; } + void visitDatum(const Field&, const TypedKey&) override { NOTIMP; } void visitDatum(const Field& field, const std::string& keyFingerprint) override { EntryVisitor::visitDatum(field, keyFingerprint); diff --git a/src/fdb5/api/local/WipeVisitor.h b/src/fdb5/api/local/WipeVisitor.h index f3260a05f..0bfbdfeab 100644 --- a/src/fdb5/api/local/WipeVisitor.h +++ b/src/fdb5/api/local/WipeVisitor.h @@ -50,7 +50,7 @@ class WipeVisitor : public QueryVisitor { bool visitDatabase(const Catalogue& catalogue, const Store& store) override; bool visitIndex(const Index& index) override; void catalogueComplete(const Catalogue& catalogue) override; - void visitDatum(const Field&, const ApiKey&) override { NOTIMP; } + void visitDatum(const Field&, const TypedKey&) override { NOTIMP; } void visitDatum(const Field& field, const std::string& keyFingerprint) override { NOTIMP; } virtual void onDatabaseNotFound(const fdb5::DatabaseNotFoundException& e) override { throw e; } diff --git a/src/fdb5/daos/DaosCatalogueReader.cc b/src/fdb5/daos/DaosCatalogueReader.cc index b9fbc406b..a6f4a49b8 100644 --- a/src/fdb5/daos/DaosCatalogueReader.cc +++ b/src/fdb5/daos/DaosCatalogueReader.cc @@ -122,7 +122,7 @@ bool DaosCatalogueReader::axis(const std::string &keyword, eckit::StringSet &s) } -bool DaosCatalogueReader::retrieve(const ApiKey& key, Field& field) const { +bool DaosCatalogueReader::retrieve(const TypedKey& key, Field& field) const { eckit::Log::debug() << "Trying to retrieve key " << key << std::endl; eckit::Log::debug() << "Scanning index " << current_.location() << std::endl; diff --git a/src/fdb5/daos/DaosCatalogueReader.h b/src/fdb5/daos/DaosCatalogueReader.h index 48cc872c3..84713be44 100644 --- a/src/fdb5/daos/DaosCatalogueReader.h +++ b/src/fdb5/daos/DaosCatalogueReader.h @@ -40,7 +40,7 @@ class DaosCatalogueReader : public DaosCatalogue, public CatalogueReader { bool axis(const std::string &keyword, eckit::StringSet &s) const override; - bool retrieve(const ApiKey& key, Field& field) const override; + bool retrieve(const TypedKey& key, Field& field) const override; void print( std::ostream &out ) const override { NOTIMP; } diff --git a/src/fdb5/daos/DaosEngine.h b/src/fdb5/daos/DaosEngine.h index 35a873f0a..520cec46a 100644 --- a/src/fdb5/daos/DaosEngine.h +++ b/src/fdb5/daos/DaosEngine.h @@ -41,7 +41,7 @@ class DaosEngine : public fdb5::Engine { virtual bool canHandle(const eckit::URI&, const Config&) const override; - virtual std::vector allLocations(const CanonicalKey& key, const Config& config) const override { NOTIMP; }; + // virtual std::vector allLocations(const CanonicalKey& key, const Config& config) const override { NOTIMP; }; virtual std::vector visitableLocations(const CanonicalKey& key, const Config& config) const override; virtual std::vector visitableLocations(const metkit::mars::MarsRequest& rq, const Config& config) const override; diff --git a/src/fdb5/daos/DaosIndex.cc b/src/fdb5/daos/DaosIndex.cc index f14808052..ea166ba20 100644 --- a/src/fdb5/daos/DaosIndex.cc +++ b/src/fdb5/daos/DaosIndex.cc @@ -159,7 +159,7 @@ bool DaosIndex::get(const CanonicalKey& key, const CanonicalKey& remapKey, Field } -void DaosIndex::add(const ApiKey& key, const Field &field) { +void DaosIndex::add(const TypedKey& key, const Field &field) { eckit::MemoryHandle h{(size_t) PATH_MAX}; eckit::HandleStream hs{h}; diff --git a/src/fdb5/daos/DaosIndex.h b/src/fdb5/daos/DaosIndex.h index 66f12fb4f..1399fcefb 100644 --- a/src/fdb5/daos/DaosIndex.h +++ b/src/fdb5/daos/DaosIndex.h @@ -48,7 +48,7 @@ class DaosIndex : public IndexBase { void visit(IndexLocationVisitor& visitor) const override { NOTIMP; } bool get( const CanonicalKey& key, const CanonicalKey& remapKey, Field &field ) const override; - void add( const ApiKey& key, const Field &field ) override; + void add( const TypedKey& key, const Field &field ) override; void flush() override { NOTIMP; } void encode(eckit::Stream& s, const int version) const override { NOTIMP; } void entries(EntryVisitor& visitor) const override; diff --git a/src/fdb5/daos/DaosStore.cc b/src/fdb5/daos/DaosStore.cc index 655a64447..8026abc3f 100644 --- a/src/fdb5/daos/DaosStore.cc +++ b/src/fdb5/daos/DaosStore.cc @@ -105,7 +105,7 @@ eckit::DataHandle* DaosStore::retrieve(Field& field) const { } -std::unique_ptr DaosStore::archive(const CanonicalKey& key, const void *data, eckit::Length length) { +std::unique_ptr DaosStore::archive(const CanonicalKey&, const void *data, eckit::Length length) { /// @note: performed RPCs: /// - open pool if not cached (daos_pool_connect) -- always skipped as it is cached after selectDatabase. diff --git a/src/fdb5/daos/DaosStore.h b/src/fdb5/daos/DaosStore.h index 14a62123d..754e004be 100644 --- a/src/fdb5/daos/DaosStore.h +++ b/src/fdb5/daos/DaosStore.h @@ -49,7 +49,7 @@ class DaosStore : public Store, public DaosCommon { bool exists() const override; eckit::DataHandle* retrieve(Field& field) const override; - std::unique_ptr archive(const CanonicalKey& key, const void *data, eckit::Length length) override; + std::unique_ptr archive(const CanonicalKey&, const void *data, eckit::Length length) override; void remove(const eckit::URI& uri, std::ostream& logAlways, std::ostream& logVerbose, bool doit) const override; diff --git a/src/fdb5/database/ArchiveVisitor.cc b/src/fdb5/database/ArchiveVisitor.cc index 84c5a58af..673cc90bf 100644 --- a/src/fdb5/database/ArchiveVisitor.cc +++ b/src/fdb5/database/ArchiveVisitor.cc @@ -16,21 +16,19 @@ namespace fdb5 { -ArchiveVisitor::ArchiveVisitor(Archiver &owner, const CanonicalKey& field, const void *data, size_t size) : - BaseArchiveVisitor(owner, field), +ArchiveVisitor::ArchiveVisitor(Archiver &owner, const CanonicalKey& initialFieldKey, const void *data, size_t size) : + BaseArchiveVisitor(owner, initialFieldKey), data_(data), size_(size) { } -bool ArchiveVisitor::selectDatum(const ApiKey& key, const CanonicalKey& full) { +bool ArchiveVisitor::selectDatum(const TypedKey& datumKey, const TypedKey& fullComputedKey) { - // eckit::Log::info() << "selectDatum " << key << ", " << full << " " << size_ << std::endl; - checkMissingKeys(full); + checkMissingKeys(fullComputedKey); ASSERT(current()); - current()->archive(key, data_, size_); - + current()->archive(datumKey, data_, size_); return true; } diff --git a/src/fdb5/database/ArchiveVisitor.h b/src/fdb5/database/ArchiveVisitor.h index 5bb255584..258375924 100644 --- a/src/fdb5/database/ArchiveVisitor.h +++ b/src/fdb5/database/ArchiveVisitor.h @@ -34,7 +34,7 @@ class ArchiveVisitor : public BaseArchiveVisitor { protected: // methods - virtual bool selectDatum(const ApiKey& key, const CanonicalKey& full) override; + virtual bool selectDatum(const TypedKey& datumKey, const TypedKey& fullComputedKey) override; virtual void print( std::ostream &out ) const override; diff --git a/src/fdb5/database/Archiver.cc b/src/fdb5/database/Archiver.cc index e50e3ecad..4410d56a2 100644 --- a/src/fdb5/database/Archiver.cc +++ b/src/fdb5/database/Archiver.cc @@ -45,7 +45,6 @@ void Archiver::archive(const CanonicalKey& key, BaseArchiveVisitor& visitor) { visitor.rule(nullptr); - dbConfig_.schema().expand(key, visitor); const Rule* rule = visitor.rule(); diff --git a/src/fdb5/database/BaseArchiveVisitor.cc b/src/fdb5/database/BaseArchiveVisitor.cc index cbc7c9137..75243f04f 100644 --- a/src/fdb5/database/BaseArchiveVisitor.cc +++ b/src/fdb5/database/BaseArchiveVisitor.cc @@ -17,30 +17,30 @@ namespace fdb5 { -BaseArchiveVisitor::BaseArchiveVisitor(Archiver &owner, const CanonicalKey& field) : +BaseArchiveVisitor::BaseArchiveVisitor(Archiver &owner, const CanonicalKey& initialFieldKey) : WriteVisitor(owner.prev_), owner_(owner), - field_(field) { + initialFieldKey_(initialFieldKey) { checkMissingKeysOnWrite_ = eckit::Resource("checkMissingKeysOnWrite", true); } -bool BaseArchiveVisitor::selectDatabase(const CanonicalKey& dbKey, const CanonicalKey&) { - LOG_DEBUG_LIB(LibFdb5) << "selectDatabase " << dbKey << std::endl; +bool BaseArchiveVisitor::selectDatabase(const CanonicalKey& dbKey, const TypedKey& fullComputedKey) { + LOG_DEBUG_LIB(LibFdb5) << "BaseArchiveVisitor::selectDatabase " << dbKey << std::endl; owner_.current_ = &owner_.database(dbKey); owner_.current_->deselectIndex(); return true; } -bool BaseArchiveVisitor::selectIndex(const CanonicalKey& idxKey, const CanonicalKey&) { +bool BaseArchiveVisitor::selectIndex(const CanonicalKey& idxKey, const TypedKey& fullComputedKey) { // eckit::Log::info() << "selectIndex " << idxKey << std::endl; ASSERT(owner_.current_); return owner_.current_->selectIndex(idxKey); } -void BaseArchiveVisitor::checkMissingKeys(const CanonicalKey& full) { +void BaseArchiveVisitor::checkMissingKeys(const TypedKey& fullComputedKey) { if (checkMissingKeysOnWrite_) { - field_.validateKeysOf(full); + fullComputedKey.validateKeys(initialFieldKey_); } } diff --git a/src/fdb5/database/BaseArchiveVisitor.h b/src/fdb5/database/BaseArchiveVisitor.h index 6a4857b19..a8119ec1a 100644 --- a/src/fdb5/database/BaseArchiveVisitor.h +++ b/src/fdb5/database/BaseArchiveVisitor.h @@ -32,15 +32,15 @@ class BaseArchiveVisitor : public WriteVisitor { public: // methods - BaseArchiveVisitor(Archiver &owner, const CanonicalKey& field); + BaseArchiveVisitor(Archiver &owner, const CanonicalKey& initialFieldKey); protected: // methods - virtual bool selectDatabase(const CanonicalKey& dbKey, const CanonicalKey& full); + virtual bool selectDatabase(const CanonicalKey& dbKey, const TypedKey& fullComputedKey); - virtual bool selectIndex(const CanonicalKey& idxKey, const CanonicalKey& full); + virtual bool selectIndex(const CanonicalKey& idxKey, const TypedKey& fullComputedKey); - virtual void checkMissingKeys(const CanonicalKey& full); + virtual void checkMissingKeys(const TypedKey& fullComputedKey); virtual const Schema& databaseSchema() const; @@ -50,7 +50,7 @@ class BaseArchiveVisitor : public WriteVisitor { Archiver &owner_; - const CanonicalKey& field_; + const CanonicalKey& initialFieldKey_; bool checkMissingKeysOnWrite_; }; diff --git a/src/fdb5/database/Catalogue.h b/src/fdb5/database/Catalogue.h index c27769c33..f362a0a20 100644 --- a/src/fdb5/database/Catalogue.h +++ b/src/fdb5/database/Catalogue.h @@ -115,16 +115,16 @@ class CatalogueReader { public: virtual DbStats stats() const = 0; virtual bool axis(const std::string& keyword, eckit::StringSet& s) const = 0; - virtual bool retrieve(const ApiKey& key, Field& field) const = 0; + virtual bool retrieve(const TypedKey& key, Field& field) const = 0; }; class CatalogueWriter { public: virtual const Index& currentIndex() = 0; - virtual void archive(const ApiKey& key, std::unique_ptr fieldLocation) = 0; + virtual void archive(const TypedKey& key, std::unique_ptr fieldLocation) = 0; virtual void overlayDB(const Catalogue& otherCatalogue, const std::set& variableKeys, bool unmount) = 0; - virtual void index(const ApiKey& key, const eckit::URI& uri, eckit::Offset offset, eckit::Length length) = 0; + virtual void index(const TypedKey& key, const eckit::URI& uri, eckit::Offset offset, eckit::Length length) = 0; virtual void reconsolidate() = 0; }; diff --git a/src/fdb5/database/DB.cc b/src/fdb5/database/DB.cc index 79d7bb68e..23ce07973 100644 --- a/src/fdb5/database/DB.cc +++ b/src/fdb5/database/DB.cc @@ -83,7 +83,7 @@ bool DB::axis(const std::string &keyword, eckit::StringSet &s) const { return cat->axis(keyword, s); } -bool DB::inspect(const ApiKey& key, Field& field) { +bool DB::inspect(const TypedKey& key, Field& field) { LOG_DEBUG_LIB(LibFdb5) << "Trying to retrieve key " << key << std::endl; @@ -93,7 +93,7 @@ bool DB::inspect(const ApiKey& key, Field& field) { return cat->retrieve(key, field); } -eckit::DataHandle *DB::retrieve(const ApiKey& key) { +eckit::DataHandle *DB::retrieve(const TypedKey& key) { Field field; if (inspect(key, field)) { @@ -103,7 +103,7 @@ eckit::DataHandle *DB::retrieve(const ApiKey& key) { return nullptr; } -void DB::archive(const ApiKey& key, const void* data, eckit::Length length) { +void DB::archive(const TypedKey& key, const void* data, eckit::Length length) { CatalogueWriter* cat = dynamic_cast(catalogue_.get()); ASSERT(cat); @@ -164,7 +164,7 @@ void DB::reconsolidate() { cat->reconsolidate(); } -void DB::index(const ApiKey& key, const eckit::PathName &path, eckit::Offset offset, eckit::Length length) { +void DB::index(const TypedKey& key, const eckit::PathName &path, eckit::Offset offset, eckit::Length length) { if (catalogue_->type() == TocEngine::typeName()) { CatalogueWriter* cat = dynamic_cast(catalogue_.get()); ASSERT(cat); diff --git a/src/fdb5/database/DB.h b/src/fdb5/database/DB.h index ece22dd22..6cf457b34 100644 --- a/src/fdb5/database/DB.h +++ b/src/fdb5/database/DB.h @@ -54,9 +54,9 @@ class DB final : public eckit::OwnedLock { const Schema& schema() const; bool axis(const std::string &keyword, eckit::StringSet &s) const; - bool inspect(const ApiKey& key, Field& field); - eckit::DataHandle *retrieve(const ApiKey& key); - void archive(const ApiKey& key, const void *data, eckit::Length length); + bool inspect(const TypedKey& key, Field& field); + eckit::DataHandle *retrieve(const TypedKey& key); + void archive(const TypedKey& key, const void *data, eckit::Length length); bool open(); void flush(); @@ -79,7 +79,7 @@ class DB final : public eckit::OwnedLock { void visitEntries(EntryVisitor& visitor, bool sorted = false); /// Used for adopting & indexing external data to the TOC dir - void index(const ApiKey& key, const eckit::PathName &path, eckit::Offset offset, eckit::Length length); + void index(const TypedKey& key, const eckit::PathName &path, eckit::Offset offset, eckit::Length length); // Control access properties of the DB void control(const ControlAction& action, const ControlIdentifiers& identifiers) const; diff --git a/src/fdb5/database/Engine.h b/src/fdb5/database/Engine.h index 42f40d371..343b926b8 100644 --- a/src/fdb5/database/Engine.h +++ b/src/fdb5/database/Engine.h @@ -56,7 +56,7 @@ class Engine : private eckit::NonCopyable { virtual eckit::URI location(const CanonicalKey& key, const Config& config) const = 0; /// Lists the roots that can be visited given a DB key - virtual std::vector allLocations(const CanonicalKey& key, const Config& config) const = 0; + // virtual std::vector allLocations(const CanonicalKey& key, const Config& config) const = 0; /// Lists the roots that can be visited given a DB key virtual std::vector visitableLocations(const CanonicalKey& key, const Config& config) const = 0; diff --git a/src/fdb5/database/EntryVisitMechanism.cc b/src/fdb5/database/EntryVisitMechanism.cc index 34b6054f9..1bb3b86ba 100644 --- a/src/fdb5/database/EntryVisitMechanism.cc +++ b/src/fdb5/database/EntryVisitMechanism.cc @@ -61,7 +61,7 @@ void EntryVisitor::visitDatum(const Field& field, const std::string& keyFingerpr ASSERT(currentCatalogue_); ASSERT(currentIndex_); - ApiKey key(keyFingerprint, currentCatalogue_->schema().ruleFor(currentCatalogue_->key(), currentIndex_->key())); + TypedKey key(keyFingerprint, currentCatalogue_->schema().ruleFor(currentCatalogue_->key(), currentIndex_->key())); visitDatum(field, key); } diff --git a/src/fdb5/database/EntryVisitMechanism.h b/src/fdb5/database/EntryVisitMechanism.h index 0399efe0e..6d459b6e2 100644 --- a/src/fdb5/database/EntryVisitMechanism.h +++ b/src/fdb5/database/EntryVisitMechanism.h @@ -26,7 +26,6 @@ class Catalogue; class Store; class FDBToolRequest; class Index; -class Key; //---------------------------------------------------------------------------------------------------------------------- @@ -52,7 +51,7 @@ class EntryVisitor : public eckit::NonCopyable { private: // methods - virtual void visitDatum(const Field& field, const ApiKey& datumKey) = 0; + virtual void visitDatum(const Field& field, const TypedKey& datumKey) = 0; protected: // members diff --git a/src/fdb5/database/Index.cc b/src/fdb5/database/Index.cc index 3f23fe694..6231b0eed 100755 --- a/src/fdb5/database/Index.cc +++ b/src/fdb5/database/Index.cc @@ -125,11 +125,11 @@ void IndexBase::encodeLegacy(eckit::Stream& s, const int version) const { s << type_; } -void IndexBase::put(const ApiKey& key, const Field &field) { +void IndexBase::put(const TypedKey& key, const Field &field) { LOG_DEBUG_LIB(LibFdb5) << "FDB Index " << indexer_ << " " << key << " -> " << field << std::endl; - axes_.insert(key); + axes_.insert(key.canonical()); add(key, field); } @@ -142,7 +142,7 @@ bool IndexBase::partialMatch(const metkit::mars::MarsRequest& request) const { return true; } -bool IndexBase::mayContain(const ApiKey& key) const { +bool IndexBase::mayContain(const TypedKey& key) const { return axes_.contains(key.canonical()); } @@ -200,8 +200,8 @@ class NullIndex : public IndexBase { virtual void visit(IndexLocationVisitor&) const override { NOTIMP; } - virtual bool get( const ApiKey&, const CanonicalKey&, Field&) const override { NOTIMP; } - virtual void add( const ApiKey&, const Field&) override { NOTIMP; } + virtual bool get( const TypedKey&, const CanonicalKey&, Field&) const override { NOTIMP; } + virtual void add( const TypedKey&, const Field&) override { NOTIMP; } virtual void flush() override { NOTIMP; } virtual void encode(eckit::Stream&, const int version) const override { NOTIMP; } virtual void entries(EntryVisitor&) const override { NOTIMP; } diff --git a/src/fdb5/database/Index.h b/src/fdb5/database/Index.h index 9d98948fb..120cc9952 100755 --- a/src/fdb5/database/Index.h +++ b/src/fdb5/database/Index.h @@ -39,7 +39,7 @@ class Stream; namespace fdb5 { class CanonicalKey; -class ApiKey; +class TypedKey; class Index; class IndexLocationVisitor; class Schema; @@ -81,15 +81,15 @@ class IndexBase : public eckit::Counted { time_t timestamp() const { return timestamp_; } - virtual bool get(const ApiKey& key, const CanonicalKey& remapKey, Field &field) const = 0; - virtual void put(const ApiKey& key, const Field &field); + virtual bool get(const TypedKey& key, const CanonicalKey& remapKey, Field &field) const = 0; + virtual void put(const TypedKey& key, const Field &field); virtual void encode(eckit::Stream& s, const int version) const; virtual void entries(EntryVisitor& visitor) const = 0; virtual void dump(std::ostream& out, const char* indent, bool simple = false, bool dumpFields = false) const = 0; virtual bool partialMatch(const metkit::mars::MarsRequest& request) const; - virtual bool mayContain(const ApiKey& key) const; + virtual bool mayContain(const TypedKey& key) const; virtual IndexStats statistics() const = 0; @@ -109,7 +109,7 @@ class IndexBase : public eckit::Counted { void decodeCurrent(eckit::Stream& s, const int version); void decodeLegacy(eckit::Stream& s, const int version); - virtual void add(const ApiKey& key, const Field &field) = 0; + virtual void add(const TypedKey& key, const Field &field) = 0; protected: // members @@ -161,8 +161,8 @@ class Index { time_t timestamp() const { return content_->timestamp(); } - bool get(const ApiKey& key, const CanonicalKey& remapKey, Field& field) const { return content_->get(key, remapKey, field); } - void put(const ApiKey& key, const Field& field) { content_->put(key, field); } + bool get(const TypedKey& key, const CanonicalKey& remapKey, Field& field) const { return content_->get(key, remapKey, field); } + void put(const TypedKey& key, const Field& field) { content_->put(key, field); } void encode(eckit::Stream& s, const int version) const { content_->encode(s, version); } void entries(EntryVisitor& v) const { content_->entries(v); } @@ -176,7 +176,7 @@ class Index { const IndexBase* content() const { return content_; } bool partialMatch(const metkit::mars::MarsRequest& request) const { return content_->partialMatch(request); } - bool mayContain(const ApiKey& key) const { return content_->mayContain(key); } + bool mayContain(const TypedKey& key) const { return content_->mayContain(key); } bool null() const { return null_; } diff --git a/src/fdb5/database/IndexAxis.cc b/src/fdb5/database/IndexAxis.cc index 81b29673f..6de47e734 100755 --- a/src/fdb5/database/IndexAxis.cc +++ b/src/fdb5/database/IndexAxis.cc @@ -259,17 +259,16 @@ bool IndexAxis::contains(const CanonicalKey& key) const { return true; } -void IndexAxis::insert(const Key& key) { +void IndexAxis::insert(const CanonicalKey& key) { ASSERT(!readOnly_); - for (Key::const_iterator i = key.begin(); i != key.end(); ++i) { - const std::string &keyword = i->first; + for (const auto& k : key) { - std::shared_ptr >& axis_set = axis_[keyword]; + std::shared_ptr >& axis_set = axis_[k.first]; if (!axis_set) axis_set.reset(new eckit::DenseSet); - axis_set->insert(key.canonicalValue(keyword)); + axis_set->insert(key.canonicalValue(k.first)); dirty_ = true; } diff --git a/src/fdb5/database/IndexAxis.h b/src/fdb5/database/IndexAxis.h index fe6fcd2d1..6e044e0b2 100644 --- a/src/fdb5/database/IndexAxis.h +++ b/src/fdb5/database/IndexAxis.h @@ -35,7 +35,6 @@ class MarsRequest; namespace fdb5 { -class Key; class CanonicalKey; //---------------------------------------------------------------------------------------------------------------------- @@ -55,7 +54,7 @@ class IndexAxis : private eckit::NonCopyable { bool operator==(const IndexAxis& rhs) const; bool operator!=(const IndexAxis& rhs) const; - void insert(const Key& key); + void insert(const CanonicalKey& key); /// @note: the values are required to be cannonicalised void insert(const std::string& axis, const std::vector& values); void encode(eckit::Stream &s, const int version) const; diff --git a/src/fdb5/database/Key.cc b/src/fdb5/database/Key.cc index b2e44fb12..be3f36bb5 100644 --- a/src/fdb5/database/Key.cc +++ b/src/fdb5/database/Key.cc @@ -69,7 +69,6 @@ Key::~Key() {} void Key::decode(eckit::Stream& s) { - registry_ = nullptr; keys_.clear(); names_.clear(); @@ -93,17 +92,16 @@ void Key::decode(eckit::Stream& s) { } void Key::encode(eckit::Stream& s) const { - const TypesRegistry* registry = (registry_ ? registry_.get() : nullptr); + // const TypesRegistry* registry = (registry_ ? registry_.get() : nullptr); s << keys_.size(); for (eckit::StringDict::const_iterator i = keys_.begin(); i != keys_.end(); ++i) { - s << i->first << (registry ? canonicalise(i->first, i->second) : i->second); + s << i->first << canonicalise(i->first, i->second); } s << names_.size(); for (eckit::StringList::const_iterator i = names_.begin(); i != names_.end(); ++i) { - s << (*i); - s << (registry ? registry->lookupType(*i).type() : ""); + s << (*i) << type(*i); } } @@ -119,13 +117,14 @@ std::set Key::keys() const { } void Key::clear() { - registry_ = nullptr; keys_.clear(); names_.clear(); } void Key::set(const std::string &k, const std::string &v) { + ASSERT(names_.size() == keys_.size()); + eckit::StringDict::iterator it = keys_.find(k); if (it == keys_.end()) { names_.push_back(k); @@ -133,7 +132,6 @@ void Key::set(const std::string &k, const std::string &v) { } else { it->second = v; } - } void Key::unset(const std::string &k) { @@ -182,18 +180,20 @@ bool Key::match(const Key& other) const { bool Key::match(const metkit::mars::MarsRequest& request) const { - std::vector p = request.params(); - std::vector::const_iterator k = p.begin(); - std::vector::const_iterator kend = p.end(); - for (; k != kend; ++k) { + for (const auto& k : request.params()) { - const_iterator j = find(*k); + const_iterator j = find(k); if (j == end()) { return false; } - const auto& values = request.values(*k); - if (std::find(values.begin(), values.end(), j->second) == values.end()) { + bool found=false; + auto values = request.values(k); + std::string can = canonicalise(k, j->second); + for (auto it = values.begin(); !found && it != values.end(); it++) { + found = can == canonicalise(k, *it); + } + if (!found) { return false; } } @@ -201,34 +201,34 @@ bool Key::match(const metkit::mars::MarsRequest& request) const { return true; } -bool Key::match(const Key& other, const eckit::StringList& ignore) const { +// bool Key::match(const Key& other, const eckit::StringList& ignore) const { - for (const_iterator i = other.begin(); i != other.end(); ++i) { - if (std::find(ignore.begin(), ignore.end(), i->first) != ignore.end()) - continue; +// for (const_iterator i = other.begin(); i != other.end(); ++i) { +// if (std::find(ignore.begin(), ignore.end(), i->first) != ignore.end()) +// continue; - const_iterator j = find(i->first); - if (j == end()) { - return false; - } +// const_iterator j = find(i->first); +// if (j == end()) { +// return false; +// } - if (j->second != i->second) { - return false; - } +// if (j->second != i->second) { +// return false; +// } - } - return true; -} +// } +// return true; +// } -bool Key::match(const std::string &key, const std::set &values) const { +// bool Key::match(const std::string &key, const std::set &values) const { - eckit::StringDict::const_iterator i = find(key); - if (i == end()) { - return false; - } +// eckit::StringDict::const_iterator i = find(key); +// if (i == end()) { +// return false; +// } - return values.find(canonicalise(key, i->second)) != values.end(); -} +// return values.find(canonicalise(key, i->second)) != values.end(); +// } bool Key::match(const std::string &key, const eckit::DenseSet &values) const { @@ -257,24 +257,6 @@ bool Key::partialMatch(const metkit::mars::MarsRequest& request) const { return true; } -void Key::registry(const std::shared_ptr reg) { - registry_ = reg; -} - -const TypesRegistry& Key::registry() const { - if (!registry_) { - std::stringstream ss; - ss << "TypesRegistry has not been set for Key " << (*this) << " prior to use"; - throw eckit::SeriousBug(ss.str(), Here()); - } - - return *registry_; -} - -const void* Key::reg() const { - return registry_.get(); -} - std::string Key::canonicalValue(const std::string& keyword) const { eckit::StringDict::const_iterator it = keys_.find(keyword); @@ -285,7 +267,14 @@ std::string Key::canonicalValue(const std::string& keyword) const { std::string Key::valuesToString() const { - ASSERT(names_.size() == keys_.size()); + if(names_.size() != keys_.size()) { + std::stringstream ss; + ss << "names and keys size mismatch" << std::endl + << " names: " << names_.size() << " " << names_ << std::endl + << " keys: " << keys_.size() << " " << keys_ << std::endl; + + throw eckit::SeriousBug(ss.str()); + } std::ostringstream oss; const char *sep = ""; @@ -348,7 +337,7 @@ fdb5::Key::operator eckit::StringDict() const ASSERT(i != keys_.end()); ASSERT(!(*i).second.empty()); - res[*j] = registry_ ? (*i).second : registry_->lookupType(*j).tidy(*j, (*i).second); + res[*j] = canonicalise(*j, (*i).second); } return res; @@ -379,22 +368,19 @@ std::string Key::toString() const { //---------------------------------------------------------------------------------------------------------------------- -CanonicalKey::CanonicalKey(const std::shared_ptr reg) : - Key({}, reg) {} - -CanonicalKey::CanonicalKey(const std::string &s, const Rule *rule) : - Key({}, rule ? rule->registry() : nullptr) { +CanonicalKey::CanonicalKey() : + Key() {} - eckit::Tokenizer parse(":", true); - eckit::StringList values; - parse(s, values); +// CanonicalKey::CanonicalKey(const std::string &s) : +// Key({}) { - ASSERT(rule); - rule->fill(*this, values); -} +// eckit::Tokenizer parse(":", true); +// eckit::StringList values; +// parse(s, values); +// } -CanonicalKey::CanonicalKey(const eckit::StringDict &keys, const std::shared_ptr reg) : - Key(keys, reg) { +CanonicalKey::CanonicalKey(const eckit::StringDict &keys) : + Key(keys) { eckit::StringDict::const_iterator it = keys.begin(); eckit::StringDict::const_iterator end = keys.end(); @@ -403,13 +389,13 @@ CanonicalKey::CanonicalKey(const eckit::StringDict &keys, const std::shared_ptr< } } -CanonicalKey::CanonicalKey(eckit::Stream& s, const std::shared_ptr reg) : - Key({}, reg) { +CanonicalKey::CanonicalKey(eckit::Stream& s) : + Key() { decode(s); } -CanonicalKey::CanonicalKey(std::initializer_list> l, const std::shared_ptr reg) : - Key(l, reg) { +CanonicalKey::CanonicalKey(std::initializer_list> l) : + Key(l) { for (const auto& kv : keys_) { names_.emplace_back(kv.first); @@ -434,21 +420,24 @@ CanonicalKey CanonicalKey::parseString(const std::string& s) { return CanonicalKey{keys}; } -void CanonicalKey::validateKeysOf(const Key& other, bool checkAlsoValues) const +void TypedKey::validateKeys(const Key& other, bool checkAlsoValues) const { + + // std::cout << "validateKeys " << (*this) << std::endl + // << " " << other << std::endl; eckit::StringSet missing; eckit::StringSet mismatch; - const TypesRegistry* registry = (registry_ ? registry_.get() : nullptr); + ASSERT(registry_); - for (Key::const_iterator j = begin(); j != end(); ++j) { + for (Key::const_iterator j = other.begin(); j != other.end(); ++j) { const std::string& keyword = (*j).first; - Key::const_iterator k = other.find(keyword); - if (k == other.end()) { + Key::const_iterator k = find(keyword); + if (k == keys_.end()) { missing.insert(keyword); } else { - if(checkAlsoValues && (!registry || !registry->lookupType(keyword).match(keyword, k->second, j->second)) ) { + if(checkAlsoValues && !registry_->lookupType(keyword).match(keyword, j->second, k->second)) { mismatch.insert((*j).first + "=" + j->second + " and " + k->second); } } @@ -475,16 +464,23 @@ std::string CanonicalKey::canonicalise(const std::string& keyword, const std::st return value; } +std::string CanonicalKey::type(const std::string& keyword) const { + return ""; +} + //---------------------------------------------------------------------------------------------------------------------- -ApiKey::ApiKey(const Key& key) : - Key(key) {} +// TypedKey::TypedKey(const CanonicalKey& key) : +// Key(key), registry_(nullptr) {} + +TypedKey::TypedKey(const CanonicalKey& key, const std::shared_ptr reg) : + Key(key), registry_(reg) {} -ApiKey::ApiKey(const std::shared_ptr reg) : - Key({}, reg) {} +TypedKey::TypedKey(const std::shared_ptr reg) : + Key({}), registry_(reg) {} -ApiKey::ApiKey(const std::string &s, const Rule *rule) : - Key({}, rule ? rule->registry() : nullptr) { +TypedKey::TypedKey(const std::string &s, const Rule *rule) : + Key({}), registry_(rule ? rule->registry() : nullptr) { eckit::Tokenizer parse(":", true); eckit::StringList values; @@ -494,8 +490,8 @@ ApiKey::ApiKey(const std::string &s, const Rule *rule) : rule->fill(*this, values); } -ApiKey::ApiKey(const eckit::StringDict &keys, const std::shared_ptr reg) : - Key(keys, reg) { +TypedKey::TypedKey(const eckit::StringDict &keys, const std::shared_ptr reg) : + Key(keys), registry_(reg) { eckit::StringDict::const_iterator it = keys.begin(); eckit::StringDict::const_iterator end = keys.end(); @@ -504,24 +500,24 @@ ApiKey::ApiKey(const eckit::StringDict &keys, const std::shared_ptr reg) : - Key({}, reg) { +TypedKey::TypedKey(eckit::Stream& s, const std::shared_ptr reg) : + Key({}), registry_(reg) { decode(s); } -ApiKey::ApiKey(std::initializer_list> l, const std::shared_ptr reg) : - Key(l, reg) { +TypedKey::TypedKey(std::initializer_list> l, const std::shared_ptr reg) : + Key(l), registry_(reg) { for (const auto& kv : keys_) { names_.emplace_back(kv.first); } } -ApiKey ApiKey::parseString(const std::string &s, const std::shared_ptr registry) { +TypedKey TypedKey::parseString(const std::string &s, const std::shared_ptr registry) { eckit::Tokenizer parse1(","); eckit::Tokenizer parse2("="); - ApiKey ret(registry); + TypedKey ret(registry); eckit::StringList vals; parse1(s, vals); @@ -544,7 +540,26 @@ ApiKey ApiKey::parseString(const std::string &s, const std::shared_ptr reg) { + registry_ = reg; +} + +const TypesRegistry& TypedKey::registry() const { + if (!registry_) { + std::stringstream ss; + ss << "TypesRegistry has not been set for Key " << (*this) << " prior to use"; + throw eckit::SeriousBug(ss.str(), Here()); + } + + return *registry_; +} + +const void* TypedKey::reg() const { + return registry_.get(); +} + +std::string TypedKey::canonicalise(const std::string& keyword, const std::string& value) const { if (value.empty()) { return value; } else { @@ -552,8 +567,12 @@ std::string ApiKey::canonicalise(const std::string& keyword, const std::string& } } -CanonicalKey ApiKey::canonical() const { - CanonicalKey key{{}, registry_}; +std::string TypedKey::type(const std::string& keyword) const { + return this->registry().lookupType(keyword).type(); +} + +CanonicalKey TypedKey::canonical() const { + CanonicalKey key{}; for (const auto& name: names_) { auto m = keys_.find(name); diff --git a/src/fdb5/database/Key.h b/src/fdb5/database/Key.h index d1e584220..08fabaa70 100644 --- a/src/fdb5/database/Key.h +++ b/src/fdb5/database/Key.h @@ -52,13 +52,15 @@ class Key { // explicit Key(const eckit::StringDict &keys, const std::shared_ptr reg=nullptr); // Key(std::initializer_list>, const std::shared_ptr reg=nullptr); - Key(const Key &key) : keys_(key.keys_), names_(key.names_), registry_(key.registry_) {} - explicit Key(const eckit::StringDict &keys, const std::shared_ptr reg=nullptr) : keys_(keys), registry_(reg) { + Key() : keys_(), names_() {} + Key(const Key &key) : keys_(key.keys_), names_(key.names_) {} + + explicit Key(const eckit::StringDict &keys) : keys_(keys) { for (const auto& k : keys) { names_.emplace_back(k.first); } } - Key(std::initializer_list> l, const std::shared_ptr reg=nullptr) : keys_(l), registry_(reg) { + Key(std::initializer_list> l) : keys_(l) { for (const auto& k : l) { names_.emplace_back(k.first); } @@ -78,12 +80,13 @@ class Key { void clear(); + // std::vector TocEngine::databases(const CanonicalKey& key, bool match(const Key& other) const; bool match(const metkit::mars::MarsRequest& request) const; - bool match(const Key& other, const eckit::StringList& ignore) const; + // bool match(const Key& other, const eckit::StringList& ignore) const; - bool match(const std::string& key, const std::set& values) const; + // bool match(const std::string& key, const std::set& values) const; bool match(const std::string& key, const eckit::DenseSet& values) const; /// test that, if keys are present in the supplied request, they match the @@ -112,12 +115,6 @@ class Key { return s; } - // Registry is needed before we can stringise/canonicalise. - void registry(const std::shared_ptr reg); - [[ nodiscard ]] - const TypesRegistry& registry() const; - const void* reg() const; - std::string valuesToString() const; const eckit::StringList& names() const; @@ -152,6 +149,7 @@ class Key { //TODO add unit test for each type virtual std::string canonicalise(const std::string& keyword, const std::string& value) const = 0; + virtual std::string type(const std::string& keyword) const = 0; void print( std::ostream &out ) const; void decode(eckit::Stream& s); @@ -161,8 +159,6 @@ class Key { eckit::StringDict keys_; eckit::StringList names_; - - std::shared_ptr registry_; }; @@ -172,17 +168,14 @@ class CanonicalKey : public Key { public: // methods - explicit CanonicalKey(const std::shared_ptr reg = nullptr); - explicit CanonicalKey(eckit::Stream &, const std::shared_ptr reg = nullptr); - explicit CanonicalKey(const std::string &keys, const Rule* rule); - explicit CanonicalKey(const eckit::StringDict &keys, const std::shared_ptr reg=nullptr); - CanonicalKey(std::initializer_list>, const std::shared_ptr reg=nullptr); + explicit CanonicalKey(); + explicit CanonicalKey(eckit::Stream &); + // explicit CanonicalKey(const std::string &keys); + explicit CanonicalKey(const eckit::StringDict &keys); + CanonicalKey(std::initializer_list>); static CanonicalKey parseString(const std::string& s); - /// @throws When "other" doesn't contain all the keys of "this" - void validateKeysOf(const Key& other, bool checkAlsoValues = false) const; - friend eckit::Stream& operator>>(eckit::Stream& s, CanonicalKey& x) { x = CanonicalKey(s); return s; @@ -192,36 +185,50 @@ class CanonicalKey : public Key { //TODO add unit test for each type std::string canonicalise(const std::string& keyword, const std::string& value) const override; + std::string type(const std::string& keyword) const override; }; //---------------------------------------------------------------------------------------------------------------------- -class ApiKey : public Key { +class TypedKey : public Key { public: // methods - ApiKey(const Key& key); - explicit ApiKey(const std::shared_ptr reg = nullptr); - explicit ApiKey(eckit::Stream &, const std::shared_ptr reg = nullptr); - explicit ApiKey(const std::string &keys, const Rule* rule); - explicit ApiKey(const eckit::StringDict &keys, const std::shared_ptr reg=nullptr); - ApiKey(std::initializer_list>, const std::shared_ptr reg=nullptr); + // explicit TypedKey(const CanonicalKey& key); + explicit TypedKey(const CanonicalKey& key, const std::shared_ptr reg); + explicit TypedKey(const std::shared_ptr reg); + explicit TypedKey(eckit::Stream &, const std::shared_ptr reg); + explicit TypedKey(const std::string &keys, const Rule* rule); + explicit TypedKey(const eckit::StringDict &keys, const std::shared_ptr reg); + TypedKey(std::initializer_list>, const std::shared_ptr reg); /// @todo - this functionality should not be supported any more. - static ApiKey parseString(const std::string&, const std::shared_ptr reg); + static TypedKey parseString(const std::string&, const std::shared_ptr reg); CanonicalKey canonical() const; - friend eckit::Stream& operator>>(eckit::Stream& s, ApiKey& x) { - x = ApiKey(s); + /// @throws When "other" doesn't contain all the keys of "this" + void validateKeys(const Key& other, bool checkAlsoValues = false) const; + + friend eckit::Stream& operator>>(eckit::Stream& s, TypedKey& x) { + x = TypedKey(s, nullptr); return s; } + // Registry is needed before we can stringise/canonicalise. + void registry(const std::shared_ptr reg); + [[ nodiscard ]] + const TypesRegistry& registry() const; + const void* reg() const; + private: // members //TODO add unit test for each type std::string canonicalise(const std::string& keyword, const std::string& value) const override; + std::string type(const std::string& keyword) const override; + + std::shared_ptr registry_; }; diff --git a/src/fdb5/database/Manager.cc b/src/fdb5/database/Manager.cc index bcc131862..2e88a6b8b 100644 --- a/src/fdb5/database/Manager.cc +++ b/src/fdb5/database/Manager.cc @@ -276,22 +276,22 @@ eckit::URI Manager::location(const CanonicalKey& key) { return Engine::backend(name).location(key, config_); } -std::vector Manager::allLocations(const CanonicalKey& key) -{ - std::set engines = Manager::engines(key); +// std::vector Manager::allLocations(const CanonicalKey& key) +// { +// std::set engines = Manager::engines(key); - LOG_DEBUG_LIB(LibFdb5) << "Matching engines for key " << key << " -> " << engines << std::endl; +// LOG_DEBUG_LIB(LibFdb5) << "Matching engines for key " << key << " -> " << engines << std::endl; - std::vector r; // union of all locations +// std::vector r; // union of all locations - for(std::set::const_iterator i = engines.begin(); i != engines.end(); ++i) { - LOG_DEBUG_LIB(LibFdb5) << "Selected FDB engine " << *i << std::endl; - std::vector p = Engine::backend(*i).allLocations(key, config_); - r.insert(r.end(), p.begin(), p.end()); - } +// for(std::set::const_iterator i = engines.begin(); i != engines.end(); ++i) { +// LOG_DEBUG_LIB(LibFdb5) << "Selected FDB engine " << *i << std::endl; +// std::vector p = Engine::backend(*i).allLocations(key, config_); +// r.insert(r.end(), p.begin(), p.end()); +// } - return r; -} +// return r; +// } std::vector Manager::visitableLocations(const metkit::mars::MarsRequest& rq, bool all) { diff --git a/src/fdb5/database/Manager.h b/src/fdb5/database/Manager.h index fcff4a891..352eea9e5 100644 --- a/src/fdb5/database/Manager.h +++ b/src/fdb5/database/Manager.h @@ -51,7 +51,7 @@ class Manager { eckit::URI location(const CanonicalKey& key); /// Lists the roots that can be visited given a DB key - std::vector allLocations(const CanonicalKey& key); + // std::vector allLocations(const CanonicalKey& key); /// Lists the roots that can be visited given a DB key std::vector visitableLocations(const metkit::mars::MarsRequest& request, bool all); diff --git a/src/fdb5/database/MoveVisitor.h b/src/fdb5/database/MoveVisitor.h index 45c2ed783..a27e3f7b8 100644 --- a/src/fdb5/database/MoveVisitor.h +++ b/src/fdb5/database/MoveVisitor.h @@ -38,7 +38,7 @@ class MoveVisitor : public EntryVisitor { bool visitEntries() override { return false; } bool visitIndex(const Index&) override { NOTIMP; } - void visitDatum(const Field&, const ApiKey&) override { NOTIMP; } + void visitDatum(const Field&, const TypedKey&) override { NOTIMP; } void visitDatum(const Field& /*field*/, const std::string& /*keyFingerprint*/) override { NOTIMP; } protected: // members diff --git a/src/fdb5/database/MultiRetrieveVisitor.cc b/src/fdb5/database/MultiRetrieveVisitor.cc index a03f0cd61..80ed4b561 100644 --- a/src/fdb5/database/MultiRetrieveVisitor.cc +++ b/src/fdb5/database/MultiRetrieveVisitor.cc @@ -43,7 +43,7 @@ MultiRetrieveVisitor::~MultiRetrieveVisitor() { // From Visitor -bool MultiRetrieveVisitor::selectDatabase(const CanonicalKey& dbKey, const CanonicalKey&) { +bool MultiRetrieveVisitor::selectDatabase(const CanonicalKey& dbKey, const TypedKey& fullComputedKey) { LOG_DEBUG_LIB(LibFdb5) << "FDB5 selectDatabase " << dbKey << std::endl; @@ -77,7 +77,7 @@ bool MultiRetrieveVisitor::selectDatabase(const CanonicalKey& dbKey, const Canon return false; } - LOG_DEBUG_LIB(LibFdb5) << "selectDatabase opening database " << dbKey << " (type=" << newDB->dbType() << ")" << std::endl; + LOG_DEBUG_LIB(LibFdb5) << "MultiRetrieveVisitor::selectDatabase opening database " << dbKey << " (type=" << newDB->dbType() << ")" << std::endl; if (!newDB->open()) { LOG_DEBUG_LIB(LibFdb5) << "Database does not exist " << dbKey << std::endl; @@ -89,21 +89,21 @@ bool MultiRetrieveVisitor::selectDatabase(const CanonicalKey& dbKey, const Canon } } -bool MultiRetrieveVisitor::selectIndex(const CanonicalKey& idxKey, const CanonicalKey&) { +bool MultiRetrieveVisitor::selectIndex(const CanonicalKey& idxKey, const TypedKey&) { ASSERT(db_); LOG_DEBUG_LIB(LibFdb5) << "selectIndex " << idxKey << std::endl; return db_->selectIndex(idxKey); } -bool MultiRetrieveVisitor::selectDatum(const ApiKey& key, const CanonicalKey& full) { +bool MultiRetrieveVisitor::selectDatum(const TypedKey& datumKey, const TypedKey& full) { ASSERT(db_); - LOG_DEBUG_LIB(LibFdb5) << "selectDatum " << key << ", " << full << std::endl; + LOG_DEBUG_LIB(LibFdb5) << "selectDatum " << datumKey << ", " << full << std::endl; Field field; - if (db_->inspect(key, field)) { + if (db_->inspect(datumKey, field)) { CanonicalKey simplifiedKey; - for (auto k = key.begin(); k != key.end(); k++) { + for (auto k = datumKey.begin(); k != datumKey.end(); k++) { if (!k->second.empty()) simplifiedKey.set(k->first, k->second); } diff --git a/src/fdb5/database/MultiRetrieveVisitor.h b/src/fdb5/database/MultiRetrieveVisitor.h index ed0e8be6d..4c11e77f6 100644 --- a/src/fdb5/database/MultiRetrieveVisitor.h +++ b/src/fdb5/database/MultiRetrieveVisitor.h @@ -50,11 +50,11 @@ class MultiRetrieveVisitor : public ReadVisitor { // From Visitor - virtual bool selectDatabase(const CanonicalKey& dbKey, const CanonicalKey& full) override; + virtual bool selectDatabase(const CanonicalKey& dbKey, const TypedKey& fullComputedKey) override; - virtual bool selectIndex(const CanonicalKey& idxKey, const CanonicalKey& full) override; + virtual bool selectIndex(const CanonicalKey& idxKey, const TypedKey& fullComputedKey) override; - virtual bool selectDatum(const ApiKey& key, const CanonicalKey& full) override; + virtual bool selectDatum(const TypedKey& datumKey, const TypedKey& fullComputedKey) override; virtual void values(const metkit::mars::MarsRequest& request, const std::string& keyword, diff --git a/src/fdb5/database/ReadVisitor.h b/src/fdb5/database/ReadVisitor.h index af273e797..834117b4f 100644 --- a/src/fdb5/database/ReadVisitor.h +++ b/src/fdb5/database/ReadVisitor.h @@ -30,7 +30,7 @@ namespace mars { namespace fdb5 { class CanonicalKey; -class ApiKey; +class TypedKey; class TypesRegistry; class Schema; @@ -42,9 +42,9 @@ class ReadVisitor : public eckit::NonCopyable { virtual ~ReadVisitor(); - virtual bool selectDatabase(const CanonicalKey& dbKey, const CanonicalKey& full) = 0; - virtual bool selectIndex(const CanonicalKey& idxKey, const CanonicalKey& full) = 0; - virtual bool selectDatum(const ApiKey& key, const CanonicalKey& full) = 0; + virtual bool selectDatabase(const CanonicalKey& dbKey, const TypedKey& fullComputedKey) = 0; + virtual bool selectIndex(const CanonicalKey& idxKey, const TypedKey& fullComputedKey) = 0; + virtual bool selectDatum(const TypedKey& datumKey, const TypedKey& fullComputedKey) = 0; // Once we have selected a database, return its schema. Used for further iteration. virtual const Schema& databaseSchema() const = 0; diff --git a/src/fdb5/database/RetrieveVisitor.cc b/src/fdb5/database/RetrieveVisitor.cc index d8a66dbae..659700da3 100644 --- a/src/fdb5/database/RetrieveVisitor.cc +++ b/src/fdb5/database/RetrieveVisitor.cc @@ -35,7 +35,7 @@ RetrieveVisitor::~RetrieveVisitor() { // From Visitor -bool RetrieveVisitor::selectDatabase(const CanonicalKey& dbKey, const CanonicalKey&) { +bool RetrieveVisitor::selectDatabase(const CanonicalKey& dbKey, const TypedKey& fullComputedKey) { if(db_) { if(dbKey == db_->key()) { @@ -43,7 +43,7 @@ bool RetrieveVisitor::selectDatabase(const CanonicalKey& dbKey, const CanonicalK } } - LOG_DEBUG_LIB(LibFdb5) << "selectDatabase " << dbKey << std::endl; + LOG_DEBUG_LIB(LibFdb5) << "RetrieveVisitor::selectDatabase " << dbKey << std::endl; // db_.reset(DBFactory::buildReader(key)); db_ = DB::buildReader(dbKey); @@ -64,17 +64,17 @@ bool RetrieveVisitor::selectDatabase(const CanonicalKey& dbKey, const CanonicalK } } -bool RetrieveVisitor::selectIndex(const CanonicalKey& idxKey, const CanonicalKey&) { +bool RetrieveVisitor::selectIndex(const CanonicalKey& idxKey, const TypedKey& fullComputedKey) { ASSERT(db_); // eckit::Log::info() << "selectIndex " << idxKey << std::endl; return db_->selectIndex(idxKey); } -bool RetrieveVisitor::selectDatum(const ApiKey& key, const CanonicalKey&) { +bool RetrieveVisitor::selectDatum(const TypedKey& datumKey, const TypedKey& fullComputedKey) { ASSERT(db_); // eckit::Log::info() << "selectDatum " << key << ", " << full << std::endl; - eckit::DataHandle *dh = db_->retrieve(key); + eckit::DataHandle *dh = db_->retrieve(datumKey); if (dh) { gatherer_.add(dh); diff --git a/src/fdb5/database/RetrieveVisitor.h b/src/fdb5/database/RetrieveVisitor.h index d276dff0a..3602eced7 100644 --- a/src/fdb5/database/RetrieveVisitor.h +++ b/src/fdb5/database/RetrieveVisitor.h @@ -42,11 +42,11 @@ class RetrieveVisitor : public ReadVisitor { // From Visitor - virtual bool selectDatabase(const CanonicalKey& dbKey, const CanonicalKey& full) override; + virtual bool selectDatabase(const CanonicalKey& dbKey, const TypedKey& fullComputedKey) override; - virtual bool selectIndex(const CanonicalKey& idxKey, const CanonicalKey& full) override; + virtual bool selectIndex(const CanonicalKey& idxKey, const TypedKey& fullComputedKey) override; - virtual bool selectDatum(const ApiKey& key, const CanonicalKey& full) override; + virtual bool selectDatum(const TypedKey& datumKey, const TypedKey& fullComputedKey) override; virtual void values(const metkit::mars::MarsRequest& request, const std::string& keyword, diff --git a/src/fdb5/database/Store.h b/src/fdb5/database/Store.h index 5c054c893..392eac0e1 100644 --- a/src/fdb5/database/Store.h +++ b/src/fdb5/database/Store.h @@ -36,7 +36,7 @@ class Store { virtual ~Store() {} virtual eckit::DataHandle* retrieve(Field& field) const = 0; - virtual std::unique_ptr archive(const CanonicalKey& key, const void *data, eckit::Length length) = 0; + virtual std::unique_ptr archive(const CanonicalKey& idxKey, const void *data, eckit::Length length) = 0; virtual void remove(const eckit::URI& uri, std::ostream& logAlways, std::ostream& logVerbose, bool doit = true) const = 0; diff --git a/src/fdb5/database/WipeVisitor.h b/src/fdb5/database/WipeVisitor.h index 3c0244ff1..4df6e7c22 100644 --- a/src/fdb5/database/WipeVisitor.h +++ b/src/fdb5/database/WipeVisitor.h @@ -37,7 +37,7 @@ class WipeVisitor : public EntryVisitor { ~WipeVisitor() override; bool visitEntries() override { return false; } - void visitDatum(const Field&, const ApiKey&) override { NOTIMP; } + void visitDatum(const Field&, const TypedKey&) override { NOTIMP; } void visitDatum(const Field& /*field*/, const std::string& /*keyFingerprint*/) override { NOTIMP; } protected: // members diff --git a/src/fdb5/database/WriteVisitor.h b/src/fdb5/database/WriteVisitor.h index 631b42bfe..3546ebc31 100644 --- a/src/fdb5/database/WriteVisitor.h +++ b/src/fdb5/database/WriteVisitor.h @@ -41,9 +41,9 @@ class WriteVisitor : public eckit::NonCopyable { virtual ~WriteVisitor(); - virtual bool selectDatabase(const CanonicalKey& dbKey, const CanonicalKey& full) = 0; - virtual bool selectIndex(const CanonicalKey& idxKey, const CanonicalKey& full) = 0; - virtual bool selectDatum(const ApiKey& key, const CanonicalKey& full) = 0; + virtual bool selectDatabase(const CanonicalKey& dbKey, const TypedKey& fullComputedKey) = 0; + virtual bool selectIndex(const CanonicalKey& idxKey, const TypedKey& fullComputedKey) = 0; + virtual bool selectDatum(const TypedKey& datumKey, const TypedKey& fullComputedKey) = 0; // Once we have selected a database, return its schema. Used for further iteration. virtual const Schema& databaseSchema() const = 0; diff --git a/src/fdb5/pmem/PMemDB.cc b/src/fdb5/pmem/PMemDB.cc index 46456a19f..2fc4920d2 100644 --- a/src/fdb5/pmem/PMemDB.cc +++ b/src/fdb5/pmem/PMemDB.cc @@ -133,7 +133,7 @@ void PMemDB::visitEntries(EntryVisitor& visitor, bool sorted) { visitor.databaseComplete(*this); } -eckit::DataHandle * PMemDB::retrieve(const ApiKey& key) const { +eckit::DataHandle * PMemDB::retrieve(const TypedKey& key) const { Log::error() << "retrieve not implemented for " << *this << std::endl; NOTIMP; } @@ -188,7 +188,7 @@ void PMemDB::dump(std::ostream& out, bool simple) const { struct DumpVisitor : EntryVisitor { DumpVisitor(std::ostream& out) : out_(out) {} - void visitDatum(const Field& field, const ApiKey& datumKey) override { + void visitDatum(const Field& field, const TypedKey& datumKey) override { out_ << "ENTRY" << std::endl; out_ << " " << datumKey << std::endl; field.location().dump(out_); diff --git a/src/fdb5/pmem/PMemDB.h b/src/fdb5/pmem/PMemDB.h index 3547fb7b6..0819fb86c 100644 --- a/src/fdb5/pmem/PMemDB.h +++ b/src/fdb5/pmem/PMemDB.h @@ -77,7 +77,7 @@ class PMemDB : public DB { std::vector metadataPaths() const; const Schema& schema() const override; - virtual eckit::DataHandle *retrieve(const ApiKey& key) const; + virtual eckit::DataHandle *retrieve(const TypedKey& key) const; virtual void archive(const CanonicalKey& key, const void *data, eckit::Length length); virtual void axis(const std::string &keyword, eckit::StringSet &s) const; diff --git a/src/fdb5/pmem/PMemDBReader.cc b/src/fdb5/pmem/PMemDBReader.cc index 22a1cd9cf..cfa9a2ea0 100644 --- a/src/fdb5/pmem/PMemDBReader.cc +++ b/src/fdb5/pmem/PMemDBReader.cc @@ -73,7 +73,7 @@ void PMemDBReader::axis(const std::string& keyword, eckit::StringSet& s) const { } -eckit::DataHandle* PMemDBReader::retrieve(const ApiKey& key) const { +eckit::DataHandle* PMemDBReader::retrieve(const TypedKey& key) const { LOG_DEBUG_LIB(LibFdb5) << "Trying to retrieve key " << key << std::endl; LOG_DEBUG_LIB(LibFdb5) << "From index " << currentIndex_ << std::endl; diff --git a/src/fdb5/pmem/PMemDBReader.h b/src/fdb5/pmem/PMemDBReader.h index 59c072561..38266b83e 100644 --- a/src/fdb5/pmem/PMemDBReader.h +++ b/src/fdb5/pmem/PMemDBReader.h @@ -42,7 +42,7 @@ class PMemDBReader : public PMemDB { virtual ~PMemDBReader() override; virtual bool selectIndex(const CanonicalKey& idxKey); - virtual eckit::DataHandle* retrieve(const ApiKey& key) const; + virtual eckit::DataHandle* retrieve(const TypedKey& key) const; virtual std::vector indexes(bool sorted) const; diff --git a/src/fdb5/pmem/PMemEngine.cc b/src/fdb5/pmem/PMemEngine.cc index 447edff12..47fdb1fb8 100644 --- a/src/fdb5/pmem/PMemEngine.cc +++ b/src/fdb5/pmem/PMemEngine.cc @@ -156,10 +156,10 @@ std::vector PMemEngine::databases(const std::set& return result; } -std::vector PMemEngine::allLocations(const CanonicalKey& key, const Config& config) const -{ - return databases(key, PoolManager(config).allPools(key), config); -} +// std::vector PMemEngine::allLocations(const CanonicalKey& key, const Config& config) const +// { +// return databases(key, PoolManager(config).allPools(key), config); +// } std::vector PMemEngine::visitableLocations(const CanonicalKey& key, const Config& config) const { diff --git a/src/fdb5/pmem/PMemEngine.h b/src/fdb5/pmem/PMemEngine.h index 45a7e5e9e..f836f5007 100644 --- a/src/fdb5/pmem/PMemEngine.h +++ b/src/fdb5/pmem/PMemEngine.h @@ -57,7 +57,7 @@ class PMemEngine : public fdb5::Engine { virtual bool canHandle(const eckit::PathName& path) const; - virtual std::vector allLocations(const CanonicalKey& key, const Config& config) const; + // virtual std::vector allLocations(const CanonicalKey& key, const Config& config) const; virtual std::vector visitableLocations(const CanonicalKey& key, const Config& config) const; virtual std::vector visitableLocations(const metkit::mars::MarsRequest& rq, const Config& config) const; diff --git a/src/fdb5/pmem/PMemIndex.cc b/src/fdb5/pmem/PMemIndex.cc index e080ddf05..49f0ace78 100755 --- a/src/fdb5/pmem/PMemIndex.cc +++ b/src/fdb5/pmem/PMemIndex.cc @@ -80,7 +80,7 @@ void PMemIndex::close() { // Intentionally left blank. Indices neither opened nor closed (part of open DB). } -void PMemIndex::add(const ApiKey& key, const Field &field) { +void PMemIndex::add(const TypedKey& key, const Field &field) { struct Inserter : FieldLocationVisitor { Inserter(PBranchingNode& indexNode, const CanonicalKey& key, DataPoolManager& poolManager) : diff --git a/src/fdb5/pmem/PMemIndex.h b/src/fdb5/pmem/PMemIndex.h index 606ae0dac..d69d2aa19 100755 --- a/src/fdb5/pmem/PMemIndex.h +++ b/src/fdb5/pmem/PMemIndex.h @@ -58,7 +58,7 @@ class PMemIndex : public IndexBase { virtual void reopen(); virtual bool get( const CanonicalKey& key, Field &field ) const; - virtual void add( const ApiKey& key, const Field &field ); + virtual void add( const TypedKey& key, const Field &field ); virtual void flush(); virtual void encode(eckit::Stream &s) const override; virtual void entries(EntryVisitor &visitor) const; diff --git a/src/fdb5/pmem/PMemStats.h b/src/fdb5/pmem/PMemStats.h index b5d1b565a..2dc1e9796 100644 --- a/src/fdb5/pmem/PMemStats.h +++ b/src/fdb5/pmem/PMemStats.h @@ -162,7 +162,7 @@ class PMemStatsReportVisitor : public virtual StatsReportVisitor { bool visitDatabase(const DB& db) override; void visitDatum(const Field& field, const std::string& keyFingerprint) override; - void visitDatum(const Field& field, const ApiKey& datumKey) override { NOTIMP; } + void visitDatum(const Field& field, const TypedKey& datumKey) override { NOTIMP; } // This visitor is only legit for one DB - so don't reset database void databaseComplete(const DB& db) override; diff --git a/src/fdb5/pmem/PoolManager.cc b/src/fdb5/pmem/PoolManager.cc index acb928661..4a5fc5e41 100644 --- a/src/fdb5/pmem/PoolManager.cc +++ b/src/fdb5/pmem/PoolManager.cc @@ -292,7 +292,7 @@ std::vector PoolManager::visitablePools(const CanonicalKey& key) { } std::vector PoolManager::visitablePools(const metkit::mars::MarsRequest& request) { - std::set keys; + std::set keys; config_.schema().matchFirstLevel(request, keys, ""); return visitablePools(keys); } diff --git a/src/fdb5/rules/MatchAny.cc b/src/fdb5/rules/MatchAny.cc index bc693f95e..56b0d7f92 100644 --- a/src/fdb5/rules/MatchAny.cc +++ b/src/fdb5/rules/MatchAny.cc @@ -26,7 +26,7 @@ MatchAny::~MatchAny() { bool MatchAny::match(const std::string &keyword, const CanonicalKey& key) const { - CanonicalKey::const_iterator i = key.find(keyword); + auto i = key.find(keyword); if (i == key.end()) { return false; diff --git a/src/fdb5/rules/MatchOptional.cc b/src/fdb5/rules/MatchOptional.cc index 2ead9ed91..d20f04ada 100644 --- a/src/fdb5/rules/MatchOptional.cc +++ b/src/fdb5/rules/MatchOptional.cc @@ -40,7 +40,7 @@ bool MatchOptional::optional() const { return true; } -void MatchOptional::fill(Key& key, const std::string &keyword, const std::string& value) const { +void MatchOptional::fill(TypedKey& key, const std::string &keyword, const std::string& value) const { if (!value.empty()) { key.push(keyword, value); } diff --git a/src/fdb5/rules/MatchOptional.h b/src/fdb5/rules/MatchOptional.h index a6d5ef017..69952f390 100644 --- a/src/fdb5/rules/MatchOptional.h +++ b/src/fdb5/rules/MatchOptional.h @@ -44,7 +44,7 @@ class MatchOptional : public Matcher { virtual const std::vector& values(const metkit::mars::MarsRequest& rq, const std::string& keyword) const override; virtual void print( std::ostream &out ) const override; virtual const std::string &defaultValue() const override; - virtual void fill(Key& key, const std::string &keyword, const std::string& value) const override; + virtual void fill(TypedKey& key, const std::string &keyword, const std::string& value) const override; std::vector default_; diff --git a/src/fdb5/rules/MatchValue.cc b/src/fdb5/rules/MatchValue.cc index db3907e28..7dcef4a82 100644 --- a/src/fdb5/rules/MatchValue.cc +++ b/src/fdb5/rules/MatchValue.cc @@ -25,7 +25,7 @@ MatchValue::~MatchValue() { } bool MatchValue::match(const std::string &keyword, const CanonicalKey& key) const { - CanonicalKey::const_iterator i = key.find(keyword); + auto i = key.find(keyword); if (i == key.end()) { return false; diff --git a/src/fdb5/rules/Matcher.cc b/src/fdb5/rules/Matcher.cc index f454fa7d5..e084067ec 100644 --- a/src/fdb5/rules/Matcher.cc +++ b/src/fdb5/rules/Matcher.cc @@ -37,7 +37,7 @@ const std::vector &Matcher::values(const metkit::mars::MarsRequest& return rq.values(keyword); } -void Matcher::fill(Key& key, const std::string &keyword, const std::string& value) const { +void Matcher::fill(TypedKey& key, const std::string &keyword, const std::string& value) const { key.push(keyword, value); } diff --git a/src/fdb5/rules/Matcher.h b/src/fdb5/rules/Matcher.h index 768e94c31..38af5d866 100644 --- a/src/fdb5/rules/Matcher.h +++ b/src/fdb5/rules/Matcher.h @@ -31,6 +31,7 @@ namespace mars { namespace fdb5 { class Key; +class TypedKey; class CanonicalKey; class TypesRegistry; @@ -51,7 +52,7 @@ class Matcher : public eckit::NonCopyable { virtual const std::string &defaultValue() const; virtual bool match(const std::string &keyword, const CanonicalKey& key) const = 0; - virtual void fill(Key& key, const std::string &keyword, const std::string& value) const; + virtual void fill(TypedKey& key, const std::string &keyword, const std::string& value) const; virtual void dump(std::ostream &s, const std::string &keyword, const TypesRegistry ®istry) const = 0; diff --git a/src/fdb5/rules/Predicate.cc b/src/fdb5/rules/Predicate.cc index 98f8f793e..4796ba311 100644 --- a/src/fdb5/rules/Predicate.cc +++ b/src/fdb5/rules/Predicate.cc @@ -10,6 +10,7 @@ #include "metkit/mars/MarsRequest.h" +#include "fdb5/database/Key.h" #include "fdb5/rules/Predicate.h" #include "fdb5/rules/Matcher.h" @@ -47,6 +48,10 @@ bool Predicate::optional() const { return matcher_->optional(); } +// const std::string &Predicate::value(const TypedKey& key) const { +// return matcher_->value(key, keyword_); +// } + const std::string &Predicate::value(const CanonicalKey& key) const { return matcher_->value(key, keyword_); } @@ -55,7 +60,7 @@ const std::vector& Predicate::values(const metkit::mars::MarsReques return matcher_->values(rq, keyword_); } -void Predicate::fill(Key& key, const std::string& value) const { +void Predicate::fill(TypedKey& key, const std::string& value) const { matcher_->fill(key, keyword_, value); } diff --git a/src/fdb5/rules/Predicate.h b/src/fdb5/rules/Predicate.h index 275923153..fa63aac97 100644 --- a/src/fdb5/rules/Predicate.h +++ b/src/fdb5/rules/Predicate.h @@ -44,9 +44,10 @@ class Predicate : public eckit::NonCopyable { bool match(const CanonicalKey& key) const; void dump( std::ostream &s, const TypesRegistry ®istry ) const; - void fill(Key& key, const std::string& value) const; + void fill(TypedKey& key, const std::string& value) const; const std::string &value(const CanonicalKey& key) const; + // const std::string &value(const TypedKey& key) const; const std::vector& values(const metkit::mars::MarsRequest& rq) const; const std::string &defaultValue() const; diff --git a/src/fdb5/rules/Rule.cc b/src/fdb5/rules/Rule.cc index a4370d9bc..6dc9ea460 100644 --- a/src/fdb5/rules/Rule.cc +++ b/src/fdb5/rules/Rule.cc @@ -52,8 +52,8 @@ Rule::~Rule() { void Rule::expand( const metkit::mars::MarsRequest &request, std::vector::const_iterator cur, size_t depth, - std::vector &keys, - CanonicalKey& full, + std::vector &keys, + TypedKey& fullComputedKey, ReadVisitor &visitor) const { ASSERT(depth < 3); @@ -65,24 +65,24 @@ void Rule::expand( const metkit::mars::MarsRequest &request, // TODO: join these 2 methods if (rules_.empty()) { ASSERT(depth == 2); /// we have 3 levels ATM - if (!visitor.selectDatum( keys[2], full)) { + if (!visitor.selectDatum( keys[2], fullComputedKey)) { return; // This it not useful } } else { switch (depth) { case 0: - if (!visitor.selectDatabase(keys[0].canonical(), full)) { + if (!visitor.selectDatabase(keys[0].canonical(), fullComputedKey)) { return; }; // Here we recurse on the database's schema (rather than the master schema) - ASSERT(keys[0] == full); + ASSERT(keys[0] == fullComputedKey); visitor.databaseSchema().expandSecond(request, visitor, keys[0].canonical()); return; case 1: - if (!visitor.selectIndex(keys[1].canonical(), full)) { + if (!visitor.selectIndex(keys[1].canonical(), fullComputedKey)) { return; } break; @@ -93,7 +93,7 @@ void Rule::expand( const metkit::mars::MarsRequest &request, } for (std::vector::const_iterator i = rules_.begin(); i != rules_.end(); ++i ) { - (*i)->expand(request, visitor, depth + 1, keys, full); + (*i)->expand(request, visitor, depth + 1, keys, fullComputedKey); } } return; @@ -109,7 +109,7 @@ void Rule::expand( const metkit::mars::MarsRequest &request, // eckit::Log::info() << "keyword " << keyword << " values " << values << std::endl; - ApiKey& k = keys[depth]; + TypedKey& k = keys[depth]; if (values.empty() && (*cur)->optional()) { values.push_back((*cur)->defaultValue()); @@ -118,28 +118,28 @@ void Rule::expand( const metkit::mars::MarsRequest &request, for (eckit::StringList::const_iterator i = values.begin(); i != values.end(); ++i) { k.push(keyword, *i); - full.push(keyword, *i); + fullComputedKey.push(keyword, *i); if ((*cur)->match(k.canonical())) - expand(request, next, depth, keys, full, visitor); + expand(request, next, depth, keys, fullComputedKey, visitor); - full.pop(keyword); + fullComputedKey.pop(keyword); k.pop(keyword); } } -void Rule::expand(const metkit::mars::MarsRequest &request, ReadVisitor &visitor, size_t depth, std::vector &keys, CanonicalKey& full) const { +void Rule::expand(const metkit::mars::MarsRequest &request, ReadVisitor &visitor, size_t depth, std::vector &keys, TypedKey& fullComputedKey) const { ASSERT(keys.size() == 3); - expand(request, predicates_.begin(), depth, keys, full, visitor); + expand(request, predicates_.begin(), depth, keys, fullComputedKey, visitor); } -void Rule::expand( const CanonicalKey& field, +void Rule::expand( const CanonicalKey& initialFieldKey, std::vector::const_iterator cur, size_t depth, - std::vector &keys, - CanonicalKey& full, + std::vector &keys, + TypedKey& fullComputedKey, WriteVisitor &visitor) const { static bool matchFirstFdbRule = eckit::Resource("matchFirstFdbRule", true); @@ -150,7 +150,6 @@ void Rule::expand( const CanonicalKey& field, ASSERT(depth < 3); - if (cur == predicates_.end()) { keys[depth].registry(registry()); @@ -168,24 +167,24 @@ void Rule::expand( const CanonicalKey& field, throw eckit::SeriousBug(oss.str()); } visitor.rule(this); - visitor.selectDatum( keys[2], full); + visitor.selectDatum( keys[2], fullComputedKey); } else { switch (depth) { case 0: if (keys[0] != visitor.prev_[0] /*|| keys[0].registry() != visitor.prev_[0].registry()*/) { - visitor.selectDatabase(keys[0].canonical(), full); + visitor.selectDatabase(keys[0].canonical(), fullComputedKey); visitor.prev_[0] = keys[0].canonical(); visitor.prev_[1] = CanonicalKey{}; } // Here we recurse on the database's schema (rather than the master schema) - visitor.databaseSchema().expandSecond(field, visitor, keys[0].canonical()); + visitor.databaseSchema().expandSecond(initialFieldKey, visitor, keys[0].canonical()); return; case 1: if (keys[1] != visitor.prev_[1] /*|| keys[1].registry() != visitor.prev_[1].registry()*/) { - visitor.selectIndex(keys[1].canonical(), full); + visitor.selectIndex(keys[1].canonical(), fullComputedKey); visitor.prev_[1] = keys[1].canonical(); } break; @@ -196,7 +195,7 @@ void Rule::expand( const CanonicalKey& field, } for (std::vector::const_iterator i = rules_.begin(); i != rules_.end(); ++i ) { - (*i)->expand(field, visitor, depth + 1, keys, full); + (*i)->expand(initialFieldKey, visitor, depth + 1, keys, fullComputedKey); } } return; @@ -206,56 +205,55 @@ void Rule::expand( const CanonicalKey& field, ++next; const std::string &keyword = (*cur)->keyword(); - const std::string &value = (*cur)->value(field); - - ApiKey& k = keys[depth]; + const std::string &value = (*cur)->value(initialFieldKey); + TypedKey& k = keys[depth]; k.push(keyword, value); - full.push(keyword, value); + fullComputedKey.push(keyword, value); if ((*cur)->match(k.canonical())) { - expand(field, next, depth, keys, full, visitor); + expand(initialFieldKey, next, depth, keys, fullComputedKey, visitor); } - full.pop(keyword); + fullComputedKey.pop(keyword); k.pop(keyword); } -void Rule::expand(const CanonicalKey& field, WriteVisitor &visitor, size_t depth, std::vector &keys, CanonicalKey& full) const { +void Rule::expand(const CanonicalKey& initialFieldKey, WriteVisitor &visitor, size_t depth, std::vector &keys, TypedKey& fullComputedKey) const { ASSERT(keys.size() == 3); - expand(field, predicates_.begin(), depth, keys, full, visitor); + expand(initialFieldKey, predicates_.begin(), depth, keys, fullComputedKey, visitor); } -void Rule::expandFirstLevel( const CanonicalKey& dbKey, std::vector::const_iterator cur, CanonicalKey& result, bool& found) const { +// void Rule::expandFirstLevel( const CanonicalKey& dbKey, std::vector::const_iterator cur, CanonicalKey& result, bool& found) const { - if (cur == predicates_.end()) { - found = true; - return; - } +// if (cur == predicates_.end()) { +// found = true; +// return; +// } - std::vector::const_iterator next = cur; - ++next; +// std::vector::const_iterator next = cur; +// ++next; - const std::string &keyword = (*cur)->keyword(); - const std::string &value = (*cur)->value(dbKey); +// const std::string &keyword = (*cur)->keyword(); +// const std::string &value = (*cur)->value(dbKey); - result.push(keyword, value); +// result.push(keyword, value); - if ((*cur)->match(result)) { - expandFirstLevel(dbKey, next, result, found); - } +// if ((*cur)->match(result)) { +// expandFirstLevel(dbKey, next, result, found); +// } - if (!found) { - result.pop(keyword); - } -} +// if (!found) { +// result.pop(keyword); +// } +// } -void Rule::expandFirstLevel(const CanonicalKey& dbKey, CanonicalKey& result, bool& found) const { - expandFirstLevel(dbKey, predicates_.begin(), result, found); -} +// void Rule::expandFirstLevel(const CanonicalKey& dbKey, CanonicalKey& result, bool& found) const { +// expandFirstLevel(dbKey, predicates_.begin(), result, found); +// } -void Rule::expandFirstLevel(const metkit::mars::MarsRequest& rq, std::vector::const_iterator cur, CanonicalKey& result, bool& found) const { +void Rule::expandFirstLevel(const metkit::mars::MarsRequest& rq, std::vector::const_iterator cur, TypedKey& result, bool& found) const { if (cur == predicates_.end()) { found = true; @@ -275,7 +273,7 @@ void Rule::expandFirstLevel(const metkit::mars::MarsRequest& rq, std::vector
match(result)) {
+        if ((*cur)->match(result.canonical())) {
             expandFirstLevel(rq, next, result, found);
         }
 
@@ -287,13 +285,14 @@ void Rule::expandFirstLevel(const metkit::mars::MarsRequest& rq, std::vector
::const_iterator cur, CanonicalKey& tmp, std::set& result, const char* missing) const {
 
+    // std::cout << "Rule::matchFirstLevel  dbKey " << dbKey << "  tmp " << tmp << "  result.size() " << result.size() << std::endl;
     if (cur == predicates_.end()) {
         if (tmp.match(dbKey)) {
             result.insert(tmp);
@@ -324,7 +323,7 @@ void Rule::matchFirstLevel( const CanonicalKey& dbKey, std::vector:
 }
 
 void Rule::matchFirstLevel(const CanonicalKey& dbKey,  std::set& result, const char* missing) const {
-    CanonicalKey tmp;
+    CanonicalKey tmp{};
     matchFirstLevel(dbKey, predicates_.begin(), tmp, result, missing);
 }
 
@@ -362,7 +361,7 @@ void Rule::matchFirstLevel(const metkit::mars::MarsRequest& request, std::vector
 }
 
 void Rule::matchFirstLevel(const metkit::mars::MarsRequest& request,  std::set& result, const char* missing) const {
-    CanonicalKey tmp(registry());
+    CanonicalKey tmp{};
     matchFirstLevel(request, predicates_.begin(), tmp, result, missing);
 }
 
@@ -395,7 +394,7 @@ const Rule* Rule::ruleFor(const std::vector &keys, size_t de
     return 0;
 }
 
-void Rule::fill(Key& key, const eckit::StringList& values) const {
+void Rule::fill(TypedKey& key, const eckit::StringList& values) const {
 
     // See FDB-103. This is a hack to work around the indexing abstraction
     // being leaky.
diff --git a/src/fdb5/rules/Rule.h b/src/fdb5/rules/Rule.h
index 4b811dad5..0b75c7184 100644
--- a/src/fdb5/rules/Rule.h
+++ b/src/fdb5/rules/Rule.h
@@ -38,7 +38,7 @@ class ReadVisitor;
 class WriteVisitor;
 class Key;
 class CanonicalKey;
-class ApiKey;
+class TypedKey;
 
 //----------------------------------------------------------------------------------------------------------------------
 
@@ -65,17 +65,17 @@ class Rule : public eckit::NonCopyable {
     void expand(const metkit::mars::MarsRequest &request,
                 ReadVisitor &Visitor,
                 size_t depth,
-                std::vector &keys,
-                CanonicalKey& full) const;
+                std::vector &keys,
+                TypedKey& fullComputedKey) const;
 
-    void expand(const CanonicalKey& field,
+    void expand(const CanonicalKey& initialFieldKey,
                 WriteVisitor &Visitor,
                 size_t depth,
-                std::vector &keys,
-                CanonicalKey& full) const;
+                std::vector &keys,
+                TypedKey& fullComputedKey) const;
 
     const Rule* ruleFor(const std::vector &keys, size_t depth) const;
-    void fill(Key& key, const eckit::StringList& values) const;
+    void fill(TypedKey& key, const eckit::StringList& values) const;
 
 
     size_t depth() const;
@@ -93,21 +93,21 @@ class Rule : public eckit::NonCopyable {
     void expand(const metkit::mars::MarsRequest &request,
                 std::vector::const_iterator cur,
                 size_t depth,
-                std::vector &keys,
-                CanonicalKey& full,
+                std::vector &keys,
+                TypedKey& fullComputedKey,
                 ReadVisitor &Visitor) const;
 
-    void expand(const CanonicalKey& field,
+    void expand(const CanonicalKey& initialFieldKey,
                 std::vector::const_iterator cur,
                 size_t depth,
-                std::vector &keys,
-                CanonicalKey& full,
+                std::vector &keys,
+                TypedKey& fullComputedKey,
                 WriteVisitor &Visitor) const;
 
-    void expandFirstLevel(const CanonicalKey& dbKey, std::vector::const_iterator cur, CanonicalKey& result, bool& done) const;
-    void expandFirstLevel(const CanonicalKey& dbKey,  CanonicalKey& result, bool& done) const ;
-    void expandFirstLevel(const metkit::mars::MarsRequest& request, std::vector::const_iterator cur, CanonicalKey& result, bool& done) const;
-    void expandFirstLevel(const metkit::mars::MarsRequest& request,  CanonicalKey& result, bool& done) const;
+    // void expandFirstLevel(const CanonicalKey& dbKey, std::vector::const_iterator cur, CanonicalKey& result, bool& done) const;
+    // void expandFirstLevel(const CanonicalKey& dbKey,  CanonicalKey& result, bool& done) const ;
+    void expandFirstLevel(const metkit::mars::MarsRequest& request, std::vector::const_iterator cur, TypedKey& result, bool& done) const;
+    void expandFirstLevel(const metkit::mars::MarsRequest& request,  TypedKey& result, bool& done) const;
 
     void matchFirstLevel(const CanonicalKey& dbKey, std::vector::const_iterator cur, CanonicalKey& tmp, std::set& result, const char* missing) const;
     void matchFirstLevel(const CanonicalKey& dbKey, std::set& result, const char* missing) const ;
diff --git a/src/fdb5/rules/Schema.cc b/src/fdb5/rules/Schema.cc
index eb9a3d9bd..ca1715da8 100644
--- a/src/fdb5/rules/Schema.cc
+++ b/src/fdb5/rules/Schema.cc
@@ -52,26 +52,25 @@ const Rule*  Schema::ruleFor(const CanonicalKey& dbKey, const CanonicalKey& idxK
 }
 
 void Schema::expand(const metkit::mars::MarsRequest &request, ReadVisitor &visitor) const {
-    CanonicalKey full(registry());
-    std::vector keys(3);
-    for (auto& k : keys) k.registry(registry());
+    TypedKey fullComputedKey{registry()};
+    std::vector keys(3, TypedKey{{}, registry()});
+    // for (auto& k : keys) k.registry(registry());
 
     for (Rule* r : rules_) {
 		// eckit::Log::info() << "Rule " << **i <<  std::endl;
 		// (*i)->dump(eckit::Log::info());
-		r->expand(request, visitor, 0, keys, full);
+		r->expand(request, visitor, 0, keys, fullComputedKey);
     }
 }
 
 void Schema::expand(const CanonicalKey& field, WriteVisitor &visitor) const {
-    CanonicalKey full(registry());
-    std::vector keys(3);
-    for (auto& k : keys) k.registry(registry());
+    TypedKey fullComputedKey{registry()};
+    std::vector keys(3, TypedKey{{}, registry()});
 
     visitor.rule(0); // reset to no rule so we verify that we pick at least one
 
     for (Rule* r : rules_) {
-        r->expand(field, visitor, 0, keys, full);
+        r->expand(field, visitor, 0, keys, fullComputedKey);
     }
 }
 
@@ -86,14 +85,11 @@ void Schema::expandSecond(const metkit::mars::MarsRequest& request, ReadVisitor&
     }
     ASSERT(dbRule);
 
-    CanonicalKey full = dbKey;
-    std::vector keys(3);
-    keys[0] = dbKey;
-    keys[1].registry(registry());
-    keys[2].registry(registry());
+    std::vector keys(3, TypedKey{{}, registry()});
+    TypedKey fullComputedKey = keys[0] = TypedKey{dbKey, registry()};
 
     for (std::vector:: const_iterator i = dbRule->rules_.begin(); i != dbRule->rules_.end(); ++i) {
-        (*i)->expand(request, visitor, 1, keys, full);
+        (*i)->expand(request, visitor, 1, keys, fullComputedKey);
     }
 }
 
@@ -108,26 +104,23 @@ void Schema::expandSecond(const CanonicalKey& field, WriteVisitor& visitor, cons
     }
     ASSERT(dbRule);
 
-    CanonicalKey full = dbKey;
-    std::vector keys(3);
-    keys[0] = dbKey;
-    keys[1].registry(registry());
-    keys[2].registry(registry());
+    std::vector keys(3, TypedKey{{}, registry()});
+    TypedKey fullComputedKey = keys[0] = TypedKey{dbKey, registry()};
 
     for (std::vector:: const_iterator i = dbRule->rules_.begin(); i != dbRule->rules_.end(); ++i) {
-        (*i)->expand(field, visitor, 1, keys, full);
+        (*i)->expand(field, visitor, 1, keys, fullComputedKey);
     }
 }
 
-bool Schema::expandFirstLevel(const CanonicalKey& dbKey,  CanonicalKey& result) const {
-    bool found = false;
-    for (std::vector::const_iterator i = rules_.begin(); i != rules_.end() && !found; ++i ) {
-        (*i)->expandFirstLevel(dbKey, result, found);
-    }
-    return found;
-}
+// bool Schema::expandFirstLevel(const CanonicalKey& dbKey,  CanonicalKey& result) const {
+//     bool found = false;
+//     for (std::vector::const_iterator i = rules_.begin(); i != rules_.end() && !found; ++i ) {
+//         (*i)->expandFirstLevel(dbKey, result, found);
+//     }
+//     return found;
+// }
 
-bool Schema::expandFirstLevel(const metkit::mars::MarsRequest& request, CanonicalKey& result) const {
+bool Schema::expandFirstLevel(const metkit::mars::MarsRequest& request, TypedKey& result) const {
     bool found = false;
     for (const Rule* rule : rules_) {
         rule->expandFirstLevel(request, result, found);
@@ -140,14 +133,14 @@ bool Schema::expandFirstLevel(const metkit::mars::MarsRequest& request, Canonica
 }
 
 void Schema::matchFirstLevel(const CanonicalKey& dbKey,  std::set &result, const char* missing) const {
-    for (std::vector::const_iterator i = rules_.begin(); i != rules_.end(); ++i ) {
-        (*i)->matchFirstLevel(dbKey, result, missing);
+    for (const Rule* rule : rules_) {
+        rule->matchFirstLevel(dbKey, result, missing);
     }
 }
 
 void Schema::matchFirstLevel(const metkit::mars::MarsRequest& request,  std::set& result, const char* missing) const {
-    for (std::vector::const_iterator i = rules_.begin(); i != rules_.end(); ++i ) {
-        (*i)->matchFirstLevel(request, result, missing);
+    for (const Rule* rule : rules_) {
+        rule->matchFirstLevel(request, result, missing);
     }
 }
 
diff --git a/src/fdb5/rules/Schema.h b/src/fdb5/rules/Schema.h
index 4f4d5b9c1..407c1fbb3 100644
--- a/src/fdb5/rules/Schema.h
+++ b/src/fdb5/rules/Schema.h
@@ -58,8 +58,8 @@ class Schema : private eckit::NonCopyable {
     void expandSecond(const CanonicalKey& field, WriteVisitor &visitor, const CanonicalKey& dbKey) const;
     void expandSecond(const metkit::mars::MarsRequest& request, ReadVisitor &visitor, const CanonicalKey& dbKey) const;
 
-    bool expandFirstLevel(const CanonicalKey& dbKey,  CanonicalKey& result) const ;
-    bool expandFirstLevel(const metkit::mars::MarsRequest& request,  CanonicalKey& result) const ;
+    // bool expandFirstLevel(const CanonicalKey& dbKey,  CanonicalKey& result) const ;
+    bool expandFirstLevel(const metkit::mars::MarsRequest& request,  TypedKey& result) const ;
     void matchFirstLevel(const CanonicalKey& dbKey,  std::set &result, const char* missing) const ;
     void matchFirstLevel(const metkit::mars::MarsRequest& request,  std::set& result, const char* missing) const ;
 
diff --git a/src/fdb5/toc/AdoptVisitor.cc b/src/fdb5/toc/AdoptVisitor.cc
index b2c475f69..639539256 100644
--- a/src/fdb5/toc/AdoptVisitor.cc
+++ b/src/fdb5/toc/AdoptVisitor.cc
@@ -20,8 +20,8 @@ namespace fdb5 {
 
 //----------------------------------------------------------------------------------------------------------------------
 
-AdoptVisitor::AdoptVisitor(Archiver &owner, const CanonicalKey& field, const PathName &path, Offset offset, Length length) :
-    BaseArchiveVisitor(owner, field),
+AdoptVisitor::AdoptVisitor(Archiver &owner, const CanonicalKey& initialFieldKey, const PathName &path, Offset offset, Length length) :
+    BaseArchiveVisitor(owner, initialFieldKey),
     path_(path),
     offset_(offset),
     length_(length) {
@@ -29,14 +29,14 @@ AdoptVisitor::AdoptVisitor(Archiver &owner, const CanonicalKey& field, const Pat
     ASSERT(length_ > Length(0));
 }
 
-bool AdoptVisitor::selectDatum(const ApiKey& key, const CanonicalKey& full) {
+bool AdoptVisitor::selectDatum(const TypedKey& datumKey, const TypedKey& fullComputedKey) {
 
     // Log::info() << "selectDatum " << key << ", " << full << " " << length_ << std::endl;
-    checkMissingKeys(full);
+    checkMissingKeys(fullComputedKey);
 
     ASSERT(current());
 
-    current()->index(key, path_, offset_, length_);
+    current()->index(datumKey, path_, offset_, length_);
 
     return true;
 }
diff --git a/src/fdb5/toc/AdoptVisitor.h b/src/fdb5/toc/AdoptVisitor.h
index 66a6079bb..62ac8fb3c 100644
--- a/src/fdb5/toc/AdoptVisitor.h
+++ b/src/fdb5/toc/AdoptVisitor.h
@@ -33,14 +33,14 @@ class AdoptVisitor : public BaseArchiveVisitor {
 public: // methods
 
     AdoptVisitor(Archiver &owner,
-                 const CanonicalKey& field,
+                 const CanonicalKey& initialFieldKey,
                  const eckit::PathName &path,
                  eckit::Offset offset,
                  eckit::Length length);
 
 protected: // methods
 
-    virtual bool selectDatum(const ApiKey& key, const CanonicalKey& full) override;
+    virtual bool selectDatum(const TypedKey& datumKey, const TypedKey& fullComputedKey) override;
 
     virtual void print( std::ostream &out ) const override;
 
diff --git a/src/fdb5/toc/RootManager.cc b/src/fdb5/toc/RootManager.cc
index 0a48e6ec7..47fcf0a91 100644
--- a/src/fdb5/toc/RootManager.cc
+++ b/src/fdb5/toc/RootManager.cc
@@ -642,20 +642,20 @@ TocPath RootManager::directory(const CanonicalKey& key) {
     throw eckit::SeriousBug(oss.str());
 }
 
-std::vector RootManager::allRoots(const CanonicalKey& key)
-{
-    eckit::StringSet roots;
+// std::vector RootManager::allRoots(const CanonicalKey& key)
+// {
+//     eckit::StringSet roots;
 
-    std::string k = key.valuesToString();
+//     std::string k = key.valuesToString();
 
-    for (FileSpaceTable::const_iterator i = spacesTable_.begin(); i != spacesTable_.end() ; ++i) {
-        if(i->match(k)) {
-            i->all(roots);
-        }
-    }
+//     for (FileSpaceTable::const_iterator i = spacesTable_.begin(); i != spacesTable_.end() ; ++i) {
+//         if(i->match(k)) {
+//             i->all(roots);
+//         }
+//     }
 
-    return std::vector(roots.begin(), roots.end());
-}
+//     return std::vector(roots.begin(), roots.end());
+// }
 
 std::vector RootManager::visitableRoots(const std::set& keys) {
 
diff --git a/src/fdb5/toc/RootManager.h b/src/fdb5/toc/RootManager.h
index e5d3b6e96..806b63606 100644
--- a/src/fdb5/toc/RootManager.h
+++ b/src/fdb5/toc/RootManager.h
@@ -49,7 +49,7 @@ class RootManager  {
     TocPath directory(const CanonicalKey& key);
 
     /// Lists the roots that can be visited given a DB key
-    std::vector allRoots(const CanonicalKey& key);
+    // std::vector allRoots(const CanonicalKey& key);
 
     /// Lists the roots that can be visited given a DB key
     std::vector visitableRoots(const CanonicalKey& key);
diff --git a/src/fdb5/toc/TocCatalogueReader.cc b/src/fdb5/toc/TocCatalogueReader.cc
index f8ad0a31a..dbc06a7e2 100644
--- a/src/fdb5/toc/TocCatalogueReader.cc
+++ b/src/fdb5/toc/TocCatalogueReader.cc
@@ -104,7 +104,7 @@ void TocCatalogueReader::close() {
     }
 }
 
-bool TocCatalogueReader::retrieve(const ApiKey& key, Field& field) const {
+bool TocCatalogueReader::retrieve(const TypedKey& key, Field& field) const {
     LOG_DEBUG_LIB(LibFdb5) << "Trying to retrieve key " << key << std::endl;
     LOG_DEBUG_LIB(LibFdb5) << "Scanning indexes " << matching_.size() << std::endl;
 
diff --git a/src/fdb5/toc/TocCatalogueReader.h b/src/fdb5/toc/TocCatalogueReader.h
index 9a055d84e..1e99c2a53 100644
--- a/src/fdb5/toc/TocCatalogueReader.h
+++ b/src/fdb5/toc/TocCatalogueReader.h
@@ -49,7 +49,7 @@ class TocCatalogueReader : public TocCatalogue, public CatalogueReader {
     
     bool axis(const std::string &keyword, eckit::StringSet &s) const override;
 
-    bool retrieve(const ApiKey& key, Field& field) const override;
+    bool retrieve(const TypedKey& key, Field& field) const override;
 
     void print( std::ostream &out ) const override;
 
diff --git a/src/fdb5/toc/TocCatalogueWriter.cc b/src/fdb5/toc/TocCatalogueWriter.cc
index 3553f8c06..0b788949c 100644
--- a/src/fdb5/toc/TocCatalogueWriter.cc
+++ b/src/fdb5/toc/TocCatalogueWriter.cc
@@ -121,7 +121,7 @@ void TocCatalogueWriter::close() {
     closeIndexes();
 }
 
-void TocCatalogueWriter::index(const ApiKey& key, const eckit::URI &uri, eckit::Offset offset, eckit::Length length) {
+void TocCatalogueWriter::index(const TypedKey& key, const eckit::URI &uri, eckit::Offset offset, eckit::Length length) {
     dirty_ = true;
 
     if (current_.null()) {
@@ -151,7 +151,7 @@ void TocCatalogueWriter::reconsolidateIndexesAndTocs() {
             writer_(writer) {}
         ~ConsolidateIndexVisitor() override {}
     private:
-        void visitDatum(const Field& field, const ApiKey& datumKey) override {
+        void visitDatum(const Field& field, const TypedKey& datumKey) override {
             // TODO: Do a sneaky schema.expand() here, prepopulated with the current DB/index/Rule,
             //       to extract the full key, including optional values.
             const TocFieldLocation& location(static_cast(field.location()));
@@ -294,7 +294,7 @@ bool TocCatalogueWriter::enabled(const ControlIdentifier& controlIdentifier) con
     return TocCatalogue::enabled(controlIdentifier);
 }
 
-void TocCatalogueWriter::archive(const ApiKey& key, std::unique_ptr fieldLocation) {
+void TocCatalogueWriter::archive(const TypedKey& key, std::unique_ptr fieldLocation) {
     dirty_ = true;
 
     if (current_.null()) {
diff --git a/src/fdb5/toc/TocCatalogueWriter.h b/src/fdb5/toc/TocCatalogueWriter.h
index 0941f557b..ac649e07a 100644
--- a/src/fdb5/toc/TocCatalogueWriter.h
+++ b/src/fdb5/toc/TocCatalogueWriter.h
@@ -43,7 +43,7 @@ class TocCatalogueWriter : public TocCatalogue, public CatalogueWriter {
     virtual ~TocCatalogueWriter() override;
 
     /// Used for adopting & indexing external data to the TOC dir
-    void index(const ApiKey& key, const eckit::URI &uri, eckit::Offset offset, eckit::Length length) override;
+    void index(const TypedKey& key, const eckit::URI &uri, eckit::Offset offset, eckit::Length length) override;
 
     void reconsolidate() override { reconsolidateIndexesAndTocs(); }
 
@@ -70,7 +70,7 @@ class TocCatalogueWriter : public TocCatalogue, public CatalogueWriter {
     void clean() override;
     void close() override;
 
-    void archive(const ApiKey& key, std::unique_ptr fieldLocation) override;
+    void archive(const TypedKey& key, std::unique_ptr fieldLocation) override;
     void reconsolidateIndexesAndTocs();
 
     virtual void print( std::ostream &out ) const override;
diff --git a/src/fdb5/toc/TocEngine.cc b/src/fdb5/toc/TocEngine.cc
index b82f802d9..5a6da0fbe 100644
--- a/src/fdb5/toc/TocEngine.cc
+++ b/src/fdb5/toc/TocEngine.cc
@@ -250,10 +250,10 @@ std::vector TocEngine::databases(const metkit::mars::MarsRequest& re
     return result;
 }
 
-std::vector TocEngine::allLocations(const CanonicalKey& key, const Config& config) const
-{
-    return databases(key, CatalogueRootManager(config).allRoots(key), config);
-}
+// std::vector TocEngine::allLocations(const CanonicalKey& key, const Config& config) const
+// {
+//     return databases(key, CatalogueRootManager(config).allRoots(key), config);
+// }
 
 std::vector TocEngine::visitableLocations(const CanonicalKey& key, const Config& config) const
 {
diff --git a/src/fdb5/toc/TocEngine.h b/src/fdb5/toc/TocEngine.h
index 1ded27912..4b4cab861 100644
--- a/src/fdb5/toc/TocEngine.h
+++ b/src/fdb5/toc/TocEngine.h
@@ -49,7 +49,7 @@ class TocEngine : public fdb5::Engine {
 
     virtual bool canHandle(const eckit::URI&, const Config& config) const override;
 
-    virtual std::vector allLocations(const CanonicalKey& key, const Config& config) const override;
+    // virtual std::vector allLocations(const CanonicalKey& key, const Config& config) const override;
 
     virtual std::vector visitableLocations(const CanonicalKey& key, const Config& config) const override;
     virtual std::vector visitableLocations(const metkit::mars::MarsRequest& rq, const Config& config) const override;
diff --git a/src/fdb5/toc/TocIndex.cc b/src/fdb5/toc/TocIndex.cc
index 1076122d8..0f5959e22 100644
--- a/src/fdb5/toc/TocIndex.cc
+++ b/src/fdb5/toc/TocIndex.cc
@@ -78,7 +78,7 @@ void TocIndex::encode(eckit::Stream& s, const int version) const {
 }
 
 
-bool TocIndex::get(const ApiKey& key, const CanonicalKey& remapKey, Field &field) const {
+bool TocIndex::get(const TypedKey& key, const CanonicalKey& remapKey, Field &field) const {
     ASSERT(btree_);
     FieldRef ref;
 
@@ -124,7 +124,7 @@ void TocIndex::close() {
     }
 }
 
-void TocIndex::add(const ApiKey& key, const Field &field) {
+void TocIndex::add(const TypedKey& key, const Field &field) {
     ASSERT(btree_);
     ASSERT( mode_ == TocIndex::WRITE );
 
diff --git a/src/fdb5/toc/TocIndex.h b/src/fdb5/toc/TocIndex.h
index f547c840c..3eadecf66 100644
--- a/src/fdb5/toc/TocIndex.h
+++ b/src/fdb5/toc/TocIndex.h
@@ -97,8 +97,8 @@ class TocIndex :
 
     void visit(IndexLocationVisitor& visitor) const override;
 
-    bool get( const ApiKey& key, const CanonicalKey& remapKey, Field &field ) const override;
-    void add( const ApiKey& key, const Field &field ) override;
+    bool get( const TypedKey& key, const CanonicalKey& remapKey, Field &field ) const override;
+    void add( const TypedKey& key, const Field &field ) override;
     void flush() override;
     void encode(eckit::Stream& s, const int version) const override;
     void entries(EntryVisitor& visitor) const override;
diff --git a/src/fdb5/toc/TocStats.h b/src/fdb5/toc/TocStats.h
index 3c4e83dea..2459a4fca 100644
--- a/src/fdb5/toc/TocStats.h
+++ b/src/fdb5/toc/TocStats.h
@@ -161,7 +161,7 @@ class TocStatsReportVisitor : public virtual StatsReportVisitor {
 
     bool visitDatabase(const Catalogue& catalogue, const Store& store) override;
     void visitDatum(const Field& field, const std::string& keyFingerprint) override;
-    void visitDatum(const Field& field, const ApiKey& datumKey) override { NOTIMP; }
+    void visitDatum(const Field& field, const TypedKey& datumKey) override { NOTIMP; }
 
     // This visitor is only legit for one DB - so don't reset database
     void catalogueComplete(const Catalogue& catalogue) override;
diff --git a/src/fdb5/toc/TocStore.cc b/src/fdb5/toc/TocStore.cc
index 018ec1aa7..2f32d57e4 100644
--- a/src/fdb5/toc/TocStore.cc
+++ b/src/fdb5/toc/TocStore.cc
@@ -106,10 +106,10 @@ eckit::DataHandle* TocStore::retrieve(Field& field) const {
     return field.dataHandle();
 }
 
-std::unique_ptr TocStore::archive(const CanonicalKey& key, const void *data, eckit::Length length) {
+std::unique_ptr TocStore::archive(const CanonicalKey& idxKey, const void *data, eckit::Length length) {
     dirty_ = true;
 
-    eckit::PathName dataPath = getDataPath(key);
+    eckit::PathName dataPath = getDataPath(idxKey);
 
     eckit::DataHandle &dh = getDataHandle(dataPath);
 
diff --git a/src/fdb5/toc/TocStore.h b/src/fdb5/toc/TocStore.h
index 28c965e1e..87592ee8a 100644
--- a/src/fdb5/toc/TocStore.h
+++ b/src/fdb5/toc/TocStore.h
@@ -60,7 +60,7 @@ class TocStore : public Store, public TocCommon {
     bool exists() const override;
 
     eckit::DataHandle* retrieve(Field& field) const override;
-    std::unique_ptr archive(const CanonicalKey& key, const void *data, eckit::Length length) override;
+    std::unique_ptr archive(const CanonicalKey& idxKey, const void *data, eckit::Length length) override;
 
     void remove(const eckit::URI& uri, std::ostream& logAlways, std::ostream& logVerbose, bool doit) const override;
 
diff --git a/src/fdb5/tools/fdb-hide.cc b/src/fdb5/tools/fdb-hide.cc
index 40ec688a2..e870d7987 100644
--- a/src/fdb5/tools/fdb-hide.cc
+++ b/src/fdb5/tools/fdb-hide.cc
@@ -83,10 +83,10 @@ void FdbHide::execute(const option::CmdArgs& args) {
 
     const Schema& schema = conf.schema();
 
-    CanonicalKey dbkey;
+    TypedKey dbkey{schema.registry()};
     ASSERT(schema.expandFirstLevel(dbrequest.request(), dbkey));
 
-    std::unique_ptr db = CatalogueFactory::instance().build(dbkey, conf, true);
+    std::unique_ptr db = CatalogueFactory::instance().build(dbkey.canonical(), conf, true);
     if (!db->exists()) {
         std::stringstream ss;
         ss << "Database not found: " << dbkey << std::endl;
@@ -101,7 +101,7 @@ void FdbHide::execute(const option::CmdArgs& args) {
 
     eckit::Log::info() << "Hide contents of DB: " << *db << std::endl;
     if (doit_) {
-        std::unique_ptr dbWriter = CatalogueFactory::instance().build(dbkey, conf, false);
+        std::unique_ptr dbWriter = CatalogueFactory::instance().build(dbkey.canonical(), conf, false);
         TocCatalogueWriter* tocDB = dynamic_cast(dbWriter.get());
         tocDB->hideContents();
     } else {
diff --git a/src/fdb5/tools/fdb-overlay.cc b/src/fdb5/tools/fdb-overlay.cc
index 717fad19f..f0f4cd671 100644
--- a/src/fdb5/tools/fdb-overlay.cc
+++ b/src/fdb5/tools/fdb-overlay.cc
@@ -95,8 +95,8 @@ void FdbOverlay::execute(const option::CmdArgs& args) {
     Config conf = config(args);
     const Schema& schema = conf.schema();
 
-    CanonicalKey source;
-    CanonicalKey target;
+    TypedKey source{conf.schema().registry()};
+    TypedKey target{conf.schema().registry()};
     ASSERT(schema.expandFirstLevel(sourceRequest.request(), source));
     ASSERT(schema.expandFirstLevel(targetRequest.request(), target));
 
@@ -118,12 +118,12 @@ void FdbOverlay::execute(const option::CmdArgs& args) {
         ASSERT(it != source.end());
         if (kv.second != it->second && vkeys.find(kv.first) == vkeys.end()) {
             std::stringstream ss;
-            ss << "CanonicalKey " << kv.first << " not allowed to differ between DBs: " << source << " : " << target;
+            ss << "Key " << kv.first << " not allowed to differ between DBs: " << source << " : " << target;
             throw UserError(ss.str(), Here());
         }
     }
 
-    std::unique_ptr dbSource = DB::buildReader(source, conf);
+    std::unique_ptr dbSource = DB::buildReader(source.canonical(), conf);
     if (!dbSource->exists()) {
         std::stringstream ss;
         ss << "Source database not found: " << source << std::endl;
@@ -136,7 +136,7 @@ void FdbOverlay::execute(const option::CmdArgs& args) {
         throw UserError(ss.str(), Here());
     }
 
-    std::unique_ptr dbTarget = DB::buildReader(target, conf);
+    std::unique_ptr dbTarget = DB::buildReader(target.canonical(), conf);
 
     if (remove_) {
         if (!dbTarget->exists()) {
@@ -156,7 +156,7 @@ void FdbOverlay::execute(const option::CmdArgs& args) {
 
     ASSERT(dbTarget->uri() != dbSource->uri());
 
-    std::unique_ptr newDB = DB::buildWriter(target, conf);
+    std::unique_ptr newDB = DB::buildWriter(target.canonical(), conf);
 
     // This only works for tocDBs
 
diff --git a/src/fdb5/tools/fdb-root.cc b/src/fdb5/tools/fdb-root.cc
index 6a2d78e9e..fa441016a 100644
--- a/src/fdb5/tools/fdb-root.cc
+++ b/src/fdb5/tools/fdb-root.cc
@@ -65,16 +65,16 @@ void FdbRoot::execute(const eckit::option::CmdArgs& args) {
 
             Config conf = config(args);
             const Schema& schema = conf.schema();
-            CanonicalKey result;
+            TypedKey result{conf.schema().registry()};
             ASSERT( schema.expandFirstLevel(request.request(), result) );
 
             eckit::Log::info() << result << std::endl;
 
             // 'Touch' the database (which will create it if it doesn't exist)
-            std::unique_ptr db = DB::buildReader(result, conf);
+            std::unique_ptr db = DB::buildReader(result.canonical(), conf);
 
             if (!db->exists() && create_db) {
-                db = DB::buildWriter(result, conf);
+                db = DB::buildWriter(result.canonical(), conf);
             }
 
             if (db->exists()) {
diff --git a/tests/fdb/test_fdb5_service.cc b/tests/fdb/test_fdb5_service.cc
index 8f556e45d..9608d4888 100644
--- a/tests/fdb/test_fdb5_service.cc
+++ b/tests/fdb/test_fdb5_service.cc
@@ -96,7 +96,7 @@ struct FixtureService {
 						 << std::endl;
 					std::string data_str = data.str();
 
-                    fdb5::CanonicalKey k(p, config.schema().registry());
+                    fdb5::CanonicalKey k{p};
                     ArchiveVisitor visitor(fdb, k, static_cast(data_str.c_str()), data_str.size());
                     fdb.archive(k, visitor);
 				}
@@ -165,8 +165,7 @@ CASE ( "test_fdb_stepunit_archive" ) {
 		EXPECT(!iter.next(el));
 	}
 
-// sub-hourly data are not yet supported in metkit
-/*	key.set("step","30");
+	key.set("step","30");
 	key.set("stepunits","m");
 	fdb.archive(key, static_cast(data_str.c_str()), data_str.size());
 	fdb.flush();
@@ -181,10 +180,14 @@ CASE ( "test_fdb_stepunit_archive" ) {
 		EXPECT(!iter.next(el));
 	}
 
-	req.setValue("step", "0/to/2/by/30m");
+	req.values("step", {"0","to","2","by","30m"});
+	req.unsetValues("param");
 	{
 		metkit::mars::MarsExpension expand{false};
+
+		std::cout << req << endl;
 		metkit::mars::MarsRequest expandedRequests = expand.expand(req);
+		std::cout << expandedRequests << endl;
 		fdb5::FDBToolRequest r(expandedRequests);
 		fdb5::ListIterator iter = fdb.list(r, true);
 		fdb5::ListElement el;
@@ -193,11 +196,9 @@ CASE ( "test_fdb_stepunit_archive" ) {
 		EXPECT(iter.next(el));
 		EXPECT(el.combinedKey().get("step") == "2");
 		EXPECT(!iter.next(el));
-	}*/
+	}
 }
 
-
-
 CASE ( "test_fdb_service" ) {
 
 	SETUP("Fixture") {
diff --git a/tests/fdb/type/test_toKey.cc b/tests/fdb/type/test_toKey.cc
index 8e9f1bf7d..d14eadb7c 100644
--- a/tests/fdb/type/test_toKey.cc
+++ b/tests/fdb/type/test_toKey.cc
@@ -31,7 +31,7 @@ char data[4];
 
 CASE( "ClimateDaily - no expansion" ) {
 
-    fdb5::CanonicalKey key(config.schema().registry());
+    fdb5::CanonicalKey key{};
     EXPECT(key.valuesToString() == "");
     EXPECT_THROWS(key.canonicalValue("date"));
 
@@ -48,7 +48,7 @@ CASE( "ClimateDaily - no expansion" ) {
 
 CASE( "Step & ClimateDaily - expansion" ) {
 
-    fdb5::ApiKey key(config.schema().registry());
+    fdb5::TypedKey key(config.schema().registry());
     EXPECT(key.valuesToString() == "");
     EXPECT_THROWS(key.canonicalValue("date"));
 
@@ -172,7 +172,7 @@ CASE( "Levelist" ) {
     values.insert("0.333333");
     values.sort();
 
-    fdb5::ApiKey key(config.schema().registry());
+    fdb5::TypedKey key(config.schema().registry());
     EXPECT(key.valuesToString() == "");
     EXPECT_THROWS(key.canonicalValue("levelist"));
 
@@ -227,7 +227,7 @@ CASE( "Levelist" ) {
 
 CASE( "Expver, Time & ClimateDaily - string ctor - expansion" ) {
 
-    fdb5::ApiKey key = fdb5::ApiKey::parseString(
+    fdb5::TypedKey key = fdb5::TypedKey::parseString(
         "class=ei,expver=1,stream=dacl,domain=g,type=pb,levtype=pl,date=20210427,time=6,step=0,quantile=99:100,levelist=50,param=129.128",
         config.schema().registry());
 
@@ -246,7 +246,7 @@ CASE( "Expver, Time & ClimateDaily - string ctor - expansion" ) {
 
 CASE( "ClimateMonthly - string ctor - expansion" ) {
 
-    fdb5::ApiKey key = fdb5::ApiKey::parseString(
+    fdb5::TypedKey key = fdb5::TypedKey::parseString(
         "class=op,expver=1,stream=mnth,domain=g,type=cl,levtype=pl,date=20210427,time=0000,levelist=50,param=129.128",
         config.schema().registry());
 
@@ -268,7 +268,7 @@ CASE( "ClimateMonthly - string ctor - expansion" ) {
 // do we need to keep this behaviour? should we rely on metkit for date expansion and remove it from CanonicalKey?
 CASE( "Date - string ctor - expansion" ) {
 
-    fdb5::ApiKey key = fdb5::ApiKey::parseString(
+    fdb5::TypedKey key = fdb5::TypedKey::parseString(
             "class=od,expver=1,stream=oper,type=ofb,date=-2,time=0000,obsgroup=MHS,reportype=3001",
             config.schema().registry());