Skip to content

Commit dd9c090

Browse files
committed
Merge tag 'wl12721'
2 parents 43b6b60 + dd14226 commit dd9c090

File tree

6 files changed

+166
-5
lines changed

6 files changed

+166
-5
lines changed

cdk/parser/expr_parser.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,7 @@ Expression* Expr_parser_base::parse_ilri(Processor *prc)
15691569
next.insert(Op::BETWEEN);
15701570
next.insert(Op::REGEXP);
15711571
next.insert(Op::SOUNDS_LIKE);
1572+
next.insert(Op::OVERLAPS);
15721573

15731574
const Token *t = consume_token(next);
15741575

@@ -1580,7 +1581,7 @@ Expression* Expr_parser_base::parse_ilri(Processor *prc)
15801581
if (!t)
15811582
{
15821583
if (neg)
1583-
parse_error("Expected IN, (R)LIKE, BETWEEN or REGEXP after NOT");
1584+
parse_error("Expected IN, (R)LIKE, BETWEEN, OVERLAPS or REGEXP after NOT");
15841585

15851586
// If prc is NULL return already stored expression.
15861587

@@ -1650,7 +1651,10 @@ Expression* Expr_parser_base::parse_ilri(Processor *prc)
16501651
if (neg)
16511652
op = Op::NOT_REGEXP;
16521653
break;
1653-
1654+
case Op::OVERLAPS:
1655+
if (neg)
1656+
op = Op::NOT_OVERLAPS;
1657+
break;
16541658
default: break;
16551659
}
16561660

@@ -1747,6 +1751,11 @@ Expression* Expr_parser_base::parse_ilri(Processor *prc)
17471751
parse(COMP, aprc->list_el());
17481752
break;
17491753

1754+
case Op::OVERLAPS:
1755+
case Op::NOT_OVERLAPS:
1756+
parse(COMP, aprc->list_el());
1757+
break;
1758+
17501759
case Op::BETWEEN:
17511760
case Op::NOT_BETWEEN:
17521761
parse(COMP, aprc->list_el());

cdk/parser/expr_parser.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ POP_SYS_WARNINGS_CDK
7171
X(RLIKE, "rlike") \
7272
X(INTERVAL, "interval") \
7373
X(REGEXP, "regexp") \
74+
X(OVERLAPS, "overlaps")\
7475
X(ESCAPE, "escape") \
7576
X(HEX, "hex") \
7677
X(BIN, "bin") \
@@ -176,7 +177,9 @@ POP_SYS_WARNINGS_CDK
176177
X(REGEXP, "regexp", {}, {Keyword::REGEXP}) \
177178
X(NOT_REGEXP, "not_regexp", {}, {}) \
178179
X(CAST, "cast", {}, {Keyword::CAST}) \
179-
X(SOUNDS_LIKE, "sounds like", {}, {Keyword::SOUNDS})
180+
X(SOUNDS_LIKE, "sounds like", {}, {Keyword::SOUNDS})\
181+
X(OVERLAPS, "overlaps", {}, {Keyword::OVERLAPS}) \
182+
X(NOT_OVERLAPS, "not_overlaps", {}, {}) \
180183

181184

182185

