8000 backport of https://github.com/arangodb/arangodb/pull/14513 · arangodb/arangodb@ba3cad5 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba3cad5

Browse files
committed
backport of #14513
1 parent c87039d commit ba3cad5

File tree

6 files changed

+45
-61
lines changed

6 files changed

+45
-61
lines changed

CHANGELOG

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
v3.8.1 (XXXX-XX-XX)
2+
-------------------
3+
4+
* Fixed BTS-408: treat positive or negative signed numbers as constants
5+
immediately during AQL query parsing.
6+
Previously, a value of `-1` was parsed initially as `unary minus(value(1))`,
7+
which was not treated in the same way as a constant value `value(-1)`.
8+
The value was later optimized to just `value(-1)`, but this only happened
9+
during constant-folding after parsing. Any operations that referred to
10+
the unfolded values during parsing thus did not treat such values as
11+
constants.
12+
13+
114
v3.8.0 (XXXX-XX-XX)
215
-------------------
316

arangod/Aql/Ast.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ class Ast {
485485
/// isValid is set to false, then the returned value is not to be trued and the
486486
/// the result is equivalent to an AQL `null` value
487487
static AstNode const* resolveConstAttributeAccess(AstNode const*, bool& isValid);
488+
489+
/// @brief optimizes the unary operators + and -
490+
/// the unary plus will be converted into a simple value node if the operand
491+
/// of the operation is a constant number
492+
AstNode* optimizeUnaryOperatorArithmetic(AstNode*);
488493

489494
private:
490495
/// @brief make condition from example
@@ -496,11 +501,6 @@ class Ast {
496501
/// @brief create a number node for an arithmetic result, double
497502
AstNode* createArithmeticResultNode(double);
498503

499-
/// @brief optimizes the unary operators + and -
500-
/// the unary plus will be converted into a simple value node if the operand
501-
/// of the operation is a constant number
502-
AstNode* optimizeUnaryOperatorArithmetic(AstNode*);
503-
504504
/// @brief optimizes the unary operator NOT with a non-constant expression
505505
AstNode* optimizeNotExpression(AstNode*);
506506

arangod/Aql/grammar.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,10 +1433,10 @@ function_call:
14331433

14341434
operator_unary:
14351435
T_PLUS expression %prec UPLUS {
1436-
$$ = parser->ast()->createNodeUnaryOperator(NODE_TYPE_OPERATOR_UNARY_PLUS, $2);
1436+
$$ = parser->ast()->optimizeUnaryOperatorArithmetic(parser->ast()->createNodeUnaryOperator(NODE_TYPE_OPERATOR_UNARY_PLUS, $2));
14371437
}
14381438
| T_MINUS expression %prec UMINUS {
1439-
$$ = parser->ast()->createNodeUnaryOperator(NODE_TYPE_OPERATOR_UNARY_MINUS, $2);
1439+
$$ = parser->ast()->optimizeUnaryOperatorArithmetic(parser->ast()->createNodeUnaryOperator(NODE_TYPE_OPERATOR_UNARY_MINUS, $2));
14401440
}
14411441
| T_NOT expression %prec UNEGATION {
14421442
$$ = parser->ast()->createNodeUnaryOperator(NODE_TYPE_OPERATOR_UNARY_NOT, $2);

arangod/IResearch/IResearchFilterFactory.cpp

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -891,44 +891,6 @@ Result byRange(irs::boolean_filter* filter,
891891
return byRange<Min>(filter, name, value, incl, ctx, filterCtx);
892892
}
893893

894-
Result fromExpression(irs::boolean_filter* filter, QueryContext const& ctx,
895-
FilterContext const& filterCtx,
896-
std::shared_ptr<aql::AstNode>&& node) {
897-
if (!filter) {
898-
return {};
899-
}
900-
901-
// non-deterministic condition or self-referenced variable
902-
if (!node->isDeterministic() || arangodb::iresearch::findReference(*node, *ctx.ref)) {
903-
// not supported by IResearch, but could be handled by ArangoDB
904-
appendExpression(*filter, std::move(node), ctx, filterCtx);
905-
return {};
906-
}
907-
908-
bool result;
909-
910-
if (node->isConstant()) {
911-
result = node->isTrue();
912-
} else { // deterministic expression
913-
ScopedAqlValue value(*node);
914-
915-
if (!value.execute(ctx)) {
916-
// can't execute expression
917-
return {TRI_ERROR_BAD_PARAMETER, "can not execute expression"};
918-
}
919-
920-
result = value.getBoolean();
921-
}
922-
923-
if (result) {
924-
filter->add<irs::all>().boost(filterCtx.boost);
925-
} else {
926-
filter->add<irs::empty>();
927-
}
928-
929-
return {};
930-
}
931-
932894
Result fromExpression(irs::boolean_filter* filter, QueryContext const& ctx,
933895
FilterContext const& filterCtx, aql::AstNode const& node) {
934896
if (!filter) {
@@ -966,6 +928,15 @@ Result fromExpression(irs::boolean_filter* filter, QueryContext const& ctx,
966928
return {};
967929
}
968930

931+
Result fromExpression(irs::boolean_filter* filter, QueryContext const& ctx,
932+
FilterContext const& filterCtx,
933+
std::shared_ptr<aql::AstNode>&& node) {
934+
// redirect to existing function for AstNode const& nodes to
935+
// avoid coding the logic twice
936+
return fromExpression(filter, ctx, filterCtx, *node);
937+
}
938+
939+
969940
// GEO_IN_RANGE(attribute, shape, lower, upper[, includeLower = true, includeUpper = true])
970941
Result fromFuncGeoInRange(
971942
char const* funcName,

tests/IResearch/IResearchFilterFunction-test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6256,7 +6256,7 @@ TEST_F(IResearchFilterFunctionTest, levenshteinMatch) {
62566256
assertFilterFail(
62576257
vocbase(),
62586258
"FOR d IN myView FILTER LEVENSHTEIN_MATCH(d.foo, 'foo', 5, false) RETURN d");
6259-
assertFilterExecutionFail(
6259+
assertFilterFail(
62606260
vocbase(),
62616261
"FOR d IN myView FILTER LEVENSHTEIN_MATCH(d.foo, 'foo', -1, false) RETURN d",
62626262
&ExpressionContextMock::EMPTY);

tests/js/server/aql/aql-parse.js

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0