Package com.youtube.vitess.vtgate

Examples of com.youtube.vitess.vtgate.KeyspaceId


    }
    Row row = cursor.next();
    rowWritable = new RowWritable(row);
    rowsProcessed++;
    try {
      KeyspaceId keyspaceId = KeyspaceId.valueOf(row.getULong(KeyspaceId.COL_NAME));
      kidWritable = new KeyspaceIdWritable(keyspaceId);
    } catch (InvalidFieldException e) {
      throw new RuntimeException(e);
    }
    return true;
View Full Code Here


  @Test
  public void testIntegrityException() throws Exception {
    VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);
    String insertSql = "insert into vtgate_test(id, keyspace_id) values (:id, :keyspace_id)";
    KeyspaceId kid = testEnv.getAllKeyspaceIds().get(0);
    Query insertQuery = new QueryBuilder(insertSql, testEnv.keyspace, "master")
        .addBindVar(BindVariable.forULong("id", UnsignedLong.valueOf("1")))
        .addBindVar(BindVariable.forULong("keyspace_id", ((UnsignedLong) kid.getId())))
        .addKeyspaceId(kid).build();
    vtgate.begin();
    vtgate.execute(insertQuery);
    vtgate.commit();
    vtgate.begin();
View Full Code Here

    VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);

    vtgate.begin();
    String insertSql = "insert into vtgate_test " + "(id, name, age, percent, keyspace_id) "
        + "values (:id, :name, :age, :percent, :keyspace_id)";
    KeyspaceId kid = testEnv.getAllKeyspaceIds().get(0);
    Query query = new QueryBuilder(insertSql, testEnv.keyspace, "master")
        .addBindVar(BindVariable.forULong("id", UnsignedLong.valueOf("" + 1)))
        .addBindVar(BindVariable.forString("name", ("name_" + 1)))
        .addBindVar(BindVariable.forULong("keyspace_id", (UnsignedLong) kid.getId()))
        .addKeyspaceId(kid)
        .setStreaming(true)
        .build();
    vtgate.execute(query);
    vtgate.commit();
View Full Code Here

    vtgate.begin();
    String insertSql = "insert into vtgate_test "
        + "(id, name, age, percent, datetime_col, timestamp_col, date_col, time_col, keyspace_id) "
        + "values (:id, :name, :age, :percent, :datetime_col, :timestamp_col, :date_col, :time_col, :keyspace_id)";
    for (int i = startId; i < startId + count; i++) {
      KeyspaceId kid = testEnv.getAllKeyspaceIds().get(i % testEnv.getAllKeyspaceIds().size());
      Query query = new QueryBuilder(insertSql, testEnv.keyspace, "master")
          .addBindVar(BindVariable.forULong("id", UnsignedLong.valueOf("" + i)))
          .addBindVar(BindVariable.forBytes("name", ("name_" + i).getBytes()))
          .addBindVar(BindVariable.forInt("age", i * 2))
          .addBindVar(BindVariable.forDouble("percent", new Double(i / 100.0)))
          .addBindVar(BindVariable.forULong("keyspace_id", (UnsignedLong) kid.getId()))
          .addBindVar(BindVariable.forDateTime("datetime_col", dateTime))
          .addBindVar(BindVariable.forDateTime("timestamp_col", dateTime))
          .addBindVar(BindVariable.forDate("date_col", dateTime))
          .addBindVar(BindVariable.forTime("time_col", dateTime))
          .addKeyspaceId(kid)
View Full Code Here

    vtgate.begin();
    String sql = "insert into vtgate_test " + "(id, name, keyspace_id) "
        + "values (:id, :name, :keyspace_id)";
    List<KeyspaceId> kids = testEnv.getKeyspaceIds(shardName);
    for (int i = 1; i <= count; i++) {
      KeyspaceId kid = kids.get(i % kids.size());
      Query query = new QueryBuilder(sql, testEnv.keyspace, "master")
          .addBindVar(BindVariable.forULong("id", UnsignedLong.valueOf("" + i)))
          .addBindVar(BindVariable.forBytes("name", ("name_" + i).getBytes()))
          .addBindVar(BindVariable.forULong("keyspace_id", (UnsignedLong) kid.getId()))
          .addKeyspaceId(kid)
          .build();
      vtgate.execute(query);
    }
    vtgate.commit();
View Full Code Here

    Assert.assertEquals(10, cursor.getRowsAffected());
    Assert.assertEquals(0, cursor.getLastRowId());
    Assert.assertTrue(cursor.hasNext());

    // Fetch all rows from the first shard
    KeyspaceId firstKid = testEnv.getAllKeyspaceIds().get(0);
    Query query =
        new QueryBuilder(selectSql, testEnv.keyspace, "master").addKeyspaceId(firstKid).build();
    cursor = vtgate.execute(query);

    // Check field types and values
View Full Code Here

    Assert.assertEquals(rowsPerShard * 2, cursor.getRowsAffected());

    // 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);
View Full Code Here

        + "values (:id, :name, :keyspace_id, :age)";
    int count = 20;
    // 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()))))
            .addBindVar(BindVariable.forString("name", ("name_" + i)))
            .addBindVar(BindVariable.forULong("keyspace_id", (UnsignedLong) kid.getId()))
            .addBindVar(BindVariable.forNull("age"))
            .addKeyRange(kr)
            .build();
        vtgate.execute(query);
      }
View Full Code Here

TOP

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

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.