Package com.youtube.vitess.vtgate

Examples of com.youtube.vitess.vtgate.KeyRange


      List<KeyRange> keyranges = new ArrayList<>();
      for (Object o : (List<?>) query.get("KeyRanges")) {
        BSONObject keyrange = (BasicBSONObject) o;
        String start = Hex.encodeHexString((byte[]) keyrange.get("Start"));
        String end = Hex.encodeHexString((byte[]) keyrange.get("End"));
        KeyRange kr = new KeyRange(KeyspaceId.valueOf(start), KeyspaceId.valueOf(end));
        keyranges.add(kr);
      }

      Query q = new QueryBuilder(sql, keyspace, tabletType).setKeyRanges(keyranges)
          .setBindVars(bindVariables).setStreaming(true).build();
View Full Code Here


    for (String shardName : testEnv.shardKidMap.keySet()) {
      Util.insertRowsInShard(testEnv, shardName, rowCount);
    }
    for (String shardName : testEnv.shardKidMap.keySet()) {
      List<KeyspaceId> kids = testEnv.getKeyspaceIds(shardName);
      KeyRange kr = new KeyRange(Collections.min(kids), Collections.max(kids));
      String selectSql = "select A.* from vtgate_test A join vtgate_test B join vtgate_test C";
      Query query = new QueryBuilder(selectSql, testEnv.keyspace, "master").addKeyRange(kr)
          .setStreaming(true).build();
      Cursor cursor = vtgate.execute(query);
      int count = 0;
View Full Code Here

    // Check KeyRange query limited to a single shard returns 10 rows each
    for (String shardName : testEnv.shardKidMap.keySet()) {
      List<KeyspaceId> shardKids = testEnv.getKeyspaceIds(shardName);
      KeyspaceId minKid = Collections.min(shardKids);
      KeyspaceId maxKid = Collections.max(shardKids);
      KeyRange shardKeyRange = new KeyRange(minKid, maxKid);
      Query shardRangeQuery = new QueryBuilder(selectSql, testEnv.keyspace, "master").addKeyRange(
          shardKeyRange).build();
      cursor = vtgate.execute(shardRangeQuery);
      Assert.assertEquals(rowsPerShard, cursor.getRowsAffected());
    }

    // Now make a cross-shard KeyRange and check all rows are returned
    Iterator<String> shardNameIter = testEnv.shardKidMap.keySet().iterator();
    KeyspaceId kidShard1 = testEnv.getKeyspaceIds(shardNameIter.next()).get(2);
    KeyspaceId kidShard2 = testEnv.getKeyspaceIds(shardNameIter.next()).get(2);
    KeyRange crossShardKeyrange;
    if (kidShard1.compareTo(kidShard2) < 0) {
      crossShardKeyrange = new KeyRange(kidShard1, kidShard2);
    } else {
      crossShardKeyrange = new KeyRange(kidShard2, kidShard1);
    }
    Query shardRangeQuery = new QueryBuilder(selectSql, testEnv.keyspace, "master").addKeyRange(
        crossShardKeyrange).build();
    cursor = vtgate.execute(shardRangeQuery);
    Assert.assertEquals(rowsPerShard * 2, cursor.getRowsAffected());
View Full Code Here

    // Insert 20 rows per shard
    for (String shardName : testEnv.shardKidMap.keySet()) {
      List<KeyspaceId> kids = testEnv.getKeyspaceIds(shardName);
      KeyspaceId minKid = Collections.min(kids);
      KeyspaceId maxKid = Collections.max(kids);
      KeyRange kr = new KeyRange(minKid, maxKid);
      for (int i = 0; i < count; i++) {
        KeyspaceId kid = kids.get(i % kids.size());
        Query query = new QueryBuilder(sql, testEnv.keyspace, "master")
            .addBindVar(
                BindVariable.forULong("id", UnsignedLong.valueOf("" + Math.abs(random.nextInt()))))
View Full Code Here

TOP

Related Classes of com.youtube.vitess.vtgate.KeyRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.