Package com.youtube.vitess.vtgate

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


    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));
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));
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()));
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));
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

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

  public void testExecuteKeyspaceIds() throws Exception {
    VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);

    // Ensure empty table
    String selectSql = "select * from vtgate_test";
    Query allRowsQuery = new QueryBuilder(selectSql, testEnv.keyspace, "master").setKeyspaceIds(
        testEnv.getAllKeyspaceIds()).build();
    Cursor cursor = vtgate.execute(allRowsQuery);
    Assert.assertEquals(CursorImpl.class, cursor.getClass());
    Assert.assertEquals(0, cursor.getRowsAffected());
    Assert.assertEquals(0, cursor.getLastRowId());
    Assert.assertFalse(cursor.hasNext());
    vtgate.close();

    // Insert 10 rows
    Util.insertRows(testEnv, 1000, 10);

    vtgate = VtGate.connect("localhost:" + testEnv.port, 0);
    cursor = vtgate.execute(allRowsQuery);
    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
    Row row = cursor.next();
View Full Code Here

    VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);
    String allRowsSql = "select * from vtgate_test";

    for (String shardName : testEnv.shardKidMap.keySet()) {
      Query shardRows = new QueryBuilder(allRowsSql, testEnv.keyspace, "master").setKeyspaceIds(
          testEnv.getKeyspaceIds(shardName)).build();
      Cursor cursor = vtgate.execute(shardRows);
      Assert.assertEquals(10, cursor.getRowsAffected());
    }
    vtgate.close();
View Full Code Here

  @Test
  public void testDateFieldTypes() throws Exception {
    DateTime dt = DateTime.now().minusDays(2).withMillisOfSecond(0);
    Util.insertRows(testEnv, 10, 1, dt);
    VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);
    Query allRowsQuery = new QueryBuilder("select * from vtgate_test", testEnv.keyspace, "master")
        .setKeyspaceIds(testEnv.getAllKeyspaceIds()).build();
    Row row = vtgate.execute(allRowsQuery).next();
    Assert.assertTrue(dt.equals(row.getDateTime("timestamp_col")));
    Assert.assertTrue(dt.equals(row.getDateTime("datetime_col")));
    Assert.assertTrue(dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0)
View Full Code Here

  public void testAllKeyRange() throws Exception {
    // Insert 10 rows across the shards
    Util.insertRows(testEnv, 1000, 10);
    VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);
    String selectSql = "select * from vtgate_test";
    Query allRowsQuery =
        new QueryBuilder(selectSql, testEnv.keyspace, "master").addKeyRange(KeyRange.ALL).build();
    Cursor cursor = vtgate.execute(allRowsQuery);
    // Verify all rows returned
    Assert.assertEquals(10, cursor.getRowsAffected());
    vtgate.close();
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.