Skip to content

Commit

Permalink
Config serialization should take into account env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
ypatia committed Apr 10, 2024
1 parent e0bc0dd commit 8a3c85c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
11 changes: 11 additions & 0 deletions tiledb/sm/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,17 @@ const char* Config::get_from_config_or_env(
return *found ? value_config : "";
}

const std::map<std::string, std::string>
Config::get_all_params_from_config_or_env() const {
std::map<std::string, std::string> values;
bool found = false;
for (const auto& [key, value] : param_values_) {
std::string val = get_from_config_or_env(key, &found);
values.emplace(key, val);
}
return values;
}

template <class T, bool must_find_>
optional<T> Config::get_internal(const std::string& key) const {
auto value = get_internal_string<must_find_>(key);
Expand Down
12 changes: 9 additions & 3 deletions tiledb/sm/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ namespace tiledb::sm {
* Parsing to appropriate types happens on demand.
*/
class Config {
friend class ConfigIter;

public:
/* ****************************** */
/* CONFIG DEFAULTS */
Expand Down Expand Up @@ -689,9 +691,6 @@ class Config {
Status get_vector(
const std::string& param, std::vector<T>* value, bool* found) const;

/** Returns the param -> value map. */
const std::map<std::string, std::string>& param_values() const;

/** Gets the set parameters. */
const std::set<std::string>& set_params() const;

Expand All @@ -706,6 +705,10 @@ class Config {
/** Compares configs for equality. */
bool operator==(const Config& rhs) const;

/** Get all config params taking into account environment variables */
const std::map<std::string, std::string> get_all_params_from_config_or_env()
const;

private:
/* ********************************* */
/* PRIVATE ATTRIBUTES */
Expand Down Expand Up @@ -782,6 +785,9 @@ class Config {

template <bool must_find_>
optional<std::string> get_internal_string(const std::string& key) const;

/** Returns the param -> value map. */
const std::map<std::string, std::string>& param_values() const;
};

/**
Expand Down
5 changes: 3 additions & 2 deletions tiledb/sm/serialization/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ namespace serialization {

Status config_to_capnp(
const Config& config, capnp::Config::Builder* config_builder) {
auto entries = config_builder->initEntries(config.param_values().size());
auto config_params = config.get_all_params_from_config_or_env();
auto entries = config_builder->initEntries(config_params.size());
uint64_t i = 0;
for (const auto& kv : config.param_values()) {
for (const auto& kv : config_params) {
entries[i].setKey(kv.first);
entries[i].setValue(kv.second);
++i;
Expand Down

0 comments on commit 8a3c85c

Please sign in to comment.