cdk/parser/tests/parser-t.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify
@@ -890,6 +890,7 @@ const Expr_Test exprs[] =
890890
{ parser::Parser_mode::DOCUMENT, "-2*3+4.1%5 >> 6 & 7 >= 8 and true or docName not in ('foo%', 'bar%')"},
891891
{ parser::Parser_mode::DOCUMENT, "-2*3+4.1%5 >> 6 & 7 >= 8 and true or docName not between 'foo%' AND 'bar%'"},
892892
{ parser::Parser_mode::DOCUMENT, "-2*3+4.1%5 >> 6 & 7 >= 8 and true or docName not regexp 'foo.*'"},
893+
{ parser::Parser_mode::DOCUMENT, "-2*3+4.1%5 >> 6 & 7 >= 8 and true or docName not overlaps [foo, bar]"},
893894
{ parser::Parser_mode::DOCUMENT, "-2*3+4.1%5 >> 6 & 7 >= 8 and true or Schema.Table.docName = null"},
894895
{ parser::Parser_mode::DOCUMENT, "not (name <= 'foo' or not bar)"},
895896
{ parser::Parser_mode::DOCUMENT, "colName.Xpto[1].a[*].* + .1e-2"},
@@ -911,6 +912,9 @@ const Expr_Test exprs[] =
911912
{ parser::Parser_mode::TABLE , "CHARSET(CHAR(0x65))"},
912913
{ parser::Parser_mode::TABLE , "'abc' NOT LIKE 'ABC1'"},
913914
{ parser::Parser_mode::TABLE , "'a' REGEXP '^[a-d]'"},
915+
{ parser::Parser_mode::TABLE , "'a' OVERLAPS [a,d]"},
916+
{ parser::Parser_mode::TABLE , "`overlaps` oVeRlApS [foo, bar]"},
917+
{ parser::Parser_mode::TABLE , R"("overlaps" not OvErLaPs [foo, bar])"},
914918
{ parser::Parser_mode::TABLE , "'a' NOT RLIKE '^[a-d]'"},
915919
{ parser::Parser_mode::TABLE , "POSITION('bar' IN 'foobarbar')"},
916920
{ parser::Parser_mode::TABLE , "TRIM('barxxyz')"},
@@ -923,6 +927,9 @@ const Expr_Test exprs[] =
923927
{ parser::Parser_mode::DOCUMENT, "$.field1 IN $.field2"},
924928
{ parser::Parser_mode::DOCUMENT, "$.field1 NOT IN $.field2"},
925929
{ parser::Parser_mode::DOCUMENT, "a IN (b)"},
930+
//Commented untill WL12774 fixes it:
931+
// { parser::Parser_mode::DOCUMENT, "`overlaps` oVeRlApS [foo, bar]"},
932+
// { parser::Parser_mode::DOCUMENT, "`like` NOT LIKE :like"},
926933
{ parser::Parser_mode::TABLE , "cast(column as json) IN doc->'$.field.array'"},
927934
{ parser::Parser_mode::TABLE , "cast(column as json) NOT IN doc->'$.field.array'"},
928935
{ parser::Parser_mode::TABLE , "column->'$.field' IN [1,2,3]"},
@@ -1131,7 +1138,12 @@ const Expr_Test negative_exprs[] =
11311138
{ parser::Parser_mode::TABLE, "$.a**[0]" },
11321139
{ parser::Parser_mode::TABLE, "$.a**[*]" },
11331140
{ parser::Parser_mode::TABLE, "$.a**.bar" },
1134-
{ parser::Parser_mode::TABLE, "$.a**.foo" }
1141+
{ parser::Parser_mode::TABLE, "$.a**.foo" },
1142+
1143+
//Operators
1144+
{ parser::Parser_mode::DOCUMENT, "overlaps [a,b,c]" },
1145+
{ parser::Parser_mode::DOCUMENT, "not overlaps [a,b,c]" },
1146+
{ parser::Parser_mode::DOCUMENT, "[a,b,c] not overlaps" },
11351147
};
11361148

11371149

common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ add_library(common STATIC
3434
)
3535

3636
target_link_libraries(common cdk uuid_gen)
37+
38+
add_subdirectory(tests)

common/tests/CMakeLists.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License, version 2.0, as
5+
# published by the Free Software Foundation.
6+
#
7+
# This program is also distributed with certain software (including
8+
# but not limited to OpenSSL) that is licensed under separate terms,
9+
# as designated in a particular file or component or in included license
10+
# documentation. The authors of MySQL hereby grant you an
11+
# additional permission to link the program and your derivative works
12+
# with the separately licensed software that they have included with
13+
# MySQL.
14+
#
15+
# Without limiting anything contained in the foregoing, this file,
16+
# which is part of MySQL Connector/C++, is also subject to the
17+
# Universal FOSS Exception, version 1.0, a copy of which can be found at
18+
# http://oss.oracle.com/licenses/universal-foss-exception.
19+
#
20+
# This program is distributed in the hope that it will be useful, but
21+
# WITHOUT ANY WARRANTY; without even the implied warranty of
22+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23+
# See the GNU General Public License, version 2.0, for more details.
24+
#
25+
# You should have received a copy of the GNU General Public License
26+
# along with this program; if not, write to the Free Software Foundation, Inc.,
27+
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28+
29+
#
30+
# Note: We must clear compile flags - the ones used to build the connector
31+
# are not good for building client code that uses the connector.
32+
#
33+
34+
set_property(
35+
DIRECTORY .
36+
PROPERTY COMPILE_DEFINITIONS ""
37+
)
38+
39+
if(WIN32)
40+
add_definitions(
41+
-D_CRT_SECURE_NO_WARNINGS
42+
-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
43+
)
44+
45+
endif()
46+
47+
#Add cdk includes because we are using their source tests
48+
add_test_includes(${PROJECT_SOURCE_DIR}/cdk/include)
49+
add_test_includes(${PROJECT_SOURCE_DIR}/cdk/extra/rapidjson/include)
50+
add_test_includes(${PROJECT_BINARY_DIR}/cdk/include)
51+
52+
ADD_TEST_LIBRARIES(cdk_parser)
53+
54+
ADD_NG_TEST(common-t
55+
${PROJECT_SOURCE_DIR}/cdk/parser/tests/parser-t.cc
56+
)
57+
58+

