MySQL 9.5.0
Source Code Documentation
filter_object_generator.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2025, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_REST_MRS_SRC_MRS_DATABASE_FILTER_OBJECT_GENERATOR_H_
27#define ROUTER_SRC_REST_MRS_SRC_MRS_DATABASE_FILTER_OBJECT_GENERATOR_H_
28
29#include <list>
30#include <memory>
31#include <optional>
32#include <string>
33
34#ifdef RAPIDJSON_NO_SIZETYPEDEFINE
35#include "my_rapidjson_size_t.h"
36#endif
37
38#include <rapidjson/document.h>
40
41namespace mrs {
42namespace database {
43
45 public:
46 using Document = rapidjson::Document;
47 using Object = Document::ConstObject;
48 using Value = const Document::ValueType;
49
50 public:
51 FilterObjectGenerator(std::shared_ptr<database::entry::Object> object = {},
52 bool joins_allowed = false, uint64_t wait_timeout = 0,
53 bool use_wait_in_where = true);
54
55 void reconfigure(uint64_t wait_timeout = 0, bool use_wait_in_where = true);
56 void parse(const std::string &filter_query);
59 bool has_where(bool filter_only = true) const;
60 bool has_order() const;
61 bool has_asof() const;
62
63 enum Clear { kWhere = 1, kOrder = 2, kAsof = 4, kAll = 7 };
64 void reset(const Clear clear = Clear::kAll);
65
66 private:
67 void parse(const Document &doc);
68
69 std::optional<mysqlrouter::sqlstring> parse_simple_operator_object(
70 const std::string_view &column_name, Value *value);
71 std::optional<mysqlrouter::sqlstring> parse_complex_operator_object(
72 const std::string_view &column_name, Value *value,
73 const std::string_view &complex_key);
74 std::optional<mysqlrouter::sqlstring> parse_complex_value(
75 const std::string_view &column_name, Value *value);
76 std::optional<mysqlrouter::sqlstring> parse_complex_values(
77 const std::string_view &column_name, Value *value,
78 const std::string_view &complex_key);
79 std::optional<mysqlrouter::sqlstring> parse_column_object(
80 const std::string_view &column_name, Value *value);
81 std::optional<mysqlrouter::sqlstring> parse_direct_value(
82 const std::string_view &column_name, Value *value);
83 std::optional<mysqlrouter::sqlstring> parse_match(Value *value);
85 void parse_order(Object object);
86 void parse_asof(Value *value);
87 bool parse_wmember(const std::string_view &name, Value *value);
88 std::pair<std::shared_ptr<entry::Table>, std::shared_ptr<entry::Column>>
89 resolve_field(const std::string_view &name);
91 const std::shared_ptr<entry::Table> &table,
92 const std::shared_ptr<entry::Column> &dfield,
93 const std::string_view &name, bool for_sorting) const;
94
95 std::shared_ptr<database::entry::Object> object_metadata_;
96 bool joins_allowed_{false};
97 bool empty_{true};
99 std::list<std::string> argument_;
102 uint64_t wait_timeout_{0};
104};
105
106} // namespace database
107} // namespace mrs
108
109#endif // ROUTER_SRC_REST_MRS_SRC_MRS_DATABASE_FILTER_OBJECT_GENERATOR_H_
Definition: filter_object_generator.h:44
mysqlrouter::sqlstring get_result() const
Definition: filter_object_generator.cc:287
bool has_where(bool filter_only=true) const
Definition: filter_object_generator.cc:720
std::optional< mysqlrouter::sqlstring > parse_complex_value(const std::string_view &column_name, Value *value)
Definition: filter_object_generator.cc:365
bool has_asof() const
Definition: filter_object_generator.cc:729
const Document::ValueType Value
Definition: filter_object_generator.h:48
void parse_order(Object object)
Definition: filter_object_generator.cc:764
mysqlrouter::sqlstring order_
Definition: filter_object_generator.h:100
std::optional< mysqlrouter::sqlstring > parse_direct_value(const std::string_view &column_name, Value *value)
Definition: filter_object_generator.cc:583
bool empty_
Definition: filter_object_generator.h:97
std::optional< mysqlrouter::sqlstring > parse_complex_operator_object(const std::string_view &column_name, Value *value, const std::string_view &complex_key)
Definition: filter_object_generator.cc:392
Clear
Definition: filter_object_generator.h:63
@ kAll
Definition: filter_object_generator.h:63
@ kWhere
Definition: filter_object_generator.h:63
@ kAsof
Definition: filter_object_generator.h:63
@ kOrder
Definition: filter_object_generator.h:63
std::list< std::string > argument_
Definition: filter_object_generator.h:99
uint64_t wait_timeout_
Definition: filter_object_generator.h:102
bool parse_wmember(const std::string_view &name, Value *value)
Definition: filter_object_generator.cc:736
std::optional< mysqlrouter::sqlstring > parse_simple_operator_object(const std::string_view &column_name, Value *value)
Definition: filter_object_generator.cc:413
mysqlrouter::sqlstring resolve_field_name(const std::shared_ptr< entry::Table > &table, const std::shared_ptr< entry::Column > &dfield, const std::string_view &name, bool for_sorting) const
Definition: filter_object_generator.cc:824
void parse_orderby_asof_wmember(Object object)
Definition: filter_object_generator.cc:338
void reset(const Clear clear=Clear::kAll)
Definition: filter_object_generator.cc:304
bool use_wait_in_where_
Definition: filter_object_generator.h:103
std::shared_ptr< database::entry::Object > object_metadata_
Definition: filter_object_generator.h:95
void parse(const std::string &filter_query)
Definition: filter_object_generator.cc:330
rapidjson::Document Document
Definition: filter_object_generator.h:46
std::optional< mysqlrouter::sqlstring > parse_match(Value *value)
Definition: filter_object_generator.cc:521
void parse_asof(Value *value)
Definition: filter_object_generator.cc:756
std::optional< mysqlrouter::sqlstring > parse_complex_values(const std::string_view &column_name, Value *value, const std::string_view &complex_key)
Definition: filter_object_generator.cc:621
mysqlrouter::sqlstring get_asof() const
Definition: filter_object_generator.cc:716
mysqlrouter::sqlstring asof_gtid_
Definition: filter_object_generator.h:101
bool has_order() const
Definition: filter_object_generator.cc:727
mysqlrouter::sqlstring where_
Definition: filter_object_generator.h:98
Document::ConstObject Object
Definition: filter_object_generator.h:47
void reconfigure(uint64_t wait_timeout=0, bool use_wait_in_where=true)
Definition: filter_object_generator.cc:281
FilterObjectGenerator(std::shared_ptr< database::entry::Object > object={}, bool joins_allowed=false, uint64_t wait_timeout=0, bool use_wait_in_where=true)
Definition: filter_object_generator.cc:273
std::optional< mysqlrouter::sqlstring > parse_column_object(const std::string_view &column_name, Value *value)
Definition: filter_object_generator.cc:691
std::pair< std::shared_ptr< entry::Table >, std::shared_ptr< entry::Column > > resolve_field(const std::string_view &name)
Definition: filter_object_generator.cc:817
bool joins_allowed_
Definition: filter_object_generator.h:96
Definition: object.h:347
Definition: utils_sqlstring.h:67
Define rapidjson::SizeType to be std::uint64_t.
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
FilterObjectGenerator::Value Value
Definition: filter_object_generator.cc:51
Definition: authorize_manager.h:48
static mysql_service_status_t clear(reference_caching_channel channel) noexcept
Definition: component.cc:146