MySQL 9.1.0
Source Code Documentation
|
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... | |
Field * | field () const |
Return data-type of field in context if present. More... | |
Private Attributes | |
THD * | m_thd |
Thread context for error handlers. More... | |
Field * | m_field |
The field for checking endpoint values. More... | |
results_map * | m_results |
Where reported errors are stored. More... | |
bool | m_binary |
Whether or not the JSON object to process is in binary format. More... | |
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
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.
|
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.
|
inline |
Constructor.
Used in the context of deserializing the user-supplied JSON string to the UPDATE HISTOGRAM ... USING DATA command.
thd | Thread context |
field | The field for values on which the histogram is built |
results | Where reported errors are stored |
|
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.
template bool histograms::Error_context::check_value | ( | T * | v | ) |
Check if the value is in the field definition domain.
v | Pointer to the value. |
|
inline |
Return data-type of field in context if present.
Used to enforce that histogram datatype matches column datatype for user-defined histograms.
void histograms::Error_context::report_global | ( | Message | err_code | ) |
Report a global error to this context.
err_code | The global error code |
void histograms::Error_context::report_missing_attribute | ( | const std::string & | name | ) |
Report to this context that a required attribute is missing.
name | Name of the missing attribute |
Report to this context that an error occurs on the given dom node.
dom | The given dom node |
err_code | The error code |
|
private |
Whether or not the JSON object to process is in binary format.
|
private |
The field for checking endpoint values.
|
private |
Where reported errors are stored.
|
private |
Thread context for error handlers.