MySQL 8.0.39
Source Code Documentation
histograms::Error_context Class Reference

Error context to validate given JSON object which represents a histogram. More...

#include <histogram.h>

Public Member Functions

 Error_context ()
 Default constructor. More...
 
 Error_context (THD *thd, Field *field, results_map *results)
 Constructor. More...
 
void report_global (Message err_code)
 Report a global error to this context. More...
 
void report_missing_attribute (const std::string &name)
 Report to this context that a required attribute is missing. More...
 
void report_node (const Json_dom *dom, Message err_code)
 Report to this context that an error occurs on the given dom node. More...
 
template<typename T >
bool check_value (T *v)
 Check if the value is in the field definition domain. More...
 
bool binary () const
 Tell whether the input json is an internal persisted copy or a user-defined input. More...
 
Fieldfield () const
 Return data-type of field in context if present. More...
 

Private Attributes

THDm_thd
 Thread context for error handlers. More...
 
Fieldm_field
 The field for checking endpoint values. More...
 
results_mapm_results
 Where reported errors are stored. More...
 
bool m_binary
 Whether or not the JSON object to process is in binary format. More...
 

Detailed Description

Error context to validate given JSON object which represents a histogram.

A validation error consists of two pieces of information:

1) error code - what kind of error it is 2) JSON path - where the error occurs

Errors are classified into a few conceptual categories, namely

1) absence of required attributes 2) unexpected JSON type of attributes 3) value encoding corruption 4) value out of domain 5) breaking bucket sequence semantics 6) breaking certain constraint between pieces of information

See also
histograms::Message for the list of JSON validation errors.

Use of the Error_context class

An Error_context object is passed along with other parameters to the json_to_histogram() function that is used to create a histogram object (e.g. Equi_height<longlong>) from a JSON string.

The json_to_histogram() function has two different use cases, with different requirements for validation:

1) Deserializing a histogram that was retrieved from the dictionary. In this case the histogram has already been validated, and the user is not expecting validation feedback, so we pass along a default-constructed "empty shell" Error_context object with no-op operations.

2) When validating the user-supplied JSON string to the UPDATE HISTOGRAM ... USING DATA commmand. In this case we pass along an active Error_context object that uses a Field object to validate bucket values, and stores results in a results_map.

The binary() method is used to distinguish between these two contexts/cases.

Constructor & Destructor Documentation

◆ Error_context() [1/2]

histograms::Error_context::Error_context ( )
inline

Default constructor.

Used when deserializing binary JSON that has already been validated, e.g. when retrieving a histogram from the dictionary, and the Error_context object is not actively used for validation.

◆ Error_context() [2/2]

histograms::Error_context::Error_context ( THD thd,
Field field,
results_map results 
)
inline

Constructor.

Used in the context of deserializing the user-supplied JSON string to the UPDATE HISTOGRAM ... USING DATA command.

Parameters
thdThread context
fieldThe field for values on which the histogram is built
resultsWhere reported errors are stored

Member Function Documentation

◆ binary()

bool histograms::Error_context::binary ( ) const
inline

Tell whether the input json is an internal persisted copy or a user-defined input.

If the input is an internal copy, there should never be type/format errors. If it is a user-defined input, errors may occur and should be handled, and some type casting may be needed.

Returns
true for JSON, false otherwise

◆ check_value()

template<typename T >
template bool histograms::Error_context::check_value ( T *  v)

Check if the value is in the field definition domain.

Parameters
vPointer to the value.
Returns
true on error, false otherwise
Note
Uses Field::store() on the field for which the user-defined histogram is to be constructed in order to check the validity of the supplied value. This will have the side effect of writing to the record buffer so this should only be used with an active Error_context (with a non-nullptr field) when we do not otherwise expect to use the record buffer. Currently the only use case is to validate the JSON input to the command UPDATE HISTOGRAM ... USING DATA where it should be OK to use the field for this purpose.

◆ field()

Field * histograms::Error_context::field ( ) const
inline

Return data-type of field in context if present.

Used to enforce that histogram datatype matches column datatype for user-defined histograms.

Returns
datatype string if present, nullptr if not

◆ report_global()

void histograms::Error_context::report_global ( Message  err_code)

Report a global error to this context.

Parameters
err_codeThe global error code

◆ report_missing_attribute()

void histograms::Error_context::report_missing_attribute ( const std::string &  name)

Report to this context that a required attribute is missing.

Parameters
nameName of the missing attribute

◆ report_node()

void histograms::Error_context::report_node ( const Json_dom dom,
Message  err_code 
)

Report to this context that an error occurs on the given dom node.

Parameters
domThe given dom node
err_codeThe error code

Member Data Documentation

◆ m_binary

bool histograms::Error_context::m_binary
private

Whether or not the JSON object to process is in binary format.

◆ m_field

Field* histograms::Error_context::m_field
private

The field for checking endpoint values.

◆ m_results

results_map* histograms::Error_context::m_results
private

Where reported errors are stored.

◆ m_thd

THD* histograms::Error_context::m_thd
private

Thread context for error handlers.


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