MySQL 8.0.40
Source Code Documentation
Table_columns_view< ExclusionFilter > Class Template Reference

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>

Inheritance diagram for Table_columns_view< ExclusionFilter >:
[legend]

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_viewset_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_viewset_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_viewoperator= (const Table_columns_view &rhs)=delete
 
Table_columns_viewoperator= (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_BITMAPget_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_BITMAPget_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_viewtranslate_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_viewinit_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...
 

Detailed Description

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
class Table_columns_view< ExclusionFilter >

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; } }

Member Typedef Documentation

◆ filter_fn_type

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
using Table_columns_view< ExclusionFilter >::filter_fn_type = ExclusionFilter

Alias for the predicate type, for readability purposes.

Constructor & Destructor Documentation

◆ Table_columns_view() [1/8]

template<typename F >
template<typename U >
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.

Parameters
optionsoptional parameter for filtering and iterating options. Options should be combined with |. Available options are VFIELDS_ONLY.

◆ Table_columns_view() [2/8]

template<typename F >
template<typename U >
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.

Parameters
tablereference to the target TABLE object.
optionsoptional parameter for filtering and iterating options. Options should be combined with |. Available options are VFIELDS_ONLY.

◆ Table_columns_view() [3/8]

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
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.

Parameters
filtering_predicatethe predicate to filter this container iteration.
optionsoptional parameter for filtering and iterating options. Options should be combined with |. Available options are VFIELDS_ONLY.

◆ Table_columns_view() [4/8]

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
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.

Parameters
tablereference to the target TABLE object.
filtering_predicatethe predicate to filter this container iteration.
optionsoptional parameter for filtering and iterating options. Options should be combined with |. Available options are VFIELDS_ONLY.

◆ ~Table_columns_view()

template<typename F >
Table_columns_view< F >::~Table_columns_view
virtual

Destructor for the class.

◆ Table_columns_view() [5/8]

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
Table_columns_view< ExclusionFilter >::Table_columns_view ( const Table_columns_view< ExclusionFilter > &  rhs)
delete

◆ Table_columns_view() [6/8]

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
Table_columns_view< ExclusionFilter >::Table_columns_view ( Table_columns_view< ExclusionFilter > &&  rhs)
delete

◆ Table_columns_view() [7/8]

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
template<typename F >
Table_columns_view< ExclusionFilter >::Table_columns_view ( filtering_predicate,
unsigned long  options 
)

◆ Table_columns_view() [8/8]

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
template<typename F >
Table_columns_view< ExclusionFilter >::Table_columns_view ( TABLE const *  target,
filtering_predicate,
unsigned long  options 
)

Member Function Documentation

◆ absolute_size()

template<typename F >
size_t Table_columns_view< F >::absolute_size

Computes the total number of fields in the table.

Returns
the number of fields in the table.

◆ begin()

template<typename F >
Table_columns_view< F >::iterator Table_columns_view< F >::begin ( void  )
virtual

Creates an iterator object, pointing at the beginning of the table field set.

Returns
an iterator pointing to the beginning of the field set.

Reimplemented in cs::util::ReplicatedColumnsViewWithGipkOnSource.

◆ default_filter()

template<typename F >
bool Table_columns_view< F >::default_filter ( TABLE const *  table,
size_t  column_index 
)
staticprivate

Default filtering predicate.

◆ end()

template<typename F >
Table_columns_view< F >::iterator Table_columns_view< F >::end ( void  )
virtual

Creates an iterator object, pointing at the end of the table field set.

Returns
an iterator pointing to the end of the field set.

◆ filtered_size()

template<typename F >
size_t Table_columns_view< F >::filtered_size

Computes the total number of fields after filtering.

Returns
the number of fields after filtering.

◆ find_by_absolute_pos()

template<typename F >
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.

Parameters
absolute_posthe position in the local table
Returns
the iterator for the position, if found

◆ get_excluded_fields_bitmap()

template<typename F >
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.

Returns
a bitmap indicating which columns from the local table are to be excluded from the replicated row.

◆ get_included_fields_bitmap()

template<typename F >
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.

Returns
a bitmap indicating which columns from the local table are to be included in the replicated row.

◆ init_fields_bitmaps()

template<typename F >
Table_columns_view< F > & Table_columns_view< F >::init_fields_bitmaps
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.

Returns
this object reference (for chaining purposes).

◆ is_excluded()

template<typename F >
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.

Parameters
indexthe index of the field to test for exclusion from iteration.
Returns
true if the field is to be excluded from the iteration, false otherwise.

◆ operator=() [1/2]

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
Table_columns_view & Table_columns_view< ExclusionFilter >::operator= ( const Table_columns_view< ExclusionFilter > &  rhs)
delete

◆ operator=() [2/2]

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
Table_columns_view & Table_columns_view< ExclusionFilter >::operator= ( Table_columns_view< ExclusionFilter > &&  rhs)
delete

◆ set_filter()

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
Table_columns_view< F > & Table_columns_view< F >::set_filter ( ExclusionFilter  rhs)
virtual

Setter which initializes the internal filtering predicate of type ExclusionFilter.

Parameters
rhsreference to the target filtering predicate ExclusionFilter
Returns
a reference to this object.

◆ set_table()

template<typename F >
Table_columns_view< F > & Table_columns_view< F >::set_table ( const TABLE rhs)
virtual

Setter which initializes the internal reference to the TABLE object whose field set will be iterated over.

Parameters
rhsreference to the target TABLE object
Returns
a reference to this object.

◆ translate_bitmap()

template<typename F >
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.

Parameters
[in]sourcethe bitmap as received from the replication channel
[out]destinationthe bitmap that matches the local TABLE format
Returns
this object reference (for chaining purposes).

◆ translate_position()

template<typename F >
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.

Parameters
sourcethe position in the local table
Returns
the translated position within the local table.

Member Data Documentation

◆ DEFAULTS

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
constexpr unsigned long Table_columns_view< ExclusionFilter >::DEFAULTS = 0
staticconstexpr

Default set of options.

◆ m_excluded_fields_bitmap

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
MY_BITMAP Table_columns_view< ExclusionFilter >::m_excluded_fields_bitmap
private

Bitmap that holds the information about which columns from the local table are to be excluded from the replicated row.

◆ m_filtered_size

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
size_t Table_columns_view< ExclusionFilter >::m_filtered_size {0}
private

Number of columns to include in iteration.

◆ m_filtering_predicate

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
ExclusionFilter Table_columns_view< ExclusionFilter >::m_filtering_predicate
private

ExclusionFiltering predicate to be invoked when determining if a column is to be included in the iteration.

◆ m_included_fields_bitmap

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
MY_BITMAP Table_columns_view< ExclusionFilter >::m_included_fields_bitmap
private

Bitmap that holds the information about which columns from the local table are to be included in the replicated row.

◆ m_options

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
unsigned long Table_columns_view< ExclusionFilter >::m_options {0}
private

Set of options to apply to view behaviour.

◆ m_table

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
TABLE const* Table_columns_view< ExclusionFilter >::m_table {nullptr}
private

The TABLE object reference which contains the field set to be iterated over.

◆ VFIELDS_ONLY

template<typename ExclusionFilter = std::function<bool(TABLE const *, size_t)>>
constexpr unsigned long Table_columns_view< ExclusionFilter >::VFIELDS_ONLY = 1
staticconstexpr

Request the view excluding filter to operate TABLE::vfields instead of the full set.


The documentation for this class was generated from the following file: