summaryrefslogtreecommitdiff
path: root/storage/mroonga/vendor/groonga/lib/grn_db.h
diff options
context:
space:
mode:
Diffstat (limited to 'storage/mroonga/vendor/groonga/lib/grn_db.h')
-rw-r--r--storage/mroonga/vendor/groonga/lib/grn_db.h224
1 files changed, 124 insertions, 100 deletions
diff --git a/storage/mroonga/vendor/groonga/lib/grn_db.h b/storage/mroonga/vendor/groonga/lib/grn_db.h
index 6c84ad921f4..f0fbddad882 100644
--- a/storage/mroonga/vendor/groonga/lib/grn_db.h
+++ b/storage/mroonga/vendor/groonga/lib/grn_db.h
@@ -1,5 +1,6 @@
/* -*- c-basic-offset: 2 -*- */
-/* Copyright(C) 2009-2015 Brazil
+/*
+ Copyright(C) 2009-2016 Brazil
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -14,8 +15,8 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef GRN_DB_H
-#define GRN_DB_H
+
+#pragma once
#include "grn.h"
#include "grn_ctx.h"
@@ -37,9 +38,6 @@ extern "C" {
#define GRN_N_RESERVED_TYPES 256
-#define GRN_JSON_LOAD_OPEN_BRACKET 0x40000000
-#define GRN_JSON_LOAD_OPEN_BRACE 0x40000001
-
typedef struct _grn_db grn_db;
typedef struct _grn_proc grn_proc;
@@ -47,22 +45,88 @@ struct _grn_db {
grn_db_obj obj;
grn_obj *keys;
grn_ja *specs;
+ grn_hash *config;
grn_tiny_array values;
grn_critical_section lock;
};
+#define GRN_SERIALIZED_SPEC_INDEX_SPEC 0
+#define GRN_SERIALIZED_SPEC_INDEX_PATH 1
+#define GRN_SERIALIZED_SPEC_INDEX_SOURCE 2
+#define GRN_SERIALIZED_SPEC_INDEX_HOOK 3
+#define GRN_SERIALIZED_SPEC_INDEX_TOKEN_FILTERS 4
+#define GRN_SERIALIZED_SPEC_INDEX_EXPR 4
+
typedef struct {
grn_obj_header header;
grn_id range;
} grn_obj_spec;
+grn_bool grn_db_spec_unpack(grn_ctx *ctx,
+ grn_id id,
+ void *encoded_spec,
+ uint32_t encoded_spec_size,
+ grn_obj_spec **spec,
+ grn_obj *decoded_spec,
+ const char *error_message_tag);
+
+#define GRN_DB_SPEC_EACH_BEGIN(ctx, cursor, id, spec) do { \
+ grn_obj *db = grn_ctx_db((ctx)); \
+ grn_db *db_raw = (grn_db *)db; \
+ grn_obj decoded_spec; \
+ grn_io_win iw; \
+ grn_bool iw_need_unref = GRN_FALSE; \
+ GRN_OBJ_INIT(&decoded_spec, GRN_VECTOR, 0, GRN_DB_TEXT); \
+ GRN_TABLE_EACH_BEGIN((ctx), db, cursor, id) { \
+ void *encoded_spec; \
+ uint32_t encoded_spec_size; \
+ grn_bool success; \
+ grn_obj_spec *spec; \
+ \
+ if (iw_need_unref) { \
+ grn_ja_unref(ctx, &iw); \
+ iw_need_unref = GRN_FALSE; \
+ } \
+ encoded_spec = grn_ja_ref((ctx), \
+ db_raw->specs, \
+ id, \
+ &iw, \
+ &encoded_spec_size); \
+ if (!encoded_spec) { \
+ continue; \
+ } \
+ iw_need_unref = GRN_TRUE; \
+ \
+ GRN_BULK_REWIND(&decoded_spec); \
+ success = grn_db_spec_unpack(ctx, \
+ id, \
+ encoded_spec, \
+ encoded_spec_size, \
+ &spec, \
+ &decoded_spec, \
+ __FUNCTION__); \
+ if (!success) { \
+ continue; \
+ } \
+
+#define GRN_DB_SPEC_EACH_END(ctx, cursor) \
+ } GRN_TABLE_EACH_END(ctx, cursor); \
+ if (iw_need_unref) { \
+ grn_ja_unref(ctx, &iw); \
+ } \
+ GRN_OBJ_FIN((ctx), &decoded_spec); \
+} while(GRN_FALSE)
+
void grn_db_init_from_env(void);
GRN_API grn_rc grn_db_close(grn_ctx *ctx, grn_obj *db);
grn_obj *grn_db_keys(grn_obj *s);
-uint32_t grn_db_lastmod(grn_obj *s);
+void grn_db_generate_pathname(grn_ctx *ctx,
+ grn_obj *db,
+ grn_id id,
+ char *buffer);
grn_rc _grn_table_delete_by_id(grn_ctx *ctx, grn_obj *table, grn_id id,
grn_table_delete_optarg *optarg);
@@ -71,7 +135,11 @@ grn_id grn_table_get_v(grn_ctx *ctx, grn_obj *table, const void *key, int key_si
void **value);
grn_id grn_table_add_v(grn_ctx *ctx, grn_obj *table, const void *key, int key_size,
void **value, int *added);
-GRN_API grn_rc grn_table_get_info(grn_ctx *ctx, grn_obj *table, grn_obj_flags *flags,
+grn_id grn_table_add_by_key(grn_ctx *ctx,
+ grn_obj *table,
+ grn_obj *key,
+ int *added);
+GRN_API grn_rc grn_table_get_info(grn_ctx *ctx, grn_obj *table, grn_table_flags *flags,
grn_encoding *encoding, grn_obj **tokenizer,
grn_obj **normalizer,
grn_obj **token_filters);
@@ -81,6 +149,10 @@ grn_rc grn_table_search(grn_ctx *ctx, grn_obj *table,
const void *key, uint32_t key_size,
grn_operator mode, grn_obj *res, grn_operator op);
+grn_rc grn_table_fuzzy_search(grn_ctx *ctx, grn_obj *table,
+ const void *key, uint32_t key_size,
+ grn_fuzzy_search_optarg *args, grn_obj *res, grn_operator op);
+
grn_id grn_table_next(grn_ctx *ctx, grn_obj *table, grn_id id);
int grn_table_get_key2(grn_ctx *ctx, grn_obj *table, grn_id id, grn_obj *bulk);
@@ -111,6 +183,7 @@ struct _grn_type {
#define GRN_TABLE_SORT_GEO (0x02<<0)
#define GRN_OBJ_TMP_OBJECT 0x80000000
+#define GRN_OBJ_TMP_COLUMN 0x40000000
#define GRN_DB_OBJP(obj) \
(obj &&\
@@ -136,6 +209,12 @@ struct _grn_type {
(GRN_OBJ_VECTOR_COLUMNP(obj) &&\
(DB_OBJ(obj)->header.flags & GRN_OBJ_WITH_WEIGHT))
+struct _grn_hook {
+ grn_hook *next;
+ grn_proc *proc;
+ uint32_t hld_size;
+};
+
typedef struct _grn_proc_ctx grn_proc_ctx;
struct _grn_proc_ctx {
@@ -160,10 +239,13 @@ struct _grn_proc {
grn_proc_type type;
grn_proc_func *funcs[3];
- grn_selector_func *selector;
-
union {
struct {
+ grn_selector_func *selector;
+ grn_operator selector_op;
+ grn_bool is_stable;
+ } function;
+ struct {
grn_command_run_func *run;
} command;
struct {
@@ -174,6 +256,7 @@ struct _grn_proc {
struct {
grn_scorer_score_func *score;
} scorer;
+ grn_window_function_func *window_function;
} callbacks;
void *user_data;
@@ -201,7 +284,7 @@ GRN_API grn_obj *grn_proc_get_or_add_var(grn_ctx *ctx, grn_user_data *user_data,
const char *name, unsigned int name_size);
GRN_API grn_obj *grn_proc_alloc(grn_ctx *ctx, grn_user_data *user_data,
- grn_id domain, grn_obj_flags flags);
+ grn_id domain, unsigned char flags);
GRN_API grn_rc grn_proc_call(grn_ctx *ctx, grn_obj *proc,
int nargs, grn_obj *caller);
@@ -259,9 +342,6 @@ int grn_vector_delimit(grn_ctx *ctx, grn_obj *vector);
int grn_vector_size(grn_ctx *ctx, grn_obj *vector);
*/
-unsigned int grn_vector_pop_element(grn_ctx *ctx, grn_obj *vector,
- const char **str, unsigned int *weight, grn_id *domain);
-
grn_rc grn_vector_delimit(grn_ctx *ctx, grn_obj *v, unsigned int weight, grn_id domain);
grn_rc grn_vector_decode(grn_ctx *ctx, grn_obj *v, const char *data, uint32_t data_size);
@@ -293,6 +373,8 @@ typedef struct {
int32_t modify;
} grn_expr_code;
+#define GRN_EXPR_CONST_BLK_SIZE GRN_STACK_SIZE
+
struct _grn_expr {
grn_db_obj obj;
grn_obj name_buf;
@@ -302,7 +384,7 @@ struct _grn_expr {
uint16_t cacheable;
uint16_t taintable;
- grn_obj *consts;
+ grn_obj **const_blks;
grn_obj *values;
grn_expr_code *codes;
uint32_t nconsts;
@@ -318,15 +400,16 @@ struct _grn_expr {
};
grn_rc grn_expr_parser_close(grn_ctx *ctx);
-GRN_API grn_rc grn_obj_cast(grn_ctx *ctx, grn_obj *src, grn_obj *dest, grn_bool addp);
/**
* grn_table_open:
- * @name: 開こうとするtableの名前。NULLなら無名tableとなる。
- * @path: 開こうとするtableのファイルパス。
+ * @name: The table name to be opened. `NULL` means anonymous table.
+ * @path: The path of the table to be opened.
*
- * ctxが使用するdbの中でnameに対応付けて既存のtableを開く。
- * dbに登録されている名前付きの永続テーブルを開く場合はgrn_ctx_get()を使用するのが望ましい。
+ * Opens an existing table. The table is associated with @name in DB
+ * that is used by @ctx. grn_ctx_get() is better rather than this
+ * function when you want to open a permanent named table that is
+ * registered in DB.
**/
GRN_API grn_obj *grn_table_open(grn_ctx *ctx,
const char *name, unsigned int name_size,
@@ -334,13 +417,14 @@ GRN_API grn_obj *grn_table_open(grn_ctx *ctx,
/**
* grn_column_open:
- * @table: 対象table
- * @name: カラム名
- * @path: カラムを格納するファイルパス。
- * @type: カラム値の型。
+ * @table: The table for the opened column.
+ * @name: The column name to be opened.
+ * @path: The path of the column to be opened.
+ * @type: The type of the column value.
*
- * 既存の永続的なcolumnを、tableのnameに対応するcolumnとして開く
- * 永続dbに登録されている永続テーブルのカラムを開く場合はgrn_ctx_get()を使用するのが望ましい。
+ * Opens an existing permanent column. The column is associated with
+ * @name in @table. grn_ctx_get() is better rather than this function
+ * when you want to open a column of an permanent table in DB.
**/
grn_obj *grn_column_open(grn_ctx *ctx, grn_obj *table,
const char *name, unsigned int name_size,
@@ -348,10 +432,10 @@ grn_obj *grn_column_open(grn_ctx *ctx, grn_obj *table,
/**
* grn_obj_path_rename:
- * @old_path: 旧ファイルパス
- * @new_path: 新ファイルパス
+ * @old_path: The current file path.
+ * @new_path: The new file path.
*
- * old_pathに該当するオブジェクトのファイル名をnew_pathに変更する。
+ * It renames object's path that is stored in @old_path to @new_path.
**/
grn_rc grn_obj_path_rename(grn_ctx *ctx, const char *old_path, const char *new_path);
@@ -371,83 +455,17 @@ grn_rc grn_db_obj_init(grn_ctx *ctx, grn_obj *db, grn_id id, grn_db_obj *obj);
#define GRN_ACCESSORP(obj) \
((obj) && (((grn_obj *)(obj))->header.type == GRN_ACCESSOR))
-#define GRN_TRUEP(ctx, v, result) do {\
- switch (v->header.type) { \
- case GRN_BULK : \
- switch (v->header.domain) { \
- case GRN_DB_BOOL : \
- result = GRN_BOOL_VALUE(v); \
- break; \
- case GRN_DB_INT32 : \
- result = GRN_INT32_VALUE(v) != 0; \
- break; \
- case GRN_DB_UINT32 : \
- result = GRN_UINT32_VALUE(v) != 0; \
- break; \
- case GRN_DB_FLOAT : \
- { \
- double float_value; \
- float_value = GRN_FLOAT_VALUE(v); \
- result = (float_value < -DBL_EPSILON || \
- DBL_EPSILON < float_value); \
- } \
- break; \
- case GRN_DB_SHORT_TEXT : \
- case GRN_DB_TEXT : \
- case GRN_DB_LONG_TEXT : \
- result = GRN_TEXT_LEN(v) != 0; \
- break; \
- default : \
- result = GRN_FALSE; \
- break; \
- } \
- break; \
- case GRN_VECTOR : \
- result = GRN_TRUE; \
- break; \
- default : \
- result = GRN_FALSE; \
- break; \
- } \
-} while (0)
-
grn_id grn_obj_register(grn_ctx *ctx, grn_obj *db, const char *name, unsigned int name_size);
int grn_obj_is_persistent(grn_ctx *ctx, grn_obj *obj);
void grn_obj_spec_save(grn_ctx *ctx, grn_db_obj *obj);
grn_rc grn_obj_reinit_for(grn_ctx *ctx, grn_obj *obj, grn_obj *domain_obj);
-#define GRN_INT32_POP(obj,value) do {\
- if (GRN_BULK_VSIZE(obj) >= sizeof(int32_t)) {\
- GRN_BULK_INCR_LEN((obj), -(sizeof(int32_t)));\
- value = *(int32_t *)(GRN_BULK_CURR(obj));\
- } else {\
- value = 0;\
- }\
-} while (0)
-
-#define GRN_UINT32_POP(obj,value) do {\
- if (GRN_BULK_VSIZE(obj) >= sizeof(uint32_t)) {\
- GRN_BULK_INCR_LEN((obj), -(sizeof(uint32_t)));\
- value = *(uint32_t *)(GRN_BULK_CURR(obj));\
- } else {\
- value = 0;\
- }\
-} while (0)
-
void grn_expr_pack(grn_ctx *ctx, grn_obj *buf, grn_obj *expr);
GRN_API grn_rc grn_expr_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *expr);
grn_hash *grn_expr_get_vars(grn_ctx *ctx, grn_obj *expr, unsigned int *nvars);
grn_obj *grn_expr_open(grn_ctx *ctx, grn_obj_spec *spec, const uint8_t *p, const uint8_t *pe);
-GRN_API void grn_load_(grn_ctx *ctx, grn_content_type input_type,
- const char *table, unsigned int table_len,
- const char *columns, unsigned int columns_len,
- const char *values, unsigned int values_len,
- const char *ifexists, unsigned int ifexists_len,
- const char *each, unsigned int each_len,
- uint32_t emit_level);
-
GRN_API grn_rc grn_table_group_with_range_gap(grn_ctx *ctx, grn_obj *table,
grn_table_sort_key *group_key,
grn_obj *result_set,
@@ -458,12 +476,18 @@ GRN_API grn_rc grn_column_filter(grn_ctx *ctx, grn_obj *column,
grn_obj *value, grn_obj *result_set,
grn_operator set_op);
-grn_rc grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep,
- grn_obj *base_res, grn_obj **res,
- grn_search_optarg *optarg);
+typedef struct {
+ grn_id target;
+ unsigned int section;
+} grn_obj_default_set_value_hook_data;
+
+grn_obj *grn_obj_default_set_value_hook(grn_ctx *ctx,
+ int nargs,
+ grn_obj **args,
+ grn_user_data *user_data);
+
+grn_rc grn_pvector_fin(grn_ctx *ctx, grn_obj *obj);
#ifdef __cplusplus
}
#endif
-
-#endif /* GRN_DB_H */