All Classes Namespaces Functions Variables Groups Pages
Mapper.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* Mapper.qm Copyright 2014 - 2017 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// minimum required Qore version
// require type definitions everywhere
// enable all warnings
// do not use "$" for vars
/* Version History
*/
namespace Mapper {
class Mapper {
public:
public :
const ConstantConflictList = ("name", "struct", "code", "default");
const OptionKeys = (
"allow_dot": "allows input fields to have a dot in their name without implying a structured format",
"allow_output_dot": "allows output fields to have a dot in their name without implying a structured format",
"date_format": "gives the default format for parsing dates from strings; ex: \"MM/DD/YYYY HH:mm:SS\"",
"encoding": "gives the default output character encoding for string fields",
"info_log": "a call reference / closure for informational logging",
"input": "a hash describing the input record",
"input_log": "a call reference / closure for input record logging",
"input_timezone": "the default timezone to assume when parsing input dates",
"name": "the name of the Mapper object",
"number_format": "the default number format when parsing number fields from strings; ex: \".,\"",
"output": "a hash describing the output record",
"output_log": "a call reference / closure for input record logging",
"timezone": "the default output timezone for date/time values",
"runtime": "runtime options as a hash (see also setRuntime(), replaceRuntime())",
"empty_strings_to_nothing": "converts out record's empty strings and into NOTHING - actually the value is deleted",
);
const ValidKeys = (
"name": True,
"struct": True,
"constant": True,
"index" : True,
"code": True,
"default": True,
"maxlen": True,
"trunc": True,
"mand": True,
"number": True,
"type": True,
"date_format": True,
"number_format": True,
"runtime" : True,
"empty_strings_to_nothing" : True,
);
const ValidTypes = (
"number": True,
"integer": True,
"int": True, // is an alias for "integer"
"date": True,
"string": True,
);
const OutputKeys = (
"desc": True,
"mand": True,
"maxlen": True,
"type": True,
);
public:
private :
hash mapc;
hash mapd;
hash mapo;
string encoding = "utf-8";
*string name;
*code info_log;
*code input_log;
*code output_log;
*Qore::TimeZone timezone;
Qore::TimeZone input_timezone = TimeZone::get();
bool trunc_all = False;
bool allow_dot = False;
bool allow_output_dot = False;
*string date_format;
*string number_format;
*hash input;
*hash output;
int count = 0;
*hash m_runtime;
bool m_empty_strings_to_nothing = False;
hash identh;
*list identl;
hash consth;
hash rconsth;
public:
constructor(hash mapv, *hash opts);
private:
constructor();
public:
private:
setup(hash mapv, *hash opts);
public:
private:
checkMap();
public:
private:
convertToHash(int t, string k, reference<any> fh);
public:
private:
checkInputField(string k, string name);
public:
private:
checkMapField(string k, reference<any> fh);
public:
private:
checkTimezoneOption(hash opts, string rn);
public:
setRuntime(string key, auto value);
setRuntime(hash runtime);
replaceRuntime(*hash runtime);
auto getRuntime(string key);
string getFieldName(string fname);
hash validKeys();
hash validTypes();
hash optionKeys();
*hash getInputRecord();
*hash getOutputRecord();
list<hash> mapAll(list recs);
list<hash> mapAll(hash recs);
hash mapData(hash rec);
private:
hash mapDataIntern(hash rec);
public:
private:
nothing mapFieldIntern(reference<hash> h, string key, hash rec, bool do_list, int list_size);
public:
private:
string truncateField(string k, string val, int ix, int sze, int maxlen);
public:
private:
fieldLengthError(string k, string val, int ix, int sze, int maxlen, hash rc);
public:
logOutput(hash h);
int getCount();
resetCount();
private:
mapFieldType(string key, hash m, reference<any> v, hash rec);
public:
private:
error(string fmt);
public:
private:
error2(string ex, string fmt);
public:
private:
auto mapSubclass(hash m, auto v);
public:
};
class AbstractMapperIterator : public Qore::AbstractIterator {
public:
public :
public:
private :
Qore::AbstractIterator i;
public:
constructor(Qore::AbstractIterator iter);
bool next();
bool valid();
bool hasBulk();
list<hash> mapBulk(int size);
};
class MapperIterator : public Mapper::AbstractMapperIterator {
public:
public :
public:
private :
Mapper::Mapper mapc;
public:
constructor(Qore::AbstractIterator i, hash mapv, *hash opts) ;
constructor(Qore::AbstractIterator i, Mapper::Mapper mapv) ;
hash getValue();
int getCount();
resetCount();
};
};
Mapper::Mapper::getRuntime
auto getRuntime(string key)
get current runtime option value for a key
Mapper::AbstractMapperIterator::i
Qore::AbstractIterator i
input iterator; AbstractIterator::getValue() must return a hash
Definition: Mapper.qm.dox.h:750
Mapper::Mapper::getCount
int getCount()
returns the internal record count
Mapper::Mapper::getOutputRecord
*hash getOutputRecord()
returns the value of the &quot;output&quot; option
Mapper::Mapper::ConstantConflictList
const ConstantConflictList
field keys that conflict with &quot;constant&quot; and &quot;index&quot;
Definition: Mapper.qm.dox.h:257
Mapper::Mapper::date_format
*string date_format
the global date format for parsing dates
Definition: Mapper.qm.dox.h:357
Mapper::Mapper::validTypes
hash validTypes()
returns a list of valid field types for this class (can be overridden in subclasses) ...
Mapper::Mapper::checkInputField
checkInputField(string k, string name)
raises an error if an invalid input field name is declared; only call this if &quot;input&quot; is defined ...
Mapper::MapperIterator::mapc
Mapper::Mapper mapc
data mapper
Definition: Mapper.qm.dox.h:791
Mapper::Mapper::mapFieldIntern
nothing mapFieldIntern(reference< hash > h, string key, hash rec, bool do_list, int list_size)
maps a single field to the target
Mapper::Mapper::mapd
hash mapd
the hash with a subset of the mappings used dynamically
Definition: Mapper.qm.dox.h:321
Mapper::AbstractMapperIterator::next
bool next()
Moves the current position of the iterator to the next element; returns False if there are no more el...
True
const True
Mapper::Mapper::checkMap
checkMap()
verifies the input map in the constructor
Mapper::Mapper::consth
hash consth
map of constant fields
Definition: Mapper.qm.dox.h:388
Mapper::Mapper::getFieldName
string getFieldName(string fname)
returns a descriptive name of the given field if possible, otherwise returns the field name itself ...
Mapper::Mapper::m_empty_strings_to_nothing
bool m_empty_strings_to_nothing
flag to enforce deletion of the empty string in the output record
Definition: Mapper.qm.dox.h:379
Mapper::Mapper::OptionKeys
const OptionKeys
constructor option keys (can be extended by subclassing and reimplementing optionKeys()) ...
Definition: Mapper.qm.dox.h:260
Mapper::Mapper::output_log
*code output_log
an optional output data logging callback; must accept a hash giving the output data hash ...
Definition: Mapper.qm.dox.h:339
Mapper::Mapper::info_log
*code info_log
an optional info logging callback; must accept a sprintf()-style format specifier and optional argume...
Definition: Mapper.qm.dox.h:333
Mapper::MapperIterator
provides a hash iterator based on a mapper object and an iterator input source
Definition: Mapper.qm.dox.h:782
Mapper::Mapper::convertToHash
convertToHash(int t, string k, reference< any > fh)
convert a field definition to a hash if possible
Mapper::Mapper::checkTimezoneOption
checkTimezoneOption(hash opts, string rn)
verifies a timezone constructor option
False
const False
Mapper::Mapper::allow_dot
bool allow_dot
do not assume struct when field names have a &quot;.&quot; in them; instead allow input field names to have a &quot;...
Definition: Mapper.qm.dox.h:351
Mapper::Mapper
this class is a base class for mapping data; see Mapper Examples for usage examples ...
Definition: Mapper.qm.dox.h:252
list
list list(...)
Mapper::Mapper::mapc
hash mapc
the hash providing output field names and mappings
Definition: Mapper.qm.dox.h:318
Mapper::MapperIterator::getValue
hash getValue()
returns the current row transformed with the mapper
Mapper::Mapper::count
int count
count of records mapped
Definition: Mapper.qm.dox.h:369
Mapper::Mapper::mapo
hash mapo
the hash of output records for key order
Definition: Mapper.qm.dox.h:324
Mapper::Mapper::resetCount
resetCount()
resets the internal record count
Mapper::MapperIterator::constructor
constructor(Qore::AbstractIterator i, hash mapv, *hash opts)
creates the iterator from the arguments passed
Mapper::AbstractMapperIterator::mapBulk
list< hash > mapBulk(int size)
performs bulk mapping; if the iterator does not support bulk mapping then it is simulated in this met...
Mapper::Mapper::number_format
*string number_format
the global number format for parsing numbers
Definition: Mapper.qm.dox.h:360
Mapper::Mapper::mapSubclass
auto mapSubclass(hash m, auto v)
to be overridden as necessary in subclasses
Qore::TimeZone
Mapper::Mapper::input_timezone
Qore::TimeZone input_timezone
the timezone for input fields in case of parsing text values; if not set defaults to the current Time...
Definition: Mapper.qm.dox.h:345
Mapper::Mapper::setup
setup(hash mapv, *hash opts)
sets up the mapper object before checking the mapper hash
Mapper::AbstractMapperIterator
abstract base class for hash iterator mappping classes based on a mapper object and an iterator input...
Definition: Mapper.qm.dox.h:741
Mapper::Mapper::validKeys
hash validKeys()
returns a list of valid field keys for this class (can be overridden in subclasses) ...
Mapper::Mapper::allow_output_dot
bool allow_output_dot
do not assume structured/hash output when output field names have a &quot;.&quot; in them; instead allow output...
Definition: Mapper.qm.dox.h:354
Mapper::Mapper::ValidKeys
const ValidKeys
default known mapper hash field keys (can be extended by subclassing and reimplementing validKeys()) ...
Definition: Mapper.qm.dox.h:279
Mapper::Mapper::truncateField
string truncateField(string k, string val, int ix, int sze, int maxlen)
called to truncate fields when processing hashes of lists
Mapper::Mapper::identl
*list identl
list of fields to be mapped 1:1 input -&gt; output
Definition: Mapper.qm.dox.h:385
Mapper::Mapper::identh
hash identh
map of fields to be mapped 1:1 input -&gt; output
Definition: Mapper.qm.dox.h:382
Mapper::Mapper::error
error(string fmt)
throws a MAP-ERROR exception; prepends the map name to the description if known
Mapper::Mapper::timezone
*Qore::TimeZone timezone
an optional timezone for output date fields
Definition: Mapper.qm.dox.h:342
Mapper::Mapper::logOutput
logOutput(hash h)
calls the output logging closure or call reference (if any) to log the output record ...
Mapper::Mapper::trunc_all
bool trunc_all
truncate all option
Definition: Mapper.qm.dox.h:348
Mapper::Mapper::ValidTypes
const ValidTypes
default known field types (can be extended by subclassing and reimplementing validTypes() and mapFiel...
Definition: Mapper.qm.dox.h:298
Mapper::Mapper::mapData
hash mapData(hash rec)
processes the input record and returns a hash of the mapped values where the keys in the hash returne...
Mapper::AbstractMapperIterator::constructor
constructor(Qore::AbstractIterator iter)
creates the iterator from the arguments passed
Mapper::Mapper::output
*hash output
an optional description of the output data structure
Definition: Mapper.qm.dox.h:366
Mapper::Mapper::setRuntime
setRuntime(string key, auto value)
set the runtime option with &quot;key&quot; to value &quot;value&quot;
Mapper::Mapper::constructor
constructor()
private constructor for subclasses
Mapper::AbstractMapperIterator::hasBulk
bool hasBulk()
returns True if the iterator supports bulk mode; this method returns False (the default) ...
Mapper::Mapper::name
*string name
the optional name for the object (for example a table name); will be prepended to field names in erro...
Definition: Mapper.qm.dox.h:330
Mapper::Mapper::encoding
string encoding
the output character encoding; if not given then the output encoding is assumed to be UTF-8 ...
Definition: Mapper.qm.dox.h:327
Mapper::MapperIterator::getCount
int getCount()
returns the internal record count
Mapper::Mapper::optionKeys
hash optionKeys()
returns a list of valid constructor options for this class (can be overridden in subclasses) ...
Mapper::Mapper::input
*hash input
an optional description of possible input hash keys
Definition: Mapper.qm.dox.h:363
Mapper::Mapper::getInputRecord
*hash getInputRecord()
returns the value of the &quot;input&quot; option
Mapper::Mapper::mapDataIntern
hash mapDataIntern(hash rec)
processes the input record and returns a hash of the mapped values where the keys in the hash returne...
Mapper::Mapper::mapAll
list< hash > mapAll(list recs)
maps all input records and returns the mapped data as a list of output records
Mapper::Mapper::input_log
*code input_log
an optional input data logging callback; must accept a hash giving the input data hash ...
Definition: Mapper.qm.dox.h:336
Mapper::Mapper::replaceRuntime
replaceRuntime(*hash runtime)
replaces runtime options
Mapper::Mapper::checkMapField
checkMapField(string k, reference< any > fh)
perform per-field pre-processing on the passed map in the constructor
hash
hash hash(object obj)
Mapper::Mapper::mapFieldType
mapFieldType(string key, hash m, reference< any > v, hash rec)
performs type handling
Mapper::Mapper::rconsth
hash rconsth
map of constant runtime fields
Definition: Mapper.qm.dox.h:391
Mapper::Mapper::OutputKeys
const OutputKeys
output option keys
Definition: Mapper.qm.dox.h:307
Mapper::AbstractMapperIterator::valid
bool valid()
returns True if the iterator is currently pointing at a valid element, False if not ...
Mapper::Mapper::error2
error2(string ex, string fmt)
throws the given exception; prepends the map name to the description if known
Mapper::Mapper::m_runtime
*hash m_runtime
current runtime values
Definition: Mapper.qm.dox.h:374
Qore::AbstractIterator
Mapper::MapperIterator::resetCount
resetCount()
resets the internal record count
Mapper::Mapper::fieldLengthError
fieldLengthError(string k, string val, int ix, int sze, int maxlen, hash rc)
called when a field exceeds its maximum length when processing hashes of lists