Search in sources :

Example 1 with EarlyParam

use of com.xiaomi.linden.thrift.common.EarlyParam in project linden by XiaoMi.

the class TestBQL method testRoute.

@Test
public void testRoute() {
    String bql = "SELECT * FROM linden where title = 'sed' route by 0, 1, 2, replica_key '12345'";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    SearchRouteParam routeParam = new SearchRouteParam();
    routeParam.addToShardParams(new ShardRouteParam(0));
    routeParam.addToShardParams(new ShardRouteParam(1));
    routeParam.addToShardParams(new ShardRouteParam(2));
    routeParam.setReplicaRouteKey("12345");
    Assert.assertEquals(routeParam, lindenRequest.getRouteParam());
    bql = "SELECT * FROM linden where title = 'sed' route by 0 in top 500, 1, 2, $a, $shard in top 500, 3 in top $max";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    routeParam = new SearchRouteParam();
    routeParam.addToShardParams(new ShardRouteParam(0).setEarlyParam(new EarlyParam(500)));
    routeParam.addToShardParams(new ShardRouteParam(1));
    routeParam.addToShardParams(new ShardRouteParam(2));
    routeParam.addToShardParams(new ShardRouteParam(3));
    Assert.assertEquals(routeParam, lindenRequest.getRouteParam());
    bql = "SELECT * FROM linden where title = 'sed' route by (0,1) in top 10000, ($shard) in top 1000, 2";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    routeParam = new SearchRouteParam();
    routeParam.addToShardParams(new ShardRouteParam(0).setEarlyParam(new EarlyParam().setMaxNum(10000)));
    routeParam.addToShardParams(new ShardRouteParam(1).setEarlyParam(new EarlyParam().setMaxNum(10000)));
    routeParam.addToShardParams(new ShardRouteParam(2));
    Assert.assertEquals(routeParam, lindenRequest.getRouteParam());
}
Also used : ShardRouteParam(com.xiaomi.linden.thrift.common.ShardRouteParam) EarlyParam(com.xiaomi.linden.thrift.common.EarlyParam) SearchRouteParam(com.xiaomi.linden.thrift.common.SearchRouteParam) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 2 with EarlyParam

use of com.xiaomi.linden.thrift.common.EarlyParam in project linden by XiaoMi.

the class BQLCompilerAnalyzer method exitRoute_multi_shard_values.

@Override
public void exitRoute_multi_shard_values(BQLParser.Route_multi_shard_valuesContext ctx) {
    List<ShardRouteParam> params = new ArrayList<>();
    for (BQLParser.Numeric_valueContext shardCtx : ctx.numeric_value()) {
        if (shardCtx.PLACEHOLDER() != null) {
            continue;
        }
        ShardRouteParam shardRouteParam = new ShardRouteParam();
        int shardId = Integer.valueOf(shardCtx.getText());
        shardRouteParam.setShardId(shardId);
        EarlyParam earlyParam = (EarlyParam) valProperty.get(ctx.in_top_clause());
        if (earlyParam != null) {
            shardRouteParam.setEarlyParam(earlyParam);
        }
        params.add(shardRouteParam);
    }
    if (!params.isEmpty()) {
        valProperty.put(ctx, params);
    }
}
Also used : ShardRouteParam(com.xiaomi.linden.thrift.common.ShardRouteParam) ArrayList(java.util.ArrayList) EarlyParam(com.xiaomi.linden.thrift.common.EarlyParam)

Example 3 with EarlyParam

use of com.xiaomi.linden.thrift.common.EarlyParam in project linden by XiaoMi.

the class BQLCompilerAnalyzer method exitRoute_single_shard_value.

@Override
public void exitRoute_single_shard_value(BQLParser.Route_single_shard_valueContext ctx) {
    // ignore
    if (ctx.numeric_value().PLACEHOLDER() != null) {
        return;
    }
    ShardRouteParam shardRouteParam = new ShardRouteParam();
    int shardId = Integer.valueOf(ctx.numeric_value().getText());
    shardRouteParam.setShardId(shardId);
    EarlyParam earlyParam = (EarlyParam) valProperty.get(ctx.in_top_clause());
    if (earlyParam != null) {
        shardRouteParam.setEarlyParam(earlyParam);
    }
    valProperty.put(ctx, shardRouteParam);
}
Also used : ShardRouteParam(com.xiaomi.linden.thrift.common.ShardRouteParam) EarlyParam(com.xiaomi.linden.thrift.common.EarlyParam)

Example 4 with EarlyParam

use of com.xiaomi.linden.thrift.common.EarlyParam in project linden by XiaoMi.

the class BQLCompilerAnalyzer method exitIn_top_clause.

@Override
public void exitIn_top_clause(BQLParser.In_top_clauseContext ctx) {
    if (ctx.max_num != null && ctx.max_num.PLACEHOLDER() == null) {
        EarlyParam param = new EarlyParam();
        param.setMaxNum(Integer.parseInt(ctx.max_num.getText()));
        valProperty.put(ctx, param);
    }
}
Also used : EarlyParam(com.xiaomi.linden.thrift.common.EarlyParam)

Example 5 with EarlyParam

use of com.xiaomi.linden.thrift.common.EarlyParam in project linden by XiaoMi.

the class TestBQL method testInTop.

@Test
public void testInTop() {
    String bql = "SELECT * FROM linden where title = 'sed' in top 500";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    EarlyParam earlyParam = new EarlyParam();
    earlyParam.setMaxNum(500);
    Assert.assertEquals(earlyParam, lindenRequest.getEarlyParam());
    bql = "SELECT * FROM linden where title = 'sed' in top $num";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertFalse(lindenRequest.isSetEarlyParam());
    bql = "SELECT * FROM linden where title = 'sed' route by (0, 1, 2) in top 500, 3, replica_key '123'";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertFalse(lindenRequest.isSetEarlyParam());
    Assert.assertEquals(4, lindenRequest.getRouteParam().getShardParamsSize());
    Assert.assertEquals(earlyParam, lindenRequest.getRouteParam().getShardParams().get(0).getEarlyParam());
    Assert.assertEquals(0, lindenRequest.getRouteParam().getShardParams().get(0).getShardId());
    Assert.assertEquals(earlyParam, lindenRequest.getRouteParam().getShardParams().get(1).getEarlyParam());
    Assert.assertEquals(1, lindenRequest.getRouteParam().getShardParams().get(1).getShardId());
    Assert.assertEquals(earlyParam, lindenRequest.getRouteParam().getShardParams().get(2).getEarlyParam());
    Assert.assertEquals(2, lindenRequest.getRouteParam().getShardParams().get(2).getShardId());
    Assert.assertFalse(lindenRequest.getRouteParam().getShardParams().get(3).isSetEarlyParam());
    Assert.assertEquals(3, lindenRequest.getRouteParam().getShardParams().get(3).getShardId());
    Assert.assertEquals("123", lindenRequest.getRouteParam().getReplicaRouteKey());
}
Also used : EarlyParam(com.xiaomi.linden.thrift.common.EarlyParam) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Aggregations

EarlyParam (com.xiaomi.linden.thrift.common.EarlyParam)5 ShardRouteParam (com.xiaomi.linden.thrift.common.ShardRouteParam)3 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)2 Test (org.junit.Test)2 SearchRouteParam (com.xiaomi.linden.thrift.common.SearchRouteParam)1 ArrayList (java.util.ArrayList)1