1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
|
/*
Copyright (C) 2013-2018 Brazil
Copyright (C) 2018-2024 Sutou Kouhei <kou@clear-code.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include "grn_db.h"
#include "grn_expr_code.h"
#include "grn_expr_executor.h"
#ifdef __cplusplus
extern "C" {
#endif
#define GRN_EXPR_CONST_BLK_SIZE GRN_STACK_SIZE
struct _grn_expr {
grn_db_obj obj;
grn_obj name_buf;
grn_expr_var *vars;
uint32_t nvars;
/* -- compatible with grn_proc -- */
uint16_t cacheable;
uint16_t taintable;
grn_obj **const_blks;
grn_obj *values;
grn_expr_code *codes;
uint32_t nconsts;
ptrdiff_t values_curr;
ptrdiff_t values_tail;
uint32_t values_size;
uint32_t codes_curr;
uint32_t codes_size;
grn_obj objs;
grn_obj dfi;
grn_expr_code *code0;
struct {
grn_expr_code *codes;
uint32_t codes_curr;
grn_expr_executor executor;
} cache;
grn_obj query_log_tag_prefix;
grn_obj *parent;
grn_obj *condition;
};
void *
grn_expr_parser_open(grn_ctx *ctx);
grn_rc
grn_expr_parser_close(grn_ctx *ctx, void *parser);
#define SCAN_ACCESSOR (0x01)
#define SCAN_PUSH (0x02)
#define SCAN_POP (0x04)
#define SCAN_PRE_CONST (0x08)
typedef enum {
SCAN_START = 0,
SCAN_VAR,
SCAN_COL1,
SCAN_COL2,
SCAN_CONST
} scan_stat;
typedef struct _grn_scan_info scan_info;
typedef bool (*grn_scan_info_each_arg_callback)(grn_ctx *ctx,
grn_obj *obj,
void *user_data);
void
grn_expr_init_from_env(void);
grn_obj *
grn_expr_get_query_options(grn_ctx *ctx, grn_obj *expr);
grn_rc
grn_expr_set_query_options(grn_ctx *ctx, grn_obj *expr, grn_obj *query_options);
scan_info **
grn_scan_info_build(
grn_ctx *ctx, grn_obj *expr, int *n, grn_operator op, bool record_exist);
scan_info *
grn_scan_info_open(grn_ctx *ctx, int start);
void
grn_scan_info_close(grn_ctx *ctx, scan_info *si);
void
grn_scan_info_put_index(grn_ctx *ctx,
scan_info *si,
grn_obj *index,
uint32_t sid,
int32_t start_position,
float weight,
grn_obj *scorer,
grn_obj *scorer_args_expr,
uint32_t scorer_args_expr_offset);
scan_info **
grn_scan_info_put_logical_op(grn_ctx *ctx,
scan_info **sis,
int *ip,
grn_operator op,
int start,
float weight_factor);
int
grn_scan_info_get_flags(scan_info *si);
void
grn_scan_info_set_flags(scan_info *si, int flags);
grn_operator
grn_scan_info_get_logical_op(scan_info *si);
void
grn_scan_info_set_logical_op(scan_info *si, grn_operator logical_op);
grn_operator
grn_scan_info_get_op(scan_info *si);
void
grn_scan_info_set_weight_factor(scan_info *si, float factor);
float
grn_scan_info_get_weight_factor(scan_info *si);
void
grn_scan_info_set_op(scan_info *si, grn_operator op);
void
grn_scan_info_set_end(scan_info *si, uint32_t end);
void
grn_scan_info_set_query(scan_info *si, grn_obj *query);
int
grn_scan_info_get_max_interval(scan_info *si);
void
grn_scan_info_set_max_interval(scan_info *si, int max_interval);
int
grn_scan_info_get_additional_last_interval(scan_info *si);
void
grn_scan_info_set_additional_last_interval(scan_info *si,
int additional_last_interval);
grn_obj *
grn_scan_info_get_max_element_intervals(scan_info *si);
void
grn_scan_info_set_max_element_intervals(grn_ctx *ctx,
scan_info *si,
grn_obj *max_element_intervals);
int
grn_scan_info_get_min_interval(scan_info *si);
void
grn_scan_info_set_min_interval(scan_info *si, int min_interval);
int
grn_scan_info_get_similarity_threshold(scan_info *si);
void
grn_scan_info_set_similarity_threshold(scan_info *si, int similarity_threshold);
int
grn_scan_info_get_quorum_threshold(scan_info *si);
void
grn_scan_info_set_quorum_threshold(scan_info *si, int quorum_threshold);
bool
grn_scan_info_push_arg(grn_ctx *ctx, scan_info *si, grn_obj *arg);
grn_obj *
grn_scan_info_get_arg(grn_ctx *ctx, scan_info *si, int i);
float
grn_expr_code_get_weight(grn_ctx *ctx, grn_expr_code *ec, uint32_t *offset);
grn_rc
grn_expr_code_inspect_indented(grn_ctx *ctx,
grn_obj *buffer,
grn_expr_code *code,
const char *indent);
void
grn_p_expr_code(grn_ctx *ctx, grn_expr_code *code);
grn_obj *
grn_expr_alloc_const(grn_ctx *ctx, grn_obj *expr);
grn_rc
grn_ctx_expand_stack(grn_ctx *ctx);
bool
grn_expr_is_simple_function_call(grn_ctx *ctx, grn_obj *expr);
grn_obj *
grn_expr_simple_function_call_get_function(grn_ctx *ctx, grn_obj *expr);
grn_rc
grn_expr_simple_function_call_get_arguments(grn_ctx *ctx,
grn_obj *expr,
grn_obj *arguments);
bool
grn_expr_is_module_list(grn_ctx *ctx, grn_obj *expr);
unsigned int
grn_expr_module_list_get_n_modules(grn_ctx *ctx, grn_obj *expr);
grn_obj *
grn_expr_module_list_get_function(grn_ctx *ctx, grn_obj *expr, unsigned int i);
grn_rc
grn_expr_module_list_get_arguments(grn_ctx *ctx,
grn_obj *expr,
unsigned int i,
grn_obj *arguments);
grn_rc
grn_expr_match_columns_split(grn_ctx *ctx,
grn_obj *expr,
grn_obj *splitted_match_columns);
grn_obj *
grn_expr_slice(grn_ctx *ctx,
grn_obj *expr,
uint32_t code_start_offset,
uint32_t code_end_offset);
grn_rc
grn_expr_to_script_syntax(grn_ctx *ctx, grn_obj *expr, grn_obj *buffer);
void
grn_expr_get_range_info(grn_ctx *ctx,
grn_obj *expr,
grn_id *range_id,
grn_obj_flags *range_flags);
uint32_t
grn_expr_get_n_logical_ops(grn_ctx *ctx, grn_obj *expr);
typedef enum {
GRN_EXPR_V1_FORMAT_TYPE_OUTPUT_COLUMNS,
GRN_EXPR_V1_FORMAT_TYPE_SORT_KEYS,
GRN_EXPR_V1_FORMAT_TYPE_GROUP_KEYS,
} grn_expr_v1_format_type;
bool
grn_expr_is_v1_format(grn_ctx *ctx,
const char *raw_text,
ssize_t raw_text_len,
grn_expr_v1_format_type type);
#ifdef __cplusplus
}
#endif
|