devapi/tests/crud-t.cc

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,3 +2836,80 @@ TEST_F(Crud, PS)
28362836
}
28372837

28382838
}
2839+
2840+
TEST_F(Crud, overlaps)
2841+
{
2842+
SKIP_IF_NO_XPLUGIN;
2843+
SKIP_IF_SERVER_VERSION_LESS(8, 0, 15)
2844+
2845+
cout << "Creating collection..." << endl;
2846+
2847+
Schema sch = getSchema("test");
2848+
Collection coll = sch.createCollection("c1", true);
2849+
2850+
coll.remove("true").execute();
2851+
2852+
2853+
coll.add("{ \"name\": \"foo\", \"age\": 2, \
2854+
\"food\": [\"Milk\", \"Soup\"] }")
2855+
.add("{ \"name\": \"baz\", \"age\": 2, \
2856+
\"food\": [\"Beer\", \"Soup\"] }")
2857+
.execute();
2858+
2859+
auto res = coll.find(R"(food overlaps ["Soup"])").execute();
2860+
EXPECT_EQ(2, res.count());
2861+
2862+
res = coll.find(R"(food overlaps ["Milk", "Soup"])").execute();
2863+
EXPECT_EQ(2, res.count());
2864+
2865+
res = coll.find(R"(food overlaps ["Milk"])").execute();
2866+
EXPECT_EQ(1, res.count());
2867+
EXPECT_EQ(string("foo"),res.fetchOne()["name"]);
2868+
2869+
res = coll.find(R"(food overlaps ["Beer"])").execute();
2870+
EXPECT_EQ(1, res.count());
2871+
EXPECT_EQ(string("baz"),res.fetchOne()["name"]);
2872+
2873+
res = coll.find(R"(food overlaps ["Meat"])").execute();
2874+
EXPECT_EQ(0, res.count());
2875+
2876+
res = coll.find(R"(food overlaps "Meat")").execute();
2877+
EXPECT_EQ(0, res.count());
2878+
2879+
// Not Overlaps tests
2880+
2881+
res = coll.find(R"(food not overlaps ["Soup"])").execute();
2882+
EXPECT_EQ(0, res.count());
2883+
2884+
res = coll.find(R"(food not overlaps ["Milk", "Soup"])").execute();
2885+
EXPECT_EQ(0, res.count());
2886+
2887+
res = coll.find(R"(food not overlaps ["Milk"])").execute();
2888+
EXPECT_EQ(1, res.count());
2889+
EXPECT_EQ(string("baz"),res.fetchOne()["name"]);
2890+
2891+
res = coll.find(R"(food not overlaps ["Beer"])").execute();
2892+
EXPECT_EQ(1, res.count());
2893+
EXPECT_EQ(string("foo"),res.fetchOne()["name"]);
2894+
2895+
res = coll.find(R"(food not overlaps ["Meat"])").execute();
2896+
EXPECT_EQ(2, res.count());
2897+
2898+
res = coll.find(R"(food not overlaps "Meat")").execute();
2899+
EXPECT_EQ(2, res.count());
2900+
2901+
try {
2902+
coll.find(R"(food not overlaps and "Meat")").execute();
2903+
FAIL() << "No error thrown";
2904+
} catch (Error& e) {
2905+
std::cout << "Expected: " << e << std::endl;
2906+
}
2907+
2908+
try {
2909+
coll.find(R"(food and overlaps "Meat")").execute();
2910+
FAIL() << "No error thrown";
2911+
} catch (Error& e) {
2912+
std::cout << "Expected: " << e << std::endl;
2913+
}
2914+
2915+
}

0 commit comments

Comments
 (0)