Joins and Lookups
Lookup tables
Declaration and load
static table some_dimension("dim.csv", "dim.evd", "id", table::text_read);
where the third parameter is the comma separated list of key fields, i.e. the field(s) according to which it will look up.
|
|
The forth parameter is not mandatory and it may contain these flags:
table::binary_read
the file is binary, default flag.
table::text_read
the file is a text.
table::unique_key
without this flag, it suppose there might be several keys and it will try to look for the first one. As it slows down looking up the data, if you know the lookup key is unique, use this flag.
table::ignore_case
ignore case for strings.
More complex example:
static table some_lookup("input.csv", "input.evd", "key1, key2", table::text_read | table::unique_key);
Methods
These methods looking up data in defined and loaded ‘table’:
lookup_char lookup_uchar lookup_short lookup_ushort lookup_int lookup_uint lookup_long lookup_ulong lookup_float lookup_double lookup_decimal lookup_date lookup_timestamp lookup_string
They are distinguished according to return value data type. They return the pointer to the value. For example ‘lookup_char’ returns pointer to ‘std::int8_t’ etc.
Methods return ‘nullptr’ if there is no record found in the lookup table.
All methods have two or more parameters: first one is the name of the field to be returned and other parameters are values of the key fields defined by ‘table’.
Example: Let’s have lookup (sorted) file lookup_file.csv:
1|2017-06-04|value1 1|2017-06-05|value2 2|2017-06-05|value3
with lookup_file.evd:
key1 int sep="|" key2 date sep="|" field3 string sep="\n"
Then in mapping (evm file):
static table lookup_file("lookup_file.csv", "lookup_file.evd", "key1, key2", table::text_read | table::unique_key); string* s = lookup_file.lookup_string("field3", 1, date("2017-06-05")); // -> value2