提交 86c8a18a 编写于 作者: V Vlad Ilyushchenko

optimisation + test

上级 d3dd53dc
......@@ -58,30 +58,28 @@ class LiteralMatcher implements PostOrderTreeTraversalAlgo.Visitor {
@Override
public void visit(ExprNode node) throws ParserException {
if (node.type == ExprNode.NodeType.LITERAL) {
if (match) {
if (names.contains(node.token)) {
return;
}
if (alias == null) {
match = false;
return;
}
if (node.type == ExprNode.NodeType.LITERAL && match) {
if (names.contains(node.token)) {
return;
}
ColumnName columnName = ColumnName.singleton(node.token);
if (alias == null) {
match = false;
return;
}
if (columnName.alias() == null) {
match = false;
return;
}
ColumnName columnName = ColumnName.singleton(node.token);
if (Chars.equals(columnName.alias(), alias) && names.contains(columnName.name())) {
node.token = columnName.name().toString();
return;
}
if (columnName.alias() == null) {
match = false;
return;
}
if (Chars.equals(columnName.alias(), alias) && names.contains(columnName.name())) {
node.token = columnName.name().toString();
return;
}
match = false;
}
}
......
......@@ -42,6 +42,7 @@ public class QueryResponse {
public String error;
public String query;
public List<String[]> result;
public long count;
public static class Tab {
public String id;
......
......@@ -209,11 +209,19 @@ public class QueryHandlerTest extends AbstractOptimiserTest {
@Test
public void testJsonSimpleNoMeta() throws Exception {
QueryResponse queryResponse = download("select 1 z from tab limit 10", 0, 10, true, temp);
QueryResponse queryResponse = download("select 1 z from tab limit 10", 0, 10, true, false, temp);
Assert.assertEquals(10, queryResponse.result.size());
Assert.assertNull(queryResponse.query);
}
@Test
public void testJsonSimpleNoMetaAndCount() throws Exception {
QueryResponse queryResponse = download("select 1 z from tab", 0, 10, true, true, temp);
Assert.assertEquals(10, queryResponse.result.size());
Assert.assertEquals(1000, queryResponse.count);
Assert.assertNull(queryResponse.query);
}
@Test
public void testJsonTakeLimit() throws Exception {
QueryResponse queryResponse = download("tab limit 10", 2, -1);
......@@ -227,7 +235,7 @@ public class QueryHandlerTest extends AbstractOptimiserTest {
}
static QueryResponse download(String queryUrl, TemporaryFolder temp) throws Exception {
return download(queryUrl, -1, -1, false, temp);
return download(queryUrl, -1, -1, false, false, temp);
}
static void generateJournal(String name, int count) throws JournalException, NumericException {
......@@ -245,7 +253,7 @@ public class QueryHandlerTest extends AbstractOptimiserTest {
generateJournal(name, new QueryResponse.Tab[]{record}, 1000);
}
private static QueryResponse download(String queryUrl, int limitFrom, int limitTo, boolean noMeta, TemporaryFolder temp) throws Exception {
private static QueryResponse download(String queryUrl, int limitFrom, int limitTo, boolean noMeta, boolean count, TemporaryFolder temp) throws Exception {
File f = temp.newFile();
String url = "http://localhost:9000/js?query=" + URLEncoder.encode(queryUrl, "UTF-8");
if (limitFrom >= 0) {
......@@ -259,6 +267,10 @@ public class QueryHandlerTest extends AbstractOptimiserTest {
url += "&nm=true";
}
if (count) {
url += "&count=true";
}
HttpTestUtils.download(HttpTestUtils.clientBuilder(false), url, f);
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create();
String s = Files.readStringFromFile(f);
......@@ -317,6 +329,6 @@ public class QueryHandlerTest extends AbstractOptimiserTest {
}
private static QueryResponse download(String queryUrl, int limitFrom, int limitTo) throws Exception {
return download(queryUrl, limitFrom, limitTo, false, temp);
return download(queryUrl, limitFrom, limitTo, false, false, temp);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册