1 #ifndef CEPH_RGW_ES_QUERY_H
2 #define CEPH_RGW_ES_QUERY_H
4 #include "rgw_string.h"
8 list<string>::iterator iter;
11 ESQueryStack(list<string>& src) {
17 void assign(list<string>& src) {
22 bool peek(string *dest) {
30 bool pop(string *dest) {
31 bool valid = peek(dest);
40 return (iter == l.end());
44 class ESInfixQueryParser {
51 void skip_whitespace(const char *str, int size, int& pos);
52 bool get_next_token(bool (*filter)(char));
54 bool parse_condition();
56 bool parse_specific_char(const char *pchar);
57 bool parse_open_bracket();
58 bool parse_close_bracket();
61 ESInfixQueryParser(const string& _query) : query(_query), size(query.size()), str(query.c_str()) {}
62 bool parse(list<string> *result);
67 struct ESEntityTypeMap {
75 map<string, EntityType> m;
77 ESEntityTypeMap(map<string, EntityType>& _m) : m(_m) {}
79 bool find(const string& entity, EntityType *ptype) {
80 auto i = m.find(entity);
86 *ptype = ES_ENTITY_NONE;
91 class ESQueryCompiler {
92 ESInfixQueryParser parser;
94 ESQueryNode *query_root{nullptr};
98 bool convert(list<string>& infix, string *perr);
100 list<pair<string, string> > eq_conds;
102 ESEntityTypeMap *generic_type_map{nullptr};
103 ESEntityTypeMap *custom_type_map{nullptr};
105 map<string, string, ltstr_nocase> *field_aliases = nullptr;
106 set<string> *restricted_fields = nullptr;
109 ESQueryCompiler(const string& query, list<pair<string, string> > *prepend_eq_conds, const string& _custom_prefix) : parser(query), custom_prefix(_custom_prefix) {
110 if (prepend_eq_conds) {
111 eq_conds = std::move(*prepend_eq_conds);
116 bool compile(string *perr);
117 void dump(Formatter *f) const;
119 void set_generic_type_map(ESEntityTypeMap *entity_map) {
120 generic_type_map = entity_map;
123 ESEntityTypeMap *get_generic_type_map() {
124 return generic_type_map;
126 const string& get_custom_prefix() { return custom_prefix; }
128 void set_custom_type_map(ESEntityTypeMap *entity_map) {
129 custom_type_map = entity_map;
132 ESEntityTypeMap *get_custom_type_map() {
133 return custom_type_map;
136 void set_field_aliases(map<string, string, ltstr_nocase> *fa) {
140 string unalias_field(const string& field) {
141 if (!field_aliases) {
144 auto i = field_aliases->find(field);
145 if (i == field_aliases->end()) {
152 void set_restricted_fields(set<string> *rf) {
153 restricted_fields = rf;
156 bool is_restricted(const string& f) {
157 return (restricted_fields && restricted_fields->find(f) != restricted_fields->end());