Repository: incubator-eagle Updated Branches: refs/heads/develop 34e77cafc -> 9432fcf91
[EAGLE-473] Query error if query string contains "[]" https://issues.apache.org/jira/browse/EAGLE-473 Fix the bug with an unit test Author: Qingwen Zhao <qingwen...@gmail.com> Closes #361 from qingwen220/EAGLE-473. Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/9432fcf9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/9432fcf9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/9432fcf9 Branch: refs/heads/develop Commit: 9432fcf91ab94cd9e228eb353e1b93739f977e67 Parents: 34e77ca Author: Qingwen Zhao <qingwen...@gmail.com> Authored: Fri Aug 19 12:09:53 2016 +0800 Committer: Qingwen Zhao <qingwen...@gmail.com> Committed: Fri Aug 19 12:09:53 2016 +0800 ---------------------------------------------------------------------- .../apache/eagle/query/ListQueryCompiler.java | 6 +-- .../aggregate/test/TestListQueryCompiler.java | 47 ++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/9432fcf9/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/ListQueryCompiler.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/ListQueryCompiler.java b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/ListQueryCompiler.java index c630c41..ab01064 100755 --- a/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/ListQueryCompiler.java +++ b/eagle-core/eagle-query/eagle-query-base/src/main/java/org/apache/eagle/query/ListQueryCompiler.java @@ -42,7 +42,7 @@ public class ListQueryCompiler { /** * syntax is <EntityName>[<Filter>]{<Projection>} */ - private final static String listRegex = "^([^\\[]+)\\[([^\\]]*)\\]\\{(.+)\\}$"; + private final static String listRegex = "^([^\\[]+)\\[(.*)\\]\\{(.+)\\}$"; private final static Pattern _listPattern = Pattern.compile(listRegex); /** @@ -62,10 +62,10 @@ public class ListQueryCompiler { */ /** The regular expression before add EXP{<Expression>} in query **/ - private final static String aggRegex = "^([^\\[]+)\\[([^\\]]*)\\]<([^>]*)>\\{(.+)\\}$"; + private final static String aggRegex = "^([^\\[]+)\\[(.*)\\]<([^>]*)>\\{(.+)\\}$"; private final static Pattern _aggPattern = Pattern.compile(aggRegex); - private final static String sortRegex = "^([^\\[]+)\\[([^\\]]*)\\]<([^>]*)>\\{(.+)\\}\\.\\{(.+)\\}$"; + private final static String sortRegex = "^([^\\[]+)\\[(.*)\\]<([^>]*)>\\{(.+)\\}\\.\\{(.+)\\}$"; private final static Pattern _sortPattern = Pattern.compile(sortRegex); private String _serviceName; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/9432fcf9/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestListQueryCompiler.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestListQueryCompiler.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestListQueryCompiler.java new file mode 100644 index 0000000..10f96dc --- /dev/null +++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestListQueryCompiler.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.eagle.query.aggregate.test; + +import org.apache.eagle.query.ListQueryCompiler; +import org.apache.eagle.query.parser.EagleQueryParseException; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestListQueryCompiler { + private final static Logger LOG = LoggerFactory.getLogger(TestListQueryCompiler.class); + @Test + public void test() throws Exception { + try { + String queryWithCondition = "TestTimeSeriesAPIEntity[@site=\"test\"]{*}"; + ListQueryCompiler compiler = new ListQueryCompiler(queryWithCondition); + String queryWithSquareBrackets = "TestTimeSeriesAPIEntity[@condition=\"[A9BB756BFB8] Data[site=2]/(4/5)\"]{*}"; + new ListQueryCompiler(queryWithSquareBrackets); + String queryWithoutCondition = "TestTimeSeriesAPIEntity[]{*}"; + new ListQueryCompiler(queryWithoutCondition); + String query = "TestTimeSeriesAPIEntity[@condition=\"[A9BB756BFB8]{4/5}\"]{*}"; + new ListQueryCompiler(query); + } catch (IllegalArgumentException e) { + LOG.error(e.getMessage()); + Assert.assertTrue(false); + } + Assert.assertTrue(true); + } +}