mirror of
https://github.com/tencentmusic/supersonic.git
synced 2026-04-25 17:24:27 +08:00
[improvement][Headless] Remove headless build.xml and add tag query testing. (#706)
This commit is contained in:
@@ -43,11 +43,15 @@ public class BaseTest extends BaseApplication {
|
||||
}
|
||||
|
||||
protected QueryStructReq buildQueryStructReq(List<String> groups) {
|
||||
return buildQueryStructReq(groups, QueryType.METRIC);
|
||||
}
|
||||
|
||||
protected QueryStructReq buildQueryStructReq(List<String> groups, QueryType queryType) {
|
||||
QueryStructReq queryStructReq = new QueryStructReq();
|
||||
for (Long modelId : DataUtils.getMetricAgentIModelIds()) {
|
||||
queryStructReq.addModelId(modelId);
|
||||
}
|
||||
queryStructReq.setQueryType(QueryType.METRIC);
|
||||
queryStructReq.setQueryType(queryType);
|
||||
Aggregator aggregator = new Aggregator();
|
||||
aggregator.setFunc(AggOperatorEnum.SUM);
|
||||
aggregator.setColumn("pv");
|
||||
@@ -55,7 +59,6 @@ public class BaseTest extends BaseApplication {
|
||||
|
||||
if (CollectionUtils.isNotEmpty(groups)) {
|
||||
queryStructReq.setGroups(groups);
|
||||
queryStructReq.setGroups(Arrays.asList("department"));
|
||||
}
|
||||
|
||||
DateConf dateConf = new DateConf();
|
||||
@@ -71,5 +74,4 @@ public class BaseTest extends BaseApplication {
|
||||
queryStructReq.setOrders(orders);
|
||||
return queryStructReq;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,4 +45,5 @@ public class ExplainTest extends BaseTest {
|
||||
assertTrue(explain.getSql().contains("department"));
|
||||
assertTrue(explain.getSql().contains("pv"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.tencent.supersonic.headless;
|
||||
import static java.time.LocalDate.now;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||
@@ -12,6 +13,18 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
public class QueryBySqlTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testDetailQuery() throws Exception {
|
||||
SemanticQueryResp semanticQueryResp = queryBySql("SELECT 用户,访问次数 FROM 超音数PVUV统计 WHERE 用户='alice' ");
|
||||
|
||||
assertEquals(2, semanticQueryResp.getColumns().size());
|
||||
QueryColumn firstColumn = semanticQueryResp.getColumns().get(0);
|
||||
assertEquals("用户", firstColumn.getName());
|
||||
QueryColumn secondColumn = semanticQueryResp.getColumns().get(1);
|
||||
assertEquals("访问次数", secondColumn.getName());
|
||||
assertTrue(semanticQueryResp.getResultList().size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSumQuery() throws Exception {
|
||||
SemanticQueryResp semanticQueryResp = queryBySql("SELECT SUM(访问次数) AS 访问次数 FROM 超音数PVUV统计 ");
|
||||
@@ -62,7 +75,7 @@ public class QueryBySqlTest extends BaseTest {
|
||||
public void testCacheQuery() throws Exception {
|
||||
SemanticQueryResp result1 = queryBySql("SELECT 部门, SUM(访问次数) AS 访问次数 FROM 超音数PVUV统计 GROUP BY 部门 ");
|
||||
SemanticQueryResp result2 = queryBySql("SELECT 部门, SUM(访问次数) AS 访问次数 FROM 超音数PVUV统计 GROUP BY 部门 ");
|
||||
assertEquals(result1, result2);
|
||||
assertTrue(result1 == result2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.tencent.supersonic.headless;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.Filter;
|
||||
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||
import com.tencent.supersonic.common.pojo.enums.QueryType;
|
||||
import com.tencent.supersonic.common.pojo.exception.InvalidPermissionException;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryStructReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.SemanticQueryResp;
|
||||
@@ -18,6 +20,21 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
public class QueryByStructTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testDetailQuery() throws Exception {
|
||||
QueryStructReq queryStructReq = buildQueryStructReq(Arrays.asList("user_name", "department"),
|
||||
QueryType.TAG);
|
||||
SemanticQueryResp semanticQueryResp = queryService.queryByReq(queryStructReq, User.getFakeUser());
|
||||
assertEquals(3, semanticQueryResp.getColumns().size());
|
||||
QueryColumn firstColumn = semanticQueryResp.getColumns().get(0);
|
||||
assertEquals("用户", firstColumn.getName());
|
||||
QueryColumn secondColumn = semanticQueryResp.getColumns().get(1);
|
||||
assertEquals("部门", secondColumn.getName());
|
||||
QueryColumn thirdColumn = semanticQueryResp.getColumns().get(2);
|
||||
assertEquals("访问次数", thirdColumn.getName());
|
||||
assertTrue(semanticQueryResp.getResultList().size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSumQuery() throws Exception {
|
||||
QueryStructReq queryStructReq = buildQueryStructReq(null);
|
||||
@@ -68,7 +85,7 @@ public class QueryByStructTest extends BaseTest {
|
||||
QueryStructReq queryStructReq2 = buildQueryStructReq(Arrays.asList("department"));
|
||||
SemanticQueryResp result1 = queryService.queryByReq(queryStructReq1, User.getFakeUser());
|
||||
SemanticQueryResp result2 = queryService.queryByReq(queryStructReq2, User.getFakeUser());
|
||||
assertEquals(result1, result2);
|
||||
assertTrue(result1 == result2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user