MySQL 9.1.0
Source Code Documentation
|
This template class acts as a container of table columns and encapsulates and abstracts a TABLE
object field set iteration logic, by providing an iterator interface implementation.
More...
#include <table_column_iterator.h>
Classes | |
class | iterator |
Iterator class to allow iterating over the replicatable fields in a TABLE object field set. More... | |
Public Types | |
using | filter_fn_type = ExclusionFilter |
Alias for the predicate type, for readability purposes. More... | |
Public Member Functions | |
template<typename U = ExclusionFilter> | |
Table_columns_view (unsigned long options=0, typename std::enable_if< std::is_same< U, std::function< bool(TABLE const *, size_t)> >::value >::type *=nullptr) | |
Empty constructor, only available when the predicate type is a lambda function. More... | |
template<typename U = ExclusionFilter> | |
Table_columns_view (TABLE const *table, unsigned long options=0, typename std::enable_if< std::is_same< U, std::function< bool(TABLE const *, size_t)> >::value >::type *=nullptr) | |
Constructor that takes the target TABLE object, only available when the predicate type is a lambda function. More... | |
Table_columns_view (ExclusionFilter filtering_predicate, unsigned long options=0) | |
Constructor which takes a predicate used to filter this container iteration. More... | |
Table_columns_view (TABLE const *table, ExclusionFilter filtering_predicate, unsigned long options=0) | |
Constructor which takes the TABLE object whose field set will be iterated and a predicate used to filter this container iteration. More... | |
virtual | ~Table_columns_view () |
Destructor for the class. More... | |
virtual Table_columns_view & | set_table (const TABLE *rhs) |
Setter which initializes the internal reference to the TABLE object whose field set will be iterated over. More... | |
virtual Table_columns_view & | set_filter (ExclusionFilter rhs) |
Setter which initializes the internal filtering predicate of type ExclusionFilter . More... | |
Table_columns_view (const Table_columns_view &rhs)=delete | |
Table_columns_view (Table_columns_view &&rhs)=delete | |
Table_columns_view & | operator= (const Table_columns_view &rhs)=delete |
Table_columns_view & | operator= (Table_columns_view &&rhs)=delete |
size_t | absolute_size () const |
Computes the total number of fields in the table. More... | |
size_t | filtered_size () const |
Computes the total number of fields after filtering. More... | |
virtual iterator | begin () |
Creates an iterator object, pointing at the beginning of the table field set. More... | |
virtual iterator | end () |
Creates an iterator object, pointing at the end of the table field set. More... | |
bool | is_excluded (size_t index) const |
Returns whether or not the field at index is to be excluded from the field set iteration process. More... | |
MY_BITMAP & | get_included_fields_bitmap () |
Returns the bitmap for the columns from the local table set that are to be included in the replicated row. More... | |
MY_BITMAP & | get_excluded_fields_bitmap () |
Returns the bitmap for the columns from the local table set that are to be excluded from the replicated row. More... | |
Table_columns_view & | translate_bitmap (MY_BITMAP &source, MY_BITMAP &destination) |
Takes a bitmap object, as received from the replication channel and translates it to a bitmap that matches the local TABLE object. More... | |
size_t | translate_position (size_t source) |
For the absolute position on the table that equals the given position given as a parameter, return the translated position. More... | |
iterator | find_by_absolute_pos (size_t absolute_pos) |
Returns the iterator for the (absolute) position in the table. More... | |
template<typename F > | |
Table_columns_view (F filtering_predicate, unsigned long options) | |
template<typename F > | |
Table_columns_view (TABLE const *target, F filtering_predicate, unsigned long options) | |
Static Public Attributes | |
static constexpr unsigned long | DEFAULTS = 0 |
Default set of options. More... | |
static constexpr unsigned long | VFIELDS_ONLY = 1 |
Request the view excluding filter to operate TABLE::vfields instead of the full set. More... | |
Protected Member Functions | |
Table_columns_view & | init_fields_bitmaps () |
Initializes the internal included and excluded fields bitmaps. More... | |
Static Private Member Functions | |
static bool | default_filter (TABLE const *table, size_t column_index) |
Default filtering predicate. More... | |
Private Attributes | |
TABLE const * | m_table {nullptr} |
The TABLE object reference which contains the field set to be iterated over. More... | |
ExclusionFilter | m_filtering_predicate |
ExclusionFiltering predicate to be invoked when determining if a column is to be included in the iteration. More... | |
size_t | m_filtered_size {0} |
Number of columns to include in iteration. More... | |
MY_BITMAP | m_included_fields_bitmap |
Bitmap that holds the information about which columns from the local table are to be included in the replicated row. More... | |
MY_BITMAP | m_excluded_fields_bitmap |
Bitmap that holds the information about which columns from the local table are to be excluded from the replicated row. More... | |
unsigned long | m_options {0} |
Set of options to apply to view behaviour. More... | |
This template class acts as a container of table columns and encapsulates and abstracts a TABLE
object field set iteration logic, by providing an iterator interface implementation.
The template parameter ExclusionFilter
is a predicate that takes a TABLE
reference and a column index and returns whether or not the field should be filtered out, more specifically, a signature compatible with:
std::function<bool (TABLE const*, size_t)>
This template class accepts an empty parameter set, which provides an unfiltered container and iterates over all the table columns:
void print_all_fields(TABLE *table) { Table_columns_view<> fields{table};
for (auto field : fields) { std::cout << field->field_index << ". " << field << std::endl << std::flush; } }
The template parameter predicate may take the form of a operator()
:
class JSON_fields { public: bool operator()(TABLE const *table, size_t column_index) { return table->field[column_index]->type() != MYSQL_TYPE_JSON; }
void print_json_fields(TABLE *table) { Table_columns_view<JSON_fields &> fields{table, *this}; for (auto field : fields) { std::cout << field->field_index << ". " << field << std::endl << std::flush; } } };
The template parameter predicate may take the form of a lambda function:
void print_int_fields(TABLE *table) { Table_columns_view<> fields{ table, [](TABLE const *table, size_t column_index) -> bool { return table->field[column_index]->type() != MYSQL_TYPE_INT24; }};
for (auto field : fields) { std::cout << field->field_index << ". " << field << std::endl << std::flush; } }
The list of generated columns is kept separately in the TABLE
class, in the TABLE::vfield
member. Although we could achieve accurate filtering using the above described methods, as a performance optimization, this class allows applying the filter and iteration directly and exclusively on the generated columns. For that we can use the VFIELDS_ONLY
option:
void print_virtual_generated_columns(TABLE *table) { Table_columns_view<> fields{ table, [](TABLE const *table, size_t column_index) -> bool { return table->field[column_index]->is_virtual_gcol(); }, Table_columns_view<>::VFIELDS_ONLY };
for (auto field : fields) { std::cout << field->field_index << ". " << field << std::endl << std::flush; } }
using Table_columns_view< ExclusionFilter >::filter_fn_type = ExclusionFilter |
Alias for the predicate type, for readability purposes.
Table_columns_view< F >::Table_columns_view | ( | unsigned long | options = 0 , |
typename std::enable_if< std::is_same< U, std::function< bool(TABLE const *, size_t)> >::value >::type * | = nullptr |
||
) |
Empty constructor, only available when the predicate type is a lambda function.
options | optional parameter for filtering and iterating options. Options should be combined with | . Available options are VFIELDS_ONLY . |
Table_columns_view< F >::Table_columns_view | ( | TABLE const * | table, |
unsigned long | options = 0 , |
||
typename std::enable_if< std::is_same< U, std::function< bool(TABLE const *, size_t)> >::value >::type * | = nullptr |
||
) |
Constructor that takes the target TABLE
object, only available when the predicate type is a lambda function.
table | reference to the target TABLE object. |
options | optional parameter for filtering and iterating options. Options should be combined with | . Available options are VFIELDS_ONLY . |
Table_columns_view< ExclusionFilter >::Table_columns_view | ( | ExclusionFilter | filtering_predicate, |
unsigned long | options = 0 |
||
) |
Constructor which takes a predicate used to filter this container iteration.
filtering_predicate | the predicate to filter this container iteration. |
options | optional parameter for filtering and iterating options. Options should be combined with | . Available options are VFIELDS_ONLY . |
Table_columns_view< ExclusionFilter >::Table_columns_view | ( | TABLE const * | table, |
ExclusionFilter | filtering_predicate, | ||
unsigned long | options = 0 |
||
) |
Constructor which takes the TABLE object whose field set will be iterated and a predicate used to filter this container iteration.
table | reference to the target TABLE object. |
filtering_predicate | the predicate to filter this container iteration. |
options | optional parameter for filtering and iterating options. Options should be combined with | . Available options are VFIELDS_ONLY . |
|
virtual |
Destructor for the class.
|
delete |
|
delete |
Table_columns_view< ExclusionFilter >::Table_columns_view | ( | F | filtering_predicate, |
unsigned long | options | ||
) |
Table_columns_view< ExclusionFilter >::Table_columns_view | ( | TABLE const * | target, |
F | filtering_predicate, | ||
unsigned long | options | ||
) |
size_t Table_columns_view< F >::absolute_size |
Computes the total number of fields in the table.
|
virtual |
Creates an iterator object, pointing at the beginning of the table field set.
Reimplemented in cs::util::ReplicatedColumnsViewWithGipkOnSource.
|
staticprivate |
Default filtering predicate.
|
virtual |
Creates an iterator object, pointing at the end of the table field set.
size_t Table_columns_view< F >::filtered_size |
Computes the total number of fields after filtering.
Table_columns_view< F >::iterator Table_columns_view< F >::find_by_absolute_pos | ( | size_t | absolute_pos | ) |
Returns the iterator for the (absolute) position in the table.
absolute_pos | the position in the local table |
MY_BITMAP & Table_columns_view< F >::get_excluded_fields_bitmap |
Returns the bitmap for the columns from the local table set that are to be excluded from the replicated row.
MY_BITMAP & Table_columns_view< F >::get_included_fields_bitmap |
Returns the bitmap for the columns from the local table set that are to be included in the replicated row.
|
protected |
Initializes the internal included and excluded fields bitmaps.
After each member is set, this method should be invoked in order to remake the bitmaps.
bool Table_columns_view< F >::is_excluded | ( | size_t | index | ) | const |
Returns whether or not the field at index
is to be excluded from the field set iteration process.
index | the index of the field to test for exclusion from iteration. |
|
delete |
|
delete |
|
virtual |
Setter which initializes the internal filtering predicate of type ExclusionFilter
.
rhs | reference to the target filtering predicate ExclusionFilter |
|
virtual |
Setter which initializes the internal reference to the TABLE object whose field set will be iterated over.
rhs | reference to the target TABLE object |
Table_columns_view< F > & Table_columns_view< F >::translate_bitmap | ( | MY_BITMAP & | source, |
MY_BITMAP & | destination | ||
) |
Takes a bitmap object, as received from the replication channel and translates it to a bitmap that matches the local TABLE object.
[in] | source | the bitmap as received from the replication channel |
[out] | destination | the bitmap that matches the local TABLE format |
size_t Table_columns_view< F >::translate_position | ( | size_t | source | ) |
For the absolute position on the table that equals the given position given as a parameter, return the translated position.
source | the position in the local table |
|
staticconstexpr |
Default set of options.
|
private |
Bitmap that holds the information about which columns from the local table are to be excluded from the replicated row.
|
private |
Number of columns to include in iteration.
|
private |
ExclusionFiltering predicate to be invoked when determining if a column is to be included in the iteration.
|
private |
Bitmap that holds the information about which columns from the local table are to be included in the replicated row.
|
private |
Set of options to apply to view behaviour.
|
private |
The TABLE object reference which contains the field set to be iterated over.
|
staticconstexpr |
Request the view excluding filter to operate TABLE::vfields
instead of the full set.