-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jmespath issue with reusing compiled expressions #317
Comments
updated with more clear example & way to reproduce |
interesting it seems like when the jsoncons::jmespath::detail::jmespath_evaluator<json, const json &> evaluator{}; goes out of scope the constructed expression becomes invalid try with std::string expr = "sum(people[].age)";
std::error_code ec;
std::unique_ptr<jmespath::jmespath_expression<json>> expr3 = nullptr;
{
jsoncons::jmespath::detail::jmespath_evaluator<json, const json &>
evaluator{};
expr3 = std::make_unique<jmespath::jmespath_expression<json>>(
evaluator.compile(expr.data(), expr.size(), ec));
}
json doc = json::parse(jtext);
json result = expr3->evaluate(doc);
std::cout << pretty_print(result) << "\n\n"; remove |
indeed I just created a struct to hold number of different expression to evaluate and that fixed the problem struct FieldConfig {
using Expression = jsoncons::jmespath::jmespath_expression<jsoncons::json>;
using Evaluator =
jsoncons::jmespath::detail::jmespath_evaluator<jsoncons::json,
const jsoncons::json &>;
const std::string name;
const std::string expression_str;
Evaluator evaluator;
Expression expression;
std::error_code ec;
}
std::vector<std::unique_ptr<FieldConfig>> configs_;
} it looks like as long as |
just trying that branch :) |
as to my last comment -> unfortunately my testing suite just finished and found a regression of functionality if I use the evaluator in FieldConfig. It seems like it's not a valid proposal. I just tried the commit #281541d and unfortunately it fails
I tried to evaluate 3 expression on single json object [
{"name" : "field_1", "expression" : "group.value"},
{"name" : "field_2", "expression" : "array[0].value"},
{"name" : "field_3", "expression" : "nullable.value"}
] and the object tested against {
"group": {
"value": 1
},
"array": [
{"value": 2}
]
} |
Work in progress :-) Thanks for reporting. I think the original issue was about memory ownership for function objects, that they were being owned by the original Evaluator rather than being moved into the Can you provide a complete example for a failing instance? |
I tried
and that seems to be passing in all test configurations on branch jmespath_317. I need a case that fails. |
This comment has been minimized.
This comment has been minimized.
That assertion ( |
Yes that last exception on was an error on my side. I just tested your branch and it all seems now correct. Thanks a lot for very quick response! |
The changes have been uploaded to master, once all tests have passed, we'll put out a patched release 0.163.2. |
First to all thank you providing an incredible library!
We use
JMESPath
implementation quite extensively but recently we had a big higher throughput requirements which forced use to reuse compiled expression. The usual workaround for this bug (which has been around for a while) was to compile expression every time before usage.jsoncons::jmespath::search
takes around 3x longer thanevaluate
on expressionDescribe the bug
I did a bit more digging, please have a look at the snippet
It will result in exception
Function called with wrong number of arguments
or just outrightSIGSEGV
but this problem will never occur when using
jsoncons::jmespath::search
. This seem not to happen with every expression. We seem to have issues with functions likemax
orsum
i.emax([].my_object.sub_field)
But now if we re-arrange to first
::parse
and then::compile
everything is OK and I get result75.0
It looks to me like
::parse
breaks a global state thatcompile
introducesWhat compiler, architecture, and operating system?
What jsoncons library version?
release v0.162.2, however this problem has been reoccurring for all previous versions
The text was updated successfully, but these errors were encountered: