MySQL  8.0.19
Source Code Documentation
Table_function_json Class Referencefinal

#include <table_function.h>

Inheritance diagram for Table_function_json:
Table_function

Public Member Functions

 Table_function_json (THD *thd_arg, const char *alias, Item *a, List< Json_table_column > *cols)
 
const char * func_name () const override
 Returns function's name. More...
 
bool init () override
 Initialize the table function before creation of result table. More...
 
bool fill_result_table () override
 Execute table function. More...
 
table_map used_tables () override
 Return table_map of tables used by function's data source. More...
 
bool print (String *str, enum_query_type query_type) override
 JSON_TABLE printout. More...
 
bool walk (Item_processor processor, enum_walk walk, uchar *arg) override
 
- Public Member Functions inherited from Table_function
 Table_function (THD *thd_arg)
 
virtual ~Table_function ()
 
bool create_result_table (ulonglong options, const char *table_alias)
 Create, but not instantiate the result table. More...
 
bool write_row ()
 Write current record to the result table and handle overflow to disk. More...
 
Fieldget_field (uint i)
 Returns a field with given index. More...
 
void empty_table ()
 Delete all rows in the table. More...
 
void default_row ()
 Set the default row. More...
 
virtual bool init_args ()
 Initialize table function after the result table has been created. More...
 
void cleanup ()
 Clean up table function. More...
 

Private Member Functions

bool fill_json_table ()
 Fill the result table. More...
 
bool init_json_table_col_lists (uint *nest_idx, Json_table_column *parent)
 Prepare lists used to create tmp table and function execution. More...
 
void set_subtree_to_null (Json_table_column *root, Json_table_column **last)
 Set all underlying columns of a NESTED PATH to nullptr. More...
 
bool print_nested_path (Json_table_column *col, String *str, enum_query_type query_type)
 Helper function to print single NESTED PATH column. More...
 
List< Create_field > * get_field_list () override
 Return list of fields to create result table from. More...
 
bool do_init_args () override
 Check whether given default values can be saved to fields. More...
 
void do_cleanup () override
 

Private Attributes

std::array< JT_data_source, MAX_NESTED_PATHm_jds
 Array of JSON Data Source for each NESTED PATH clause. More...
 
List< Json_table_columnm_vt_list
 List of fields for tmp table creation. More...
 
List< Json_table_column > * m_columns
 Tree of COLUMN clauses. More...
 
Mem_root_array< Json_table_column * > m_all_columns
 Array of all columns - the flattened tree above. More...
 
const char * m_table_alias
 JSON_TABLE's alias, for error reporting. More...
 
bool is_source_parsed
 Whether source data has been parsed. More...
 
Itemsource
 JSON_TABLE's data source expression. More...
 

Additional Inherited Members

- Protected Attributes inherited from Table_function
THDthd
 Thread handler. More...
 
TABLEtable
 Table function's result table. More...
 
bool inited
 Whether the table funciton was already initialized. More...
 

Constructor & Destructor Documentation

◆ Table_function_json()

Table_function_json::Table_function_json ( THD thd_arg,
const char *  alias,
Item a,
List< Json_table_column > *  cols 
)

Member Function Documentation

◆ do_cleanup()

void Table_function_json::do_cleanup ( )
overrideprivatevirtual

Reimplemented from Table_function.

◆ do_init_args()

bool Table_function_json::do_init_args ( )
overrideprivatevirtual

Check whether given default values can be saved to fields.

Returns
true a conversion error occurred false defaults can be saved or aren't specified

Implements Table_function.

◆ fill_json_table()

bool Table_function_json::fill_json_table ( )
private

Fill the result table.

Fill json table.

Returns
true on error false on success

This function goes along the flattened list of columns and updates them by calling fill_column(). As it goes, it pushes all nested path nodes to 'nested' list, using it as a stack. After writing a row, it checks whether there's more data in the right-most nested path (top in the stack). If there is, it advances path's iterator, if no - pops the path from stack and goes to the next nested path (i.e more to left). When stack is empty, then the loop is over and all data (if any) was stored in the table, and function exits. Otherwise, the list of columns is positioned to the top nested path in the stack and incremented to the column after the nested path, then the loop of updating columns is executed again. So, whole execution could look as follows:

columns (                      <-- npr
  cr1,
  cr2,
  nested path .. columns (     <-- np1
    c11,
    nested path .. columns (   <-- np2
      c21
    )
  )
)

iteration | columns updated in the loop
1           npr cr1 cr2 np1 c11 np2 c21
2                                   c21
3                                   c21
4                           c11 np2 c21
5                                   c21
6                           c11 np2 c21
7                                   c21
8           npr cr1 cr2 np1 c11 np2 c21
9                                   c21

10 c11 np2 c21 Note that result table's row isn't automatically reset and if a column isn't updated, its data is written multiple times. E.g. cr1 in the example above is updated 2 times, but is written 10 times. This allows to save cycles on updating fields that for sure haven't been changed.

When there's sibling nested paths, i.e two or more nested paths in the same columns clause, then they're processed one at a time. Started with first, and the rest are set to null with help f set_subtree_to_null(). When the first sibling nested path runs out of rows, it's set to null and processing moves on to the next one.

Returns
false table filled true error occurred

◆ fill_result_table()

bool Table_function_json::fill_result_table ( )
overridevirtual

Execute table function.

Returns
true on error false on success

Implements Table_function.

◆ func_name()

const char* Table_function_json::func_name ( ) const
inlineoverridevirtual

Returns function's name.

Implements Table_function.

◆ get_field_list()

List< Create_field > * Table_function_json::get_field_list ( )
overrideprivatevirtual

Return list of fields to create result table from.

Implements Table_function.

◆ init()

bool Table_function_json::init ( )
overridevirtual

Initialize the table function before creation of result table.

Returns
true on error false on success

Implements Table_function.

◆ init_json_table_col_lists()

bool Table_function_json::init_json_table_col_lists ( uint nest_idx,
Json_table_column parent 
)
private

Prepare lists used to create tmp table and function execution.

Initialize columns and lists for json table.

Parameters
nest_idxindex of parent's element in the nesting data array
parentParent of the NESTED PATH clause being initialized
Returns
true on error false on success

This function does several things: 1) sets up list of fields (vt_list) for result table creation 2) fills array of all columns (m_all_columns) for execution 3) for each column that has default ON EMPTY or ON ERROR clauses, checks the value to be proper json and initializes column appropriately 4) for each column that involves path, the path is checked to be correct. The function goes recursively, starting from the top NESTED PATH clause and going in the depth-first way, traverses the tree of columns.

Parameters
nest_idxindex of parent's element in the nesting data array
parentParent of the NESTED PATH clause being initialized
Returns
false ok true an error occurred

◆ print()

bool Table_function_json::print ( String str,
enum_query_type  query_type 
)
overridevirtual

JSON_TABLE printout.

Parameters
strstring to print to
query_typetype of query
Returns
true on error false on success

Implements Table_function.

◆ print_nested_path()

bool Table_function_json::print_nested_path ( Json_table_column col,
String str,
enum_query_type  query_type 
)
private

Helper function to print single NESTED PATH column.

Parameters
colcolumn to print
strstring to print to
query_typetype of the query
Returns
true on error false on success

◆ set_subtree_to_null()

void Table_function_json::set_subtree_to_null ( Json_table_column root,
Json_table_column **  last 
)
private

Set all underlying columns of a NESTED PATH to nullptr.

A helper function which sets all columns under given NESTED PATH column to nullptr.

Parameters
rootroot NESTED PATH column
[out]lastlast column which belongs to the given NESTED PATH

Used to evaluate sibling NESTED PATHS.

Parameters
rootroot NESTED PATH column
[out]lastlast column which belongs to the given NESTED PATH

◆ used_tables()

table_map Table_function_json::used_tables ( )
overridevirtual

Return table_map of tables used by function's data source.

Reimplemented from Table_function.

◆ walk()

bool Table_function_json::walk ( Item_processor  processor,
enum_walk  walk,
uchar arg 
)
overridevirtual

Implements Table_function.

Member Data Documentation

◆ is_source_parsed

bool Table_function_json::is_source_parsed
private

Whether source data has been parsed.

◆ m_all_columns

Mem_root_array<Json_table_column *> Table_function_json::m_all_columns
private

Array of all columns - the flattened tree above.

◆ m_columns

List<Json_table_column>* Table_function_json::m_columns
private

Tree of COLUMN clauses.

◆ m_jds

std::array<JT_data_source, MAX_NESTED_PATH> Table_function_json::m_jds
private

Array of JSON Data Source for each NESTED PATH clause.

◆ m_table_alias

const char* Table_function_json::m_table_alias
private

JSON_TABLE's alias, for error reporting.

◆ m_vt_list

List<Json_table_column> Table_function_json::m_vt_list
private

List of fields for tmp table creation.

◆ source

Item* Table_function_json::source
private

JSON_TABLE's data source expression.


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