use of com.xiaomi.linden.thrift.common.LindenDeleteRequest in project linden by XiaoMi.
the class TestLindenCore method deleteTest.
@Test
public void deleteTest() throws IOException {
String bql = "delete from linden where id = '1'";
LindenDeleteRequest request = bqlCompiler.compile(bql).getDeleteRequest();
lindenCore.delete(request);
lindenCore.refresh();
bql = "select * from linden where id = '1'";
LindenSearchRequest searchRequest = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(searchRequest);
Assert.assertEquals(0, result.getTotalHits());
bql = "select * from linden";
searchRequest = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(searchRequest);
Assert.assertEquals(5, result.getTotalHits());
bql = "select * from linden where id >= '1' and id <='3'";
searchRequest = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(searchRequest);
Assert.assertEquals(2, result.getTotalHits());
bql = "delete from linden where id >= '1' and id <='3'";
LindenDeleteRequest deleteRequest = bqlCompiler.compile(bql).getDeleteRequest();
lindenCore.delete(deleteRequest);
lindenCore.refresh();
bql = "select * from linden";
searchRequest = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(searchRequest);
Assert.assertEquals(3, result.getTotalHits());
bql = "delete from linden";
request = bqlCompiler.compile(bql).getDeleteRequest();
lindenCore.delete(request);
lindenCore.refresh();
bql = "select * from linden";
searchRequest = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(searchRequest);
Assert.assertEquals(0, result.getTotalHits());
}
use of com.xiaomi.linden.thrift.common.LindenDeleteRequest in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitDelete_stmt.
@Override
public void exitDelete_stmt(BQLParser.Delete_stmtContext ctx) {
deleteRequest = new LindenDeleteRequest();
if (ctx.dw != null) {
LindenFilter filter = filterProperty.get(ctx.dw);
if (filter == null) {
throw new ParseCancellationException(new SemanticException(ctx, "Filter parse failed"));
}
LindenQuery query = LindenQueryBuilder.buildMatchAllQuery();
query = LindenQueryBuilder.buildFilteredQuery(query, filter);
deleteRequest.setQuery(query);
} else {
deleteRequest.setQuery(LindenQueryBuilder.buildMatchAllQuery());
}
if (ctx.route_param != null) {
deleteRequest.setRouteParam((SearchRouteParam) valProperty.get(ctx.route_param));
}
if (ctx.indexes != null) {
deleteRequest.setIndexNames((List<String>) valProperty.get(ctx.indexes));
}
}
use of com.xiaomi.linden.thrift.common.LindenDeleteRequest in project linden by XiaoMi.
the class TestBQL method testDelete.
@Test
public void testDelete() {
String bql = "delete from linden where title = 'sed'";
LindenDeleteRequest lindenRequest = compiler.compile(bql).getDeleteRequest();
LindenTermFilter termFilter = new LindenTermFilter().setTerm(new LindenTerm().setField("title").setValue("sed"));
Assert.assertEquals(termFilter, lindenRequest.getQuery().getFilteredQuery().getLindenFilter().getTermFilter());
bql = "delete from linden";
lindenRequest = compiler.compile(bql).getDeleteRequest();
Assert.assertTrue(lindenRequest.getQuery().isSetMatchAllQuery());
bql = "delete from tag_1,tag_2";
lindenRequest = compiler.compile(bql).getDeleteRequest();
Assert.assertEquals(lindenRequest.getIndexNames().size(), 2);
Assert.assertEquals(lindenRequest.getIndexNames().get(0), "tag_1");
Assert.assertEquals(lindenRequest.getIndexNames().get(1), "tag_2");
bql = "delete from linden where id = '123' route by 1, 2, 3";
lindenRequest = compiler.compile(bql).getDeleteRequest();
Assert.assertTrue(lindenRequest.getQuery().isSetFilteredQuery());
Assert.assertEquals(3, lindenRequest.getRouteParam().getShardParamsSize());
Assert.assertEquals(1, lindenRequest.getRouteParam().getShardParams().get(0).getShardId());
Assert.assertEquals(2, lindenRequest.getRouteParam().getShardParams().get(1).getShardId());
}
use of com.xiaomi.linden.thrift.common.LindenDeleteRequest in project linden by XiaoMi.
the class TestBQL method testEqualPredicate.
@Test
public void testEqualPredicate() {
String bql = "select * from linden where title = \"qq\" and id = 211 limit 10, 50";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getFilter().isSetBooleanFilter());
LindenBooleanFilter booleanFilter = lindenRequest.getFilter().getBooleanFilter();
Assert.assertEquals(2, booleanFilter.getFiltersSize());
Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(0).getClause());
Assert.assertEquals(new LindenTerm("title", "qq"), booleanFilter.getFilters().get(0).getFilter().getTermFilter().getTerm());
Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(1).getClause());
Assert.assertEquals(new LindenRange("id", LindenType.LONG, true, true).setStartValue("211").setEndValue("211"), booleanFilter.getFilters().get(1).getFilter().getRangeFilter().getRange());
Assert.assertEquals(10, lindenRequest.getOffset());
Assert.assertEquals(50, lindenRequest.getLength());
bql = "delete from default where title = \"q\"\"q\" and id = 211";
LindenDeleteRequest deleteRequest = compiler.compile(bql).getDeleteRequest();
Assert.assertTrue(deleteRequest.getQuery().isSetFilteredQuery());
Assert.assertTrue(deleteRequest.getQuery().getFilteredQuery().isSetLindenFilter());
Assert.assertTrue(deleteRequest.getQuery().getFilteredQuery().getLindenFilter().isSetBooleanFilter());
booleanFilter = deleteRequest.getQuery().getFilteredQuery().getLindenFilter().getBooleanFilter();
Assert.assertEquals(2, booleanFilter.getFiltersSize());
Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(0).getClause());
Assert.assertEquals(new LindenTerm("title", "q\"q"), booleanFilter.getFilters().get(0).getFilter().getTermFilter().getTerm());
Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(1).getClause());
Assert.assertEquals(new LindenRange("id", LindenType.LONG, true, true).setStartValue("211").setEndValue("211"), booleanFilter.getFilters().get(1).getFilter().getRangeFilter().getRange());
bql = "delete from default where title = $a and id = 211";
deleteRequest = compiler.compile(bql).getDeleteRequest();
Assert.assertTrue(deleteRequest.getQuery().isSetFilteredQuery());
Assert.assertTrue(deleteRequest.getQuery().getFilteredQuery().isSetLindenFilter());
Assert.assertTrue(deleteRequest.getQuery().getFilteredQuery().getLindenFilter().isSetRangeFilter());
bql = "select * from linden where dynmaicTitle.STRING = \"qq\" and dynamicId.int = 211 limit 10, 50";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getFilter().isSetBooleanFilter());
booleanFilter = lindenRequest.getFilter().getBooleanFilter();
Assert.assertEquals(2, booleanFilter.getFiltersSize());
Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(0).getClause());
Assert.assertEquals(new LindenTerm("dynmaicTitle", "qq"), booleanFilter.getFilters().get(0).getFilter().getTermFilter().getTerm());
Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(1).getClause());
Assert.assertEquals(new LindenRange("dynamicId", LindenType.INTEGER, true, true).setStartValue("211").setEndValue("211"), booleanFilter.getFilters().get(1).getFilter().getRangeFilter().getRange());
Assert.assertEquals(10, lindenRequest.getOffset());
Assert.assertEquals(50, lindenRequest.getLength());
bql = "select * from linden by title = \"qq\" subBoost by 0.5 and id = 211 andDisableCoord limit 10, 50";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.isSetFilter());
Assert.assertTrue(lindenRequest.getQuery().isSetBooleanQuery());
LindenBooleanQuery query = lindenRequest.getQuery().getBooleanQuery();
Assert.assertTrue(query.isDisableCoord());
Assert.assertEquals(2, query.getQueriesSize());
Assert.assertEquals(LindenBooleanClause.MUST, query.getQueries().get(0).clause);
Assert.assertEquals(new LindenTerm("title", "qq"), query.getQueries().get(0).getQuery().getTermQuery().getTerm());
Assert.assertEquals(0.5, query.getQueries().get(0).getQuery().getBoost(), 0.001);
Assert.assertEquals(LindenBooleanClause.MUST, query.getQueries().get(1).clause);
Assert.assertEquals(new LindenRange("id", LindenType.LONG, true, true).setStartValue("211").setEndValue("211"), query.getQueries().get(1).getQuery().getRangeQuery().getRange());
Assert.assertEquals(10, lindenRequest.getOffset());
Assert.assertEquals(50, lindenRequest.getLength());
}
use of com.xiaomi.linden.thrift.common.LindenDeleteRequest in project linden by XiaoMi.
the class TestMultiLindenCore method testTimeDivision.
@Test
public void testTimeDivision() throws Exception {
String path = FilenameUtils.concat(INDEX_DIR, "time/");
lindenConfig.setIndexDirectory(path).setMultiIndexDivisionType(LindenConfig.MultiIndexDivisionType.TIME_HOUR).setLindenCoreMode(LindenConfig.LindenCoreMode.MULTI).setMultiIndexMaxLiveIndexNum(10);
Deencapsulation.setField(DocNumLimitMultiIndexStrategy.class, "INDEX_CHECK_INTERVAL_MILLISECONDS", -10);
lindenCore = new MultiLindenCoreImpl(lindenConfig);
for (int i = 0; i < 400; ++i) {
JSONObject json = new JSONObject();
json.put("type", "index");
JSONObject content = new JSONObject();
content.put("id", i);
content.put("title", "test " + i);
json.put("content", content);
handleRequest(json.toJSONString());
}
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(8, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(400, lindenCore.getServiceInfo().getDocsNum());
String bql = "select * from linden source";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(400, result.getTotalHits());
for (int i = 0; i < 400; ++i) {
JSONObject json = new JSONObject();
json.put("type", "index");
JSONObject content = new JSONObject();
content.put("id", i);
content.put("title", "test " + (400 + i));
json.put("content", content);
handleRequest(json.toJSONString());
}
lindenCore.commit();
lindenCore.refresh();
result = lindenCore.search(request);
Assert.assertEquals(500, result.getTotalHits());
Assert.assertEquals(10, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(500, lindenCore.getServiceInfo().getDocsNum());
bql = "delete from linden where query is 'title:400 title:401'";
LindenDeleteRequest deleteRequest = bqlCompiler.compile(bql).getDeleteRequest();
lindenCore.delete(deleteRequest);
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(498, lindenCore.getServiceInfo().getDocsNum());
lindenCore.close();
}
Aggregations