mongory 0.9.1-aarch64-linux → 2.0.1-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +115 -420
- data/SUBMODULE_INTEGRATION.md +7 -20
- data/docs/clang_bridge.md +28 -63
- data/docs/migration.md +17 -0
- data/docs/performance.md +14 -51
- data/examples/benchmark.rb +10 -26
- data/ext/mongory_ext/extconf.rb +1 -1
- data/ext/mongory_ext/mongory-core/include/mongory-core/adapters/json.h +62 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +31 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/error.h +3 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h +20 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h +31 -4
- data/ext/mongory_ext/mongory-core/src/foundations/array.c +48 -6
- data/ext/mongory_ext/mongory-core/src/foundations/config.c +30 -2
- data/ext/mongory_ext/mongory-core/src/foundations/error.c +10 -0
- data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +78 -19
- data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +73 -19
- data/ext/mongory_ext/mongory-core/src/foundations/table.c +8 -3
- data/ext/mongory_ext/mongory-core/src/foundations/utils.c +44 -55
- data/ext/mongory_ext/mongory-core/src/foundations/utils.h +7 -0
- data/ext/mongory_ext/mongory-core/src/foundations/value.c +3 -0
- data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +68 -0
- data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +14 -0
- data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +9 -4
- data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +132 -29
- data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +1 -1
- data/ext/mongory_ext/mongory-core/src/matchers/{existance_matcher.c → existence_matcher.c} +10 -12
- data/ext/mongory_ext/mongory-core/src/matchers/{existance_matcher.h → existence_matcher.h} +4 -4
- data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +18 -6
- data/ext/mongory_ext/mongory-core/src/matchers/{array_record_matcher.c → implicit_array_matcher.c} +57 -38
- data/ext/mongory_ext/mongory-core/src/matchers/{array_record_matcher.h → implicit_array_matcher.h} +5 -5
- data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c +8 -10
- data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +337 -96
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c +59 -21
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h +7 -1
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c +4 -4
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h +1 -1
- data/ext/mongory_ext/mongory-core/src/matchers/{literal_matcher.c → value_matcher.c} +104 -60
- data/ext/mongory_ext/mongory-core/src/matchers/{literal_matcher.h → value_matcher.h} +13 -13
- data/ext/mongory_ext/mongory_ext.c +2 -2
- data/ext/mongory_ext/mongory_ext_internal.h +2 -3
- data/ext/mongory_ext/{rb_mongory_cmatcher.c → rb_mongory_matcher.c} +145 -91
- data/ext/mongory_ext/rb_mongory_value.c +67 -0
- data/lib/core/2.6/mongory_ext.so +0 -0
- data/lib/core/2.7/mongory_ext.so +0 -0
- data/lib/core/3.0/mongory_ext.so +0 -0
- data/lib/core/3.1/mongory_ext.so +0 -0
- data/lib/core/3.2/mongory_ext.so +0 -0
- data/lib/core/3.3/mongory_ext.so +0 -0
- data/lib/core/3.4/mongory_ext.so +0 -0
- data/lib/core/4.0/mongory_ext.so +0 -0
- data/lib/generators/mongory/install/templates/initializer.rb.erb +0 -5
- data/lib/generators/mongory/matcher/templates/matcher.rb.erb +4 -15
- data/lib/mongory/converters/condition_converter.rb +1 -1
- data/lib/mongory/converters/converted.rb +28 -6
- data/lib/mongory/converters/key_converter.rb +2 -0
- data/lib/mongory/matcher.rb +50 -0
- data/lib/mongory/matchers/abstract_matcher.rb +18 -192
- data/lib/mongory/matchers.rb +68 -84
- data/lib/mongory/query_builder.rb +29 -42
- data/lib/mongory/utils/context.rb +10 -15
- data/lib/mongory/utils/tree_renderer.rb +98 -0
- data/lib/mongory/utils.rb +2 -67
- data/lib/mongory/version.rb +1 -1
- data/lib/mongory.rb +9 -59
- data/script/bench.rb +54 -0
- data/scripts/build_with_core.sh +0 -1
- metadata +13 -37
- data/lib/mongory/c_matcher.rb +0 -57
- data/lib/mongory/c_query_builder.rb +0 -44
- data/lib/mongory/matchers/abstract_multi_matcher.rb +0 -150
- data/lib/mongory/matchers/and_matcher.rb +0 -73
- data/lib/mongory/matchers/array_record_matcher.rb +0 -105
- data/lib/mongory/matchers/elem_match_matcher.rb +0 -57
- data/lib/mongory/matchers/eq_matcher.rb +0 -48
- data/lib/mongory/matchers/every_matcher.rb +0 -56
- data/lib/mongory/matchers/exists_matcher.rb +0 -53
- data/lib/mongory/matchers/field_matcher.rb +0 -160
- data/lib/mongory/matchers/gt_matcher.rb +0 -41
- data/lib/mongory/matchers/gte_matcher.rb +0 -41
- data/lib/mongory/matchers/hash_condition_matcher.rb +0 -80
- data/lib/mongory/matchers/in_matcher.rb +0 -84
- data/lib/mongory/matchers/literal_matcher.rb +0 -126
- data/lib/mongory/matchers/lt_matcher.rb +0 -41
- data/lib/mongory/matchers/lte_matcher.rb +0 -41
- data/lib/mongory/matchers/ne_matcher.rb +0 -39
- data/lib/mongory/matchers/nin_matcher.rb +0 -64
- data/lib/mongory/matchers/not_matcher.rb +0 -40
- data/lib/mongory/matchers/or_matcher.rb +0 -69
- data/lib/mongory/matchers/present_matcher.rb +0 -55
- data/lib/mongory/matchers/regex_matcher.rb +0 -109
- data/lib/mongory/matchers/size_matcher.rb +0 -54
- data/lib/mongory/query_matcher.rb +0 -93
- data/lib/mongory/rails.rb +0 -15
- data/lib/mongory/utils/debugger.rb +0 -125
- data/lib/mongory/utils/rails_patch.rb +0 -22
data/ext/mongory_ext/mongory-core/src/matchers/{array_record_matcher.c → implicit_array_matcher.c}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
2
|
+
* @file implicit_array_matcher.c
|
|
3
3
|
* @brief Implements a versatile matcher for arrays, handling various condition
|
|
4
4
|
* types. This is an internal implementation file for the matcher module.
|
|
5
5
|
*
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
* - Another array: Checks for whole-array equality.
|
|
12
12
|
* It often constructs a composite OR matcher to combine these possibilities.
|
|
13
13
|
*/
|
|
14
|
-
#include "
|
|
14
|
+
#include "implicit_array_matcher.h"
|
|
15
15
|
#include "../foundations/config_private.h"
|
|
16
16
|
#include "../foundations/utils.h" // For mongory_try_parse_int
|
|
17
17
|
#include "base_matcher.h" // For mongory_matcher_base_new
|
|
18
18
|
#include "compare_matcher.h" // For mongory_matcher_equal_new
|
|
19
19
|
#include "composite_matcher.h" // For mongory_matcher_composite_new, $elemMatch, table_cond_new, or_match
|
|
20
|
-
#include "
|
|
20
|
+
#include "value_matcher.h" // Potentially used by table_cond_new
|
|
21
21
|
#include "mongory-core/foundations/table.h"
|
|
22
22
|
#include "mongory-core/foundations/value.h"
|
|
23
23
|
#include <mongory-core.h> // General include
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
#include <string.h> // For strcmp
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* @struct
|
|
28
|
+
* @struct mongory_matcher_implicit_array_parse_table_context
|
|
29
29
|
* @brief Context used when parsing a table condition for array record matching.
|
|
30
30
|
*
|
|
31
31
|
* Helps separate parts of the condition table:
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
* - `elem_match_table`: For conditions that should apply to individual elements
|
|
35
35
|
* via an implicit or explicit $elemMatch.
|
|
36
36
|
*/
|
|
37
|
-
typedef struct
|
|
37
|
+
typedef struct mongory_matcher_implicit_array_parse_table_context {
|
|
38
38
|
mongory_table *parsed_table; /**< Stores operator or indexed conditions. */
|
|
39
39
|
mongory_table *elem_match_table; /**< Stores conditions for element matching. */
|
|
40
|
-
}
|
|
40
|
+
} mongory_matcher_implicit_array_parse_table_context;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* @brief Callback to parse a condition table for array matching.
|
|
@@ -56,7 +56,7 @@ typedef struct mongory_matcher_array_record_parse_table_context {
|
|
|
56
56
|
*
|
|
57
57
|
* @param key Current key in the condition table.
|
|
58
58
|
* @param value Current value for the key.
|
|
59
|
-
* @param acc Pointer to `
|
|
59
|
+
* @param acc Pointer to `mongory_matcher_implicit_array_parse_table_context`.
|
|
60
60
|
* @return Always true to continue.
|
|
61
61
|
*/
|
|
62
62
|
static inline bool mongory_is_elem_match_operator(char *key, mongory_value *value) {
|
|
@@ -71,8 +71,8 @@ static inline bool mongory_is_elem_match_operator(char *key, mongory_value *valu
|
|
|
71
71
|
return false;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
static inline bool
|
|
75
|
-
|
|
74
|
+
static inline bool mongory_matcher_implicit_array_parse_table_foreach(char *key, mongory_value *value, void *acc) {
|
|
75
|
+
mongory_matcher_implicit_array_parse_table_context *context = (mongory_matcher_implicit_array_parse_table_context *)acc;
|
|
76
76
|
mongory_table *parsed_table_for_operators = context->parsed_table;
|
|
77
77
|
mongory_table *table_for_elem_match_conditions = context->elem_match_table;
|
|
78
78
|
|
|
@@ -105,39 +105,37 @@ static inline bool mongory_matcher_array_record_parse_table_foreach(char *key, m
|
|
|
105
105
|
* @return A new `mongory_value` (table) containing the parsed and restructured
|
|
106
106
|
* condition. Returns NULL if input is not a table or on allocation failure.
|
|
107
107
|
*/
|
|
108
|
-
static inline mongory_value *
|
|
108
|
+
static inline mongory_value *mongory_matcher_implicit_array_parse_table(mongory_memory_pool *pool, mongory_value *condition) {
|
|
109
109
|
if (!pool) {
|
|
110
110
|
return NULL;
|
|
111
111
|
}
|
|
112
112
|
if (!condition || !condition->data.t) {
|
|
113
|
-
|
|
114
|
-
if (!error) {
|
|
115
|
-
pool->error = &MONGORY_ALLOC_ERROR;
|
|
116
|
-
return NULL;
|
|
117
|
-
}
|
|
118
|
-
error->type = MONGORY_ERROR_INVALID_TYPE;
|
|
119
|
-
error->message = "Expected condition to be a table, got a non-table value";
|
|
120
|
-
pool->error = error; // TODO: This is a hack, we should use a better error handling mechanism
|
|
113
|
+
mongory_error_set(pool, MONGORY_ERROR_INVALID_TYPE, "Expected condition to be a table, got a non-table value");
|
|
121
114
|
return NULL; // Invalid input
|
|
122
115
|
}
|
|
123
116
|
mongory_table *parsed_table = mongory_table_new(pool);
|
|
124
117
|
mongory_table *elem_match_sub_table = mongory_table_new(pool);
|
|
125
118
|
|
|
126
119
|
if (!parsed_table || !elem_match_sub_table) {
|
|
127
|
-
// Cleanup if one allocation succeeded but other failed? Pool should handle.
|
|
128
120
|
return NULL;
|
|
129
121
|
}
|
|
130
122
|
|
|
131
|
-
|
|
123
|
+
mongory_matcher_implicit_array_parse_table_context parse_ctx = {parsed_table, elem_match_sub_table};
|
|
132
124
|
mongory_table *original_condition_table = condition->data.t;
|
|
133
125
|
|
|
134
126
|
original_condition_table->each(original_condition_table, &parse_ctx,
|
|
135
|
-
|
|
127
|
+
mongory_matcher_implicit_array_parse_table_foreach);
|
|
128
|
+
if (pool->error != NULL) {
|
|
129
|
+
return NULL;
|
|
130
|
+
}
|
|
136
131
|
|
|
137
132
|
if (elem_match_sub_table->count > 0) {
|
|
138
133
|
// If there were conditions for element matching, add them as an $elemMatch
|
|
139
134
|
// clause to the main parsed_table.
|
|
140
|
-
|
|
135
|
+
mongory_value *wrapped_elem = mongory_value_wrap_t(pool, elem_match_sub_table);
|
|
136
|
+
if (!wrapped_elem || !parsed_table->set(parsed_table, "$elemMatch", wrapped_elem)) {
|
|
137
|
+
return NULL;
|
|
138
|
+
}
|
|
141
139
|
}
|
|
142
140
|
// If elem_match_sub_table is empty, it's not added. The original parsed_table
|
|
143
141
|
// (which might contain $size etc.) is returned.
|
|
@@ -145,7 +143,7 @@ static inline mongory_value *mongory_matcher_array_record_parse_table(mongory_me
|
|
|
145
143
|
}
|
|
146
144
|
|
|
147
145
|
/**
|
|
148
|
-
* @brief Main constructor for `
|
|
146
|
+
* @brief Main constructor for `mongory_matcher_implicit_array_new`.
|
|
149
147
|
*
|
|
150
148
|
* Constructs a two-part matcher (often combined with OR):
|
|
151
149
|
* - `left`: Handles element-wise conditions (like $elemMatch from various
|
|
@@ -159,27 +157,48 @@ static inline mongory_value *mongory_matcher_array_record_parse_table(mongory_me
|
|
|
159
157
|
*
|
|
160
158
|
* @param pool Memory pool.
|
|
161
159
|
* @param condition The condition to apply to arrays.
|
|
162
|
-
* @return The constructed
|
|
160
|
+
* @return The constructed implicit_array_matcher, or NULL on failure.
|
|
163
161
|
*/
|
|
164
|
-
mongory_matcher *
|
|
165
|
-
if (!condition)
|
|
162
|
+
mongory_matcher *mongory_matcher_implicit_array_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
|
|
163
|
+
if (!condition || !pool)
|
|
166
164
|
return NULL;
|
|
165
|
+
mongory_compile_budget saved = mongory_compile_budget_begin();
|
|
166
|
+
mongory_matcher *result = NULL;
|
|
167
167
|
switch (condition->type) {
|
|
168
|
-
case MONGORY_TYPE_TABLE:
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
extern_ctx
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
168
|
+
case MONGORY_TYPE_TABLE: {
|
|
169
|
+
mongory_value *parsed = mongory_matcher_implicit_array_parse_table(pool, condition);
|
|
170
|
+
if (parsed && pool->error == NULL) {
|
|
171
|
+
result = mongory_matcher_condition_new(pool, parsed, extern_ctx);
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
case MONGORY_TYPE_ARRAY: {
|
|
176
|
+
mongory_value *or_cond = MG_ARRAY_WRAP(pool, 2,
|
|
175
177
|
MG_TABLE_WRAP(pool, 1, "$eq", condition),
|
|
176
178
|
MG_TABLE_WRAP(pool, 1, "$elemMatch",
|
|
177
179
|
MG_TABLE_WRAP(pool, 1, "$eq", condition)
|
|
178
180
|
)
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
);
|
|
182
|
+
if (or_cond && pool->error == NULL) {
|
|
183
|
+
result = mongory_matcher_or_new(pool, or_cond, extern_ctx);
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case MONGORY_TYPE_REGEX: {
|
|
188
|
+
mongory_value *re_cond = MG_TABLE_WRAP(pool, 1, "$regex", condition);
|
|
189
|
+
if (re_cond && pool->error == NULL) {
|
|
190
|
+
result = mongory_matcher_elem_match_new(pool, re_cond, extern_ctx);
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
default: { // Literals (string, int, bool, etc.)
|
|
195
|
+
mongory_value *eq_cond = MG_TABLE_WRAP(pool, 1, "$eq", condition);
|
|
196
|
+
if (eq_cond && pool->error == NULL) {
|
|
197
|
+
result = mongory_matcher_elem_match_new(pool, eq_cond, extern_ctx);
|
|
198
|
+
}
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
184
201
|
}
|
|
202
|
+
mongory_compile_budget_end(saved);
|
|
203
|
+
return result;
|
|
185
204
|
}
|
data/ext/mongory_ext/mongory-core/src/matchers/{array_record_matcher.h → implicit_array_matcher.h}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#ifndef
|
|
2
|
-
#define
|
|
1
|
+
#ifndef MONGORY_MATCHER_IMPLICIT_ARRAY_H
|
|
2
|
+
#define MONGORY_MATCHER_IMPLICIT_ARRAY_H
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @file
|
|
5
|
+
* @file implicit_array_matcher.h
|
|
6
6
|
* @brief Defines the constructor for a matcher that handles complex conditions
|
|
7
7
|
* against arrays. This is an internal header for the matcher module.
|
|
8
8
|
*
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
* array or its elements.
|
|
43
43
|
* @return A new array record matcher, or NULL on failure.
|
|
44
44
|
*/
|
|
45
|
-
mongory_matcher *
|
|
45
|
+
mongory_matcher *mongory_matcher_implicit_array_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
|
|
46
46
|
|
|
47
|
-
#endif /*
|
|
47
|
+
#endif /* MONGORY_MATCHER_IMPLICIT_ARRAY_H */
|
|
@@ -74,11 +74,7 @@ static inline bool mongory_matcher_in_match(mongory_matcher *matcher, mongory_va
|
|
|
74
74
|
|
|
75
75
|
mongory_matcher *mongory_matcher_in_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
|
|
76
76
|
if (!mongory_matcher_validate_array_condition(condition)) {
|
|
77
|
-
|
|
78
|
-
if (pool->error) {
|
|
79
|
-
pool->error->type = MONGORY_ERROR_INVALID_ARGUMENT;
|
|
80
|
-
pool->error->message = "$in condition must be a valid array.";
|
|
81
|
-
}
|
|
77
|
+
mongory_error_set(pool, MONGORY_ERROR_INVALID_ARGUMENT, "$in condition must be a valid array.");
|
|
82
78
|
return NULL;
|
|
83
79
|
}
|
|
84
80
|
mongory_matcher *matcher = mongory_matcher_base_new(pool, condition, extern_ctx);
|
|
@@ -88,6 +84,9 @@ mongory_matcher *mongory_matcher_in_new(mongory_memory_pool *pool, mongory_value
|
|
|
88
84
|
matcher->match = mongory_matcher_in_match;
|
|
89
85
|
matcher->original_match = mongory_matcher_in_match;
|
|
90
86
|
matcher->name = mongory_string_cpy(pool, "In");
|
|
87
|
+
if (!matcher->name) {
|
|
88
|
+
return NULL;
|
|
89
|
+
}
|
|
91
90
|
matcher->priority = 1.0 + mongory_log((double)condition->data.a->count + 1.0, 1.5);
|
|
92
91
|
return matcher;
|
|
93
92
|
}
|
|
@@ -107,11 +106,7 @@ static inline bool mongory_matcher_not_in_match(mongory_matcher *matcher, mongor
|
|
|
107
106
|
|
|
108
107
|
mongory_matcher *mongory_matcher_not_in_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
|
|
109
108
|
if (!mongory_matcher_validate_array_condition(condition)) {
|
|
110
|
-
|
|
111
|
-
if (pool->error) {
|
|
112
|
-
pool->error->type = MONGORY_ERROR_INVALID_ARGUMENT;
|
|
113
|
-
pool->error->message = "$nin condition must be a valid array.";
|
|
114
|
-
}
|
|
109
|
+
mongory_error_set(pool, MONGORY_ERROR_INVALID_ARGUMENT, "$nin condition must be a valid array.");
|
|
115
110
|
return NULL;
|
|
116
111
|
}
|
|
117
112
|
mongory_matcher *matcher = mongory_matcher_base_new(pool, condition, extern_ctx);
|
|
@@ -121,6 +116,9 @@ mongory_matcher *mongory_matcher_not_in_new(mongory_memory_pool *pool, mongory_v
|
|
|
121
116
|
matcher->match = mongory_matcher_not_in_match;
|
|
122
117
|
matcher->original_match = mongory_matcher_not_in_match;
|
|
123
118
|
matcher->name = mongory_string_cpy(pool, "Nin");
|
|
119
|
+
if (!matcher->name) {
|
|
120
|
+
return NULL;
|
|
121
|
+
}
|
|
124
122
|
matcher->priority = 1.0 + mongory_log((double)condition->data.a->count + 1.0, 1.5);
|
|
125
123
|
return matcher;
|
|
126
124
|
}
|