Tapper::Metadata
require YAML::Syck; require Tapper::Metadata; my $or_meta = Tapper::Metadata->new({ dbh => $or_dbh, debug => 0, config => YAML::Syck::LoadFile('~/conf/tapper_metadata.conf'), }); my $b_success = $or_meta->add_multi_metadata([ { TESTRUN => 12345, key_1 => 'value_1', key_2 => 'value_2', },{ TESTRUN => 12346, key_3 => 'value_3', }, ... ],{ force => 1, }); my $or_metadata_points = $or_meta->search({ select => [ 'TESTRUN', 'key_2', ], where => [ { operator => '!=', column => 'key_1', values => 'value_1', }, { operator => '=' , column => 'key_2', values => 'value_2', }, ], order_by => [ 'key_3', { column => 'TESTRUN', direction => 'ASC', numeric => 1 }, ], exclusive => 1, limit => 2, offset => 1, }); while my $hr_metadata_point ( $or_metadata_points->fetchrow_hashref() ) { ... }
Tapper::Metadata is a module for adding metadata values in a standardised way to the the database. A search function with complexe filters already exists.
Create a new Tapper::Metadata object.
my $or_meta = Tapper::Metadata->new({ dbh => $or_dbh, debug => 0, config => YAML::Syck::LoadFile('~/conf/tapper_metadata.conf'), });
A DBI database handle.
Containing the path to the Tapper::Metadata-Configuration-File. See Configuration for details.
Setting debug to a true value results in multiple debugging informations written to STDOUT. The default is 0.
debug
Add one or more data points to a single metadata to the database.
my $b_success = $or_meta->add_single_metadata({ TESTRUN => 12345, key_1 => 'value_1', key_2 => 'value_2', },{ force => 1 });
The Testrun ID to relate metadata with a testrun.
Ignore forgivable errors while writing.
Add one or more data points to a multiple metadata to the database.
my @a_error_idxs = $or_meta->add_multi_metadata([ { TESTRUN => 12345, key_1 => 'value_1', key_2 => 'value_2', },{ TESTRUN => 12346, key_3 => 'value_3', }, ... ],{ force => 1 });
Search for metadata points in the database. Function returns a DBI Statement Handle.
my $or_metadata_points = $or_meta->search({ select => [ 'TESTRUN', 'key_2', ], where => [ { operator => '!=', column => 'key_1', values => 'value_1', }, { operator => '=' , column => 'key_2', values => 'value_2', }, ], where_sql => q#, AND NOT( ${TESTRUN} = 123 OR ${VALUE} = '144' ) #, order_by => [ 'key_3', { column => 'TESTRUN', direction => 'ASC', numeric => 1 }, ], exclusive => 1, limit => 2, offset => 1, });
An Array of Strings or Hash References containing additional selected columns. The default selected columns are: TESTRUN
Add additional data "key_2" as column to selection.
... select => [ 'TESTRUN', 'key_2', ], ...
Get the maximum "TESTRUN" of all selected data points. All other columns without an aggregation become the default_aggregation from Tapper::Metadata-Configuration. Possible aggregation types are:
default_aggregation
- min = minimum - max = maximum - avg = average - gem = geometric mean - sum = summary - cnt = count - cnd = distinct value count ... select => [ { column => 'TESTRUN', aggregate => 'max', }, { column => 'key_2' , }, ], ...
A aggregation is also possible for the default columns.
... select => [ { column => 'TESTRUN', aggregate => 'max', }, { column => 'key_2' , aggregate => 'avg', }, ], ...
All additional values internally stored as strings. For the numeric aggegation functions "min", "max", "avg", "gem" and "sum" the "numeric" flag must be set to a true value to cast the value as a numeric.
... select => [ { column => 'TESTRUN', aggregate => 'max', numeric => 1, }, { column => 'key_2' , aggregate => 'avg', }, ], ...
An Array of Hash References containing restrictions for metadata points.
... where => [ { operator => '!=', column => 'key_1', values => 'value_1', }, { operator => '=' , column => 'key_2', values => 'value_2', }, ], ...
- Parameter in Sub-Hash = operator
= - equal != - not equal < - lower > - greater <= - lower equal >= - greater equal like - SQL LIKE not like - SQL NOT LIKE
- Parameter in Sub-Hash = column
A restriction is possible for additional values and the default columns.
- Parameter in Sub-Hash = values
In general there is just a single value. For '=' and '!=' a check for multiple values is possible. Insert a array reference of values in this case. In SQL it is implemented with IN and NOT IN.
- Parameter in Sub-Hash = numeric [ optional ]
All additional values internally stored as strings. For the numeric operators '<', '<=', '>' and '>=' this flag must be set to a true value to cast the value as a numeric.
A String containing an additional where clause. Please use this feature just if the "where" parameter is not sufficient to restrict.
An Array of Strings or an Array of Array References determining the order of returned metadata points.
Array of Strings: column to sort with default order direction "ASC" (ascending)
Array of Strings or Hash References column : column to sort direction : order direction with possible values "ASC" (ascending) and "DESC" (descending) numeric : set a true value for a numeric sort
... order_by => [ 'key_3', { column => 'TESTRUN', direction => 'ASC', numeric => 1 }, ], ...
An integer value which determine the number of returned metadata points.
An integer value which determine the number of omitted metadata points.
Select testruns which contains just the metadata "columns" given by the where attribute.
Returning all metadata points as Array of Hashes.
my $ar_metadata_points = $or_meta->search_array({ select => [ 'TESTRUN', 'key_2', ], where => [ { operator => '!=', column => 'key_1', values => 'value_1', }, { operator => '=' , column => 'key_2', values => 'value_2', }, ], order_by => [ 'key_3', { column => 'TESTRUN', direction => 'ASC', numeric => 1 }, ], limit => 2, offset => 1, });
Returning all metadata points as Hash of Hashes. As compared to search search_array this function needs the parameter keys. keys is an Array of Strings which determine the columns used as the keys for the nested hashes. Every "key" create a new nested hash.
search_array
keys
my $or_metadata_points = $or_meta->search_array({ keys => [ 'TESTRUN', 'key_2', ], select => [ 'TESTRUN', 'key_2', ], where => [ { operator => '!=', column => 'key_1', values => 'value_1', }, { operator => '=' , column => 'key_2', values => 'value_2', }, ], order_by => [ 'key_3', { column => 'TESTRUN', direction => 'ASC', numeric => 1 }, ], limit => 2, offset => 1, });
Tapper::Metadata - Save and search Metadata points by database
The following elements are required in configuration:
Default aggregation used for non aggregated columns if an aggregation on any other column is found.
Containing the names of the tables used bei Tapper::Metadata
tables => { additional_type_table => 'bench_additional_types', additional_value_table => 'bench_additional_values', additional_type_relation_table => 'bench_additional_type_relations', }
In case of a true value the module cache some select results
Roberto Schaefer <schaefr@amazon.com>
This software is Copyright (c) 2016 by Amazon.com, Inc. or its affiliates.
This is free software, licensed under:
The (two-clause) FreeBSD License
To install Tapper::Metadata, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tapper::Metadata
CPAN shell
perl -MCPAN -e shell install Tapper::Metadata
For more information on module installation, please visit the detailed CPAN module installation guide.