1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #ifndef CEPH_RGW_ES_QUERY_H
5 #define CEPH_RGW_ES_QUERY_H
7 #include "rgw_string.h"
11 list
<string
>::iterator iter
;
14 explicit ESQueryStack(list
<string
>& src
) {
20 void assign(list
<string
>& src
) {
25 bool peek(string
*dest
) {
33 bool pop(string
*dest
) {
34 bool valid
= peek(dest
);
43 return (iter
== l
.end());
47 class ESInfixQueryParser
{
54 void skip_whitespace(const char *str
, int size
, int& pos
);
55 bool get_next_token(bool (*filter
)(char));
57 bool parse_condition();
59 bool parse_specific_char(const char *pchar
);
60 bool parse_open_bracket();
61 bool parse_close_bracket();
64 explicit ESInfixQueryParser(const string
& _query
) : query(_query
), size(query
.size()), str(query
.c_str()) {}
65 bool parse(list
<string
> *result
);
70 struct ESEntityTypeMap
{
78 map
<string
, EntityType
> m
;
80 explicit ESEntityTypeMap(map
<string
, EntityType
>& _m
) : m(_m
) {}
82 bool find(const string
& entity
, EntityType
*ptype
) {
83 auto i
= m
.find(entity
);
89 *ptype
= ES_ENTITY_NONE
;
94 class ESQueryCompiler
{
95 ESInfixQueryParser parser
;
97 ESQueryNode
*query_root
{nullptr};
101 bool convert(list
<string
>& infix
, string
*perr
);
103 list
<pair
<string
, string
> > eq_conds
;
105 ESEntityTypeMap
*generic_type_map
{nullptr};
106 ESEntityTypeMap
*custom_type_map
{nullptr};
108 map
<string
, string
, ltstr_nocase
> *field_aliases
= nullptr;
109 set
<string
> *restricted_fields
= nullptr;
112 ESQueryCompiler(const string
& query
, list
<pair
<string
, string
> > *prepend_eq_conds
, const string
& _custom_prefix
) : parser(query
), custom_prefix(_custom_prefix
) {
113 if (prepend_eq_conds
) {
114 eq_conds
= std::move(*prepend_eq_conds
);
119 bool compile(string
*perr
);
120 void dump(Formatter
*f
) const;
122 void set_generic_type_map(ESEntityTypeMap
*entity_map
) {
123 generic_type_map
= entity_map
;
126 ESEntityTypeMap
*get_generic_type_map() {
127 return generic_type_map
;
129 const string
& get_custom_prefix() { return custom_prefix
; }
131 void set_custom_type_map(ESEntityTypeMap
*entity_map
) {
132 custom_type_map
= entity_map
;
135 ESEntityTypeMap
*get_custom_type_map() {
136 return custom_type_map
;
139 void set_field_aliases(map
<string
, string
, ltstr_nocase
> *fa
) {
143 string
unalias_field(const string
& field
) {
144 if (!field_aliases
) {
147 auto i
= field_aliases
->find(field
);
148 if (i
== field_aliases
->end()) {
155 void set_restricted_fields(set
<string
> *rf
) {
156 restricted_fields
= rf
;
159 bool is_restricted(const string
& f
) {
160 return (restricted_fields
&& restricted_fields
->find(f
) != restricted_fields
->end());