pub struct Context {
pub name: String,
pub product_root: Option<PathBuf>,
pub data_root: Option<PathBuf>,
pub settings: MicroDataCollection,
pub allow_full_metadata: bool,
pub enable_full_metadata: bool,
}
Expand description
Holds loaded metadata and information for finding data and additional metadata.
This mutable state holds loaded metadata (if any), the rest of the information needed to add paths to the data tables used in queries and data file paths, and information about where the metadata can be found.
Often, creating a DataRequest will automatically return a
Context
along with the DataRequest
(for example, see
DataRequest::from_names and
AbacusRequest::try_from_json). In those cases,
you do not need to directly create a context yourself. If you do find yourself needing to
directly create a Context
, from_ipums_collection_name
is the easiest way to do that.
use cimdea::conventions::Context;
// Set data root to point to the directory with your data
let data_root = "tests/data_root/".to_string();
let ctx = Context::from_ipums_collection_name(
"usa",
None,
Some(data_root),
).unwrap();
assert_eq!(ctx.name, "usa");
let mut record_types: Vec<_> = ctx.settings.record_types.keys().collect();
record_types.sort();
assert_eq!(record_types, ["H", "P"]);
Fields§
§name: String
A product name like USA, IPUMSI, CPS etc
product_root: Option<PathBuf>
§data_root: Option<PathBuf>
Any output_data/current path with ./layouts and ./parquet in it
settings: MicroDataCollection
§allow_full_metadata: bool
§enable_full_metadata: bool
Implementations§
Source§impl Context
impl Context
pub fn get_md_variable_by_name( &self, name: &str, ) -> Result<IpumsVariable, MdError>
Sourcepub fn paths_from_dataset_name(
&self,
dataset_name: &str,
data_format: &InputType,
) -> Result<HashMap<String, PathBuf>, MdError>
pub fn paths_from_dataset_name( &self, dataset_name: &str, data_format: &InputType, ) -> Result<HashMap<String, PathBuf>, MdError>
Formats the exact paths needed to get data for this dataset, by record type.
Sourcepub fn load_metadata_for_datasets(
&mut self,
datasets: &[&str],
) -> Result<(), MdError>
pub fn load_metadata_for_datasets( &mut self, datasets: &[&str], ) -> Result<(), MdError>
When called, the context should be already set to read from layouts or full metadata
Sourcepub fn load_metadata_for_datasets_and_variables(
&mut self,
_datasets: Vec<String>,
_variables: Vec<String>,
)
pub fn load_metadata_for_datasets_and_variables( &mut self, _datasets: Vec<String>, _variables: Vec<String>, )
The context should be set to read from layouts or full metadata
Sourcepub fn from_ipums_collection_name(
name: &str,
other_product_root: Option<String>,
other_data_root: Option<String>,
) -> Result<Self, MdError>
pub fn from_ipums_collection_name( name: &str, other_product_root: Option<String>, other_data_root: Option<String>, ) -> Result<Self, MdError>
Based on name, use default data root and product root and initialize with defaults Optional data root and product root will be used if provided.
Returns an error if the given name isn’t the name of a recognized product.