Package com.youtube.vitess.vtgate.Query

Examples of com.youtube.vitess.vtgate.Query.QueryBuilder


      Util.insertRowsInShard(testEnv, shardName, rowCount);
    }
    VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);
    for (String shardName : testEnv.shardKidMap.keySet()) {
      String selectSql = "select A.* from vtgate_test A join vtgate_test B join vtgate_test C";
      Query query = new QueryBuilder(selectSql, testEnv.keyspace, "master")
          .setKeyspaceIds(testEnv.getKeyspaceIds(shardName)).setStreaming(true).build();
      Cursor cursor = vtgate.execute(query);
      int count = 0;
      while (cursor.hasNext()) {
        cursor.next();
View Full Code Here


    }
    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;
      while (cursor.hasNext()) {
        cursor.next();
View Full Code Here

    int rowCount = 10;
    for (String shardName : testEnv.shardKidMap.keySet()) {
      Util.insertRowsInShard(testEnv, shardName, rowCount);
    }
    String selectSql = "select A.* from vtgate_test A join vtgate_test B join vtgate_test C";
    Query query = new QueryBuilder(selectSql, testEnv.keyspace, "master")
        .setKeyspaceIds(testEnv.getAllKeyspaceIds()).setStreaming(true).build();
    VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);
    Cursor cursor = vtgate.execute(query);
    int count = 0;
    for (Row row : cursor) {
View Full Code Here

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

    vtgate.execute(getQuery(createTable));
    vtgate.commit();

    String insertSql =
        "insert into vtocc_ints values(:tiny, :tinyu, :small, :smallu, :medium, :mediumu, :normal, :normalu, :big, :bigu, :year)";
    Query insertQuery = new QueryBuilder(insertSql, testEnv.keyspace, "master")
        .addBindVar(BindVariable.forInt("tiny", -128))
        .addBindVar(BindVariable.forInt("tinyu", 255))
        .addBindVar(BindVariable.forInt("small", -32768))
        .addBindVar(BindVariable.forInt("smallu", 65535))
        .addBindVar(BindVariable.forInt("medium", -8388608))
        .addBindVar(BindVariable.forInt("mediumu", 16777215))
        .addBindVar(BindVariable.forLong("normal", -2147483648L))
        .addBindVar(BindVariable.forLong("normalu", 4294967295L))
        .addBindVar(BindVariable.forLong("big", -9223372036854775808L))
        .addBindVar(BindVariable.forULong("bigu", UnsignedLong.valueOf("18446744073709551615")))
        .addBindVar(BindVariable.forShort("year", (short) 2012))
        .addKeyRange(KeyRange.ALL)
        .build();
    vtgate.begin();
    vtgate.execute(insertQuery);
    vtgate.commit();

    String selectSql = "select * from vtocc_ints where tiny = -128";
    Query selectQuery =
        new QueryBuilder(selectSql, testEnv.keyspace, "master").addKeyRange(KeyRange.ALL).build();
    Cursor cursor = vtgate.execute(selectQuery);
    Assert.assertEquals(1, cursor.getRowsAffected());
    Row row = cursor.next();
    Assert.assertTrue(row.getInt("tiny").equals(-128));
    Assert.assertTrue(row.getInt("tinyu").equals(255));
View Full Code Here

    vtgate.begin();
    vtgate.execute(getQuery(createTable));
    vtgate.commit();

    String insertSql = "insert into vtocc_fracts values(:id, :deci, :num, :f, :d)";
    Query insertQuery = new QueryBuilder(insertSql, testEnv.keyspace, "master")
        .addBindVar(BindVariable.forInt("id", 1))
        .addBindVar(BindVariable.forDouble("deci", 1.99))
        .addBindVar(BindVariable.forDouble("num", 2.99))
        .addBindVar(BindVariable.forFloat("f", 3.99F))
        .addBindVar(BindVariable.forDouble("d", 4.99))
        .addKeyRange(KeyRange.ALL)
        .build();
    vtgate.begin();
    vtgate.execute(insertQuery);
    vtgate.commit();

    String selectSql = "select * from vtocc_fracts where id = 1";
    Query selectQuery =
        new QueryBuilder(selectSql, testEnv.keyspace, "master").addKeyRange(KeyRange.ALL).build();
    Cursor cursor = vtgate.execute(selectQuery);
    Assert.assertEquals(1, cursor.getRowsAffected());
    Row row = cursor.next();
    Assert.assertTrue(row.getLong("id").equals(1L));
    Assert.assertTrue(row.getBigDecimal("deci").equals(new BigDecimal("1.99")));
View Full Code Here

    vtgate.execute(getQuery(createTable));
    vtgate.commit();

    String insertSql =
        "insert into vtocc_strings values(:vb, :c, :vc, :b, :tb, :bl, :ttx, :tx, :en, :s)";
    Query insertQuery = new QueryBuilder(insertSql, testEnv.keyspace, "master")
        .addBindVar(BindVariable.forBytes("vb", "a".getBytes()))
        .addBindVar(BindVariable.forBytes("c", "b".getBytes()))
        .addBindVar(BindVariable.forBytes("vc", "c".getBytes()))
        .addBindVar(BindVariable.forBytes("b", "d".getBytes()))
        .addBindVar(BindVariable.forBytes("tb", "e".getBytes()))
        .addBindVar(BindVariable.forBytes("bl", "f".getBytes()))
        .addBindVar(BindVariable.forBytes("ttx", "g".getBytes()))
        .addBindVar(BindVariable.forBytes("tx", "h".getBytes()))
        .addBindVar(BindVariable.forString("en", "a"))
        .addBindVar(BindVariable.forString("s", "a,b"))
        .addKeyRange(KeyRange.ALL)
        .build();
    vtgate.begin();
    vtgate.execute(insertQuery);
    vtgate.commit();

    String selectSql = "select * from vtocc_strings where vb = 'a'";
    Query selectQuery =
        new QueryBuilder(selectSql, testEnv.keyspace, "master").addKeyRange(KeyRange.ALL).build();
    Cursor cursor = vtgate.execute(selectQuery);
    Assert.assertEquals(1, cursor.getRowsAffected());
    Row row = cursor.next();
    Assert.assertTrue(Arrays.equals(row.getBytes("vb"), "a".getBytes()));
    Assert.assertTrue(Arrays.equals(row.getBytes("c"), "b".getBytes()));
View Full Code Here

    vtgate.begin();
    vtgate.execute(getQuery(createTable));
    vtgate.commit();

    String insertSql = "insert into vtocc_misc values(:id, :b, :d, :dt, :t)";
    Query insertQuery = new QueryBuilder(insertSql, testEnv.keyspace, "master")
        .addBindVar(BindVariable.forInt("id", 1))
        .addBindVar(BindVariable.forBytes("b", ByteBuffer.allocate(1).put((byte) 1).array()))
        .addBindVar(BindVariable.forDate("d", DateTime.parse("2012-01-01")))
        .addBindVar(BindVariable.forDateTime("dt", DateTime.parse("2012-01-01T15:45:45")))
        .addBindVar(BindVariable.forTime("t",
            DateTime.parse("15:45:45", ISODateTimeFormat.timeElementParser())))
        .addKeyRange(KeyRange.ALL)
        .build();
    vtgate.begin();
    vtgate.execute(insertQuery);
    vtgate.commit();

    String selectSql = "select * from vtocc_misc where id = 1";
    Query selectQuery =
        new QueryBuilder(selectSql, testEnv.keyspace, "master").addKeyRange(KeyRange.ALL).build();
    Cursor cursor = vtgate.execute(selectQuery);
    Assert.assertEquals(1, cursor.getRowsAffected());
    Row row = cursor.next();
    Assert.assertTrue(row.getLong("id").equals(1L));
    Assert.assertTrue(
View Full Code Here

        DateTime.parse("15:45:45", ISODateTimeFormat.timeElementParser())));
    vtgate.close();
  }

  private Query getQuery(String sql) {
    return new QueryBuilder(sql, testEnv.keyspace, "master").addKeyRange(KeyRange.ALL).build();
  }
View Full Code Here

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

TOP

Related Classes of com.youtube.vitess.vtgate.Query.QueryBuilder

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.