mirror of https://gitee.com/bigwinds/arangodb
added regex operators ~= and !~
This commit is contained in:
parent
80d3164622
commit
274cfeb5c2
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +1,8 @@
|
||||||
/* A Bison parser, made by GNU Bison 3.0.2. */
|
/* A Bison parser, made by GNU Bison 3.0.4. */
|
||||||
|
|
||||||
/* Bison interface for Yacc-like parsers in C
|
/* Bison interface for Yacc-like parsers in C
|
||||||
|
|
||||||
Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
|
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -79,46 +79,48 @@ extern int Aqldebug;
|
||||||
T_AND = 288,
|
T_AND = 288,
|
||||||
T_OR = 289,
|
T_OR = 289,
|
||||||
T_NIN = 290,
|
T_NIN = 290,
|
||||||
T_EQ = 291,
|
T_REGEX_MATCH = 291,
|
||||||
T_NE = 292,
|
T_REGEX_NON_MATCH = 292,
|
||||||
T_LT = 293,
|
T_EQ = 293,
|
||||||
T_GT = 294,
|
T_NE = 294,
|
||||||
T_LE = 295,
|
T_LT = 295,
|
||||||
T_GE = 296,
|
T_GT = 296,
|
||||||
T_LIKE = 297,
|
T_LE = 297,
|
||||||
T_PLUS = 298,
|
T_GE = 298,
|
||||||
T_MINUS = 299,
|
T_LIKE = 299,
|
||||||
T_TIMES = 300,
|
T_PLUS = 300,
|
||||||
T_DIV = 301,
|
T_MINUS = 301,
|
||||||
T_MOD = 302,
|
T_TIMES = 302,
|
||||||
T_QUESTION = 303,
|
T_DIV = 303,
|
||||||
T_COLON = 304,
|
T_MOD = 304,
|
||||||
T_SCOPE = 305,
|
T_QUESTION = 305,
|
||||||
T_RANGE = 306,
|
T_COLON = 306,
|
||||||
T_COMMA = 307,
|
T_SCOPE = 307,
|
||||||
T_OPEN = 308,
|
T_RANGE = 308,
|
||||||
T_CLOSE = 309,
|
T_COMMA = 309,
|
||||||
T_OBJECT_OPEN = 310,
|
T_OPEN = 310,
|
||||||
T_OBJECT_CLOSE = 311,
|
T_CLOSE = 311,
|
||||||
T_ARRAY_OPEN = 312,
|
T_OBJECT_OPEN = 312,
|
||||||
T_ARRAY_CLOSE = 313,
|
T_OBJECT_CLOSE = 313,
|
||||||
T_OUTBOUND = 314,
|
T_ARRAY_OPEN = 314,
|
||||||
T_INBOUND = 315,
|
T_ARRAY_CLOSE = 315,
|
||||||
T_ANY = 316,
|
T_OUTBOUND = 316,
|
||||||
T_ALL = 317,
|
T_INBOUND = 317,
|
||||||
T_NONE = 318,
|
T_ANY = 318,
|
||||||
UMINUS = 319,
|
T_ALL = 319,
|
||||||
UPLUS = 320,
|
T_NONE = 320,
|
||||||
FUNCCALL = 321,
|
UMINUS = 321,
|
||||||
REFERENCE = 322,
|
UPLUS = 322,
|
||||||
INDEXED = 323,
|
FUNCCALL = 323,
|
||||||
EXPANSION = 324
|
REFERENCE = 324,
|
||||||
|
INDEXED = 325,
|
||||||
|
EXPANSION = 326
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Value type. */
|
/* Value type. */
|
||||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||||
typedef union YYSTYPE YYSTYPE;
|
|
||||||
union YYSTYPE
|
union YYSTYPE
|
||||||
{
|
{
|
||||||
#line 19 "Aql/grammar.y" /* yacc.c:1909 */
|
#line 19 "Aql/grammar.y" /* yacc.c:1909 */
|
||||||
|
@ -131,8 +133,10 @@ union YYSTYPE
|
||||||
bool boolval;
|
bool boolval;
|
||||||
int64_t intval;
|
int64_t intval;
|
||||||
|
|
||||||
#line 135 "Aql/grammar.hpp" /* yacc.c:1909 */
|
#line 137 "Aql/grammar.hpp" /* yacc.c:1909 */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef union YYSTYPE YYSTYPE;
|
||||||
# define YYSTYPE_IS_TRIVIAL 1
|
# define YYSTYPE_IS_TRIVIAL 1
|
||||||
# define YYSTYPE_IS_DECLARED 1
|
# define YYSTYPE_IS_DECLARED 1
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -238,6 +238,9 @@ static AstNode const* GetIntoExpression(AstNode const* node) {
|
||||||
%token T_OR "or operator"
|
%token T_OR "or operator"
|
||||||
%token T_NIN "not in operator"
|
%token T_NIN "not in operator"
|
||||||
|
|
||||||
|
%token T_REGEX_MATCH "~= operator"
|
||||||
|
%token T_REGEX_NON_MATCH "~! operator"
|
||||||
|
|
||||||
%token T_EQ "== operator"
|
%token T_EQ "== operator"
|
||||||
%token T_NE "!= operator"
|
%token T_NE "!= operator"
|
||||||
%token T_LT "< operator"
|
%token T_LT "< operator"
|
||||||
|
@ -285,7 +288,7 @@ static AstNode const* GetIntoExpression(AstNode const* node) {
|
||||||
%left T_OR
|
%left T_OR
|
||||||
%left T_AND
|
%left T_AND
|
||||||
%nonassoc T_OUTBOUND T_INBOUND T_ANY T_ALL T_NONE
|
%nonassoc T_OUTBOUND T_INBOUND T_ANY T_ALL T_NONE
|
||||||
%left T_EQ T_NE T_LIKE
|
%left T_EQ T_NE T_LIKE T_REGEX_MATCH T_REGEX_NON_MATCH
|
||||||
%left T_IN T_NIN
|
%left T_IN T_NIN
|
||||||
%left T_LT T_GT T_LE T_GE
|
%left T_LT T_GT T_LE T_GE
|
||||||
%left T_RANGE
|
%left T_RANGE
|
||||||
|
@ -1147,6 +1150,19 @@ operator_binary:
|
||||||
arguments->addMember($3);
|
arguments->addMember($3);
|
||||||
$$ = parser->ast()->createNodeFunctionCall("LIKE", arguments);
|
$$ = parser->ast()->createNodeFunctionCall("LIKE", arguments);
|
||||||
}
|
}
|
||||||
|
| expression T_REGEX_MATCH expression {
|
||||||
|
AstNode* arguments = parser->ast()->createNodeArray(2);
|
||||||
|
arguments->addMember($1);
|
||||||
|
arguments->addMember($3);
|
||||||
|
$$ = parser->ast()->createNodeFunctionCall("REGEX_TEST", arguments);
|
||||||
|
}
|
||||||
|
| expression T_REGEX_NON_MATCH expression {
|
||||||
|
AstNode* arguments = parser->ast()->createNodeArray(2);
|
||||||
|
arguments->addMember($1);
|
||||||
|
arguments->addMember($3);
|
||||||
|
AstNode* node = parser->ast()->createNodeFunctionCall("REGEX_TEST", arguments);
|
||||||
|
$$ = parser->ast()->createNodeUnaryOperator(NODE_TYPE_OPERATOR_UNARY_NOT, node);
|
||||||
|
}
|
||||||
| expression quantifier T_EQ expression {
|
| expression quantifier T_EQ expression {
|
||||||
$$ = parser->ast()->createNodeBinaryArrayOperator(NODE_TYPE_OPERATOR_BINARY_ARRAY_EQ, $1, $4, $2);
|
$$ = parser->ast()->createNodeBinaryArrayOperator(NODE_TYPE_OPERATOR_BINARY_ARRAY_EQ, $1, $4, $2);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -199,6 +199,14 @@ namespace arangodb {
|
||||||
* operators
|
* operators
|
||||||
* --------------------------------------------------------------------------- */
|
* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
"=~" {
|
||||||
|
return T_REGEX_MATCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
"!~" {
|
||||||
|
return T_REGEX_NON_MATCH;
|
||||||
|
}
|
||||||
|
|
||||||
"==" {
|
"==" {
|
||||||
return T_EQ;
|
return T_EQ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,8 +225,13 @@ function ahuacatlStringFunctionsTestSuite () {
|
||||||
|
|
||||||
query = "RETURN NOOPT(V8(REGEX_TEST(@what, @re)))";
|
query = "RETURN NOOPT(V8(REGEX_TEST(@what, @re)))";
|
||||||
assertEqual(v[2], getQueryResults(query, { what: v[0], re: v[1] })[0], v);
|
assertEqual(v[2], getQueryResults(query, { what: v[0], re: v[1] })[0], v);
|
||||||
|
|
||||||
|
query = "RETURN @what =~ @re";
|
||||||
|
assertEqual(v[2], getQueryResults(query, { what: v[0], re: v[1] })[0], v);
|
||||||
|
|
||||||
|
query = "RETURN @what !~ @re";
|
||||||
|
assertEqual(!v[2], getQueryResults(query, { what: v[0], re: v[1] })[0], v);
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
/*jshint globalstrict:false, strict:false, maxlen:5000 */
|
||||||
|
/*global assertEqual, AQL_EXECUTE */
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief tests for query language, functions
|
||||||
|
///
|
||||||
|
/// @file
|
||||||
|
///
|
||||||
|
/// DISCLAIMER
|
||||||
|
///
|
||||||
|
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
|
||||||
|
///
|
||||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
/// you may not use this file except in compliance with the License.
|
||||||
|
/// You may obtain a copy of the License at
|
||||||
|
///
|
||||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
///
|
||||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
/// See the License for the specific language governing permissions and
|
||||||
|
/// limitations under the License.
|
||||||
|
///
|
||||||
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||||
|
///
|
||||||
|
/// @author Jan Steemann
|
||||||
|
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
var internal = require("internal");
|
||||||
|
var jsunity = require("jsunity");
|
||||||
|
var db = internal.db;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test suite
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function ahuacatlRegexTestSuite () {
|
||||||
|
var c;
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief set up
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
setUp : function () {
|
||||||
|
db._drop("UnitTestsAhuacatlRegex");
|
||||||
|
c = db._create("UnitTestsAhuacatlRegex");
|
||||||
|
|
||||||
|
for (var i = 0; i < 1000; ++i) {
|
||||||
|
c.insert({ _key: "test" + i });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief tear down
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
tearDown : function () {
|
||||||
|
db._drop("UnitTestsAhuacatlRegex");
|
||||||
|
c = null;
|
||||||
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test regex matching
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
testRegexMatch : function () {
|
||||||
|
var values = [
|
||||||
|
[ '^test$', 0 ],
|
||||||
|
[ '^test\\d+$', 1000 ],
|
||||||
|
[ '^test1$', 1 ],
|
||||||
|
[ '^test1', 111 ],
|
||||||
|
[ '^test1*', 1000 ],
|
||||||
|
[ '^test1+', 111 ],
|
||||||
|
[ '^test1..$', 100 ],
|
||||||
|
[ '^test1.$', 10 ],
|
||||||
|
[ '^test11.', 10 ],
|
||||||
|
[ 'test', 1000 ],
|
||||||
|
[ 'test123', 1 ],
|
||||||
|
[ 'test12', 11 ],
|
||||||
|
[ '111', 1 ],
|
||||||
|
[ '111$', 1 ],
|
||||||
|
[ '11$', 10 ],
|
||||||
|
[ '1$', 100 ]
|
||||||
|
];
|
||||||
|
|
||||||
|
values.forEach(function(v) {
|
||||||
|
// test match
|
||||||
|
var query = "FOR doc IN @@collection FILTER doc._key =~ @re RETURN doc._key";
|
||||||
|
var result = AQL_EXECUTE(query, { "@collection": c.name(), re: v[0] }).json;
|
||||||
|
assertEqual(v[1], result.length);
|
||||||
|
|
||||||
|
// test non-match
|
||||||
|
query = "FOR doc IN @@collection FILTER doc._key !~ @re RETURN doc._key";
|
||||||
|
result = AQL_EXECUTE(query, { "@collection": c.name(), re: v[0] }).json;
|
||||||
|
assertEqual(1000 - v[1], result.length);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief executes the test suite
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
jsunity.run(ahuacatlRegexTestSuite);
|
||||||
|
|
||||||
|
return jsunity.done();
|
||||||
|
|
Loading…
Reference in New Issue