Package com.youtube.vitess.vtgate.Query

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


        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();
      long size = (long) splitObj.get("Size");
      queries.put(q, size);
    }
    return new SplitQueryResponse(queries, error);
View Full Code Here


public class QueryBuilderTest {
  @Test
  public void testValidQueryWithKeyspaceIds() {
    String sql = "select 1 from dual";
    KeyspaceId kid = KeyspaceId.valueOf("80");
    QueryBuilder builder =
        new QueryBuilder("select 1 from dual", "test_keyspace", "master").addKeyspaceId(kid);
    Query query = builder.build();
    Assert.assertEquals(sql, query.getSql());
    Assert.assertEquals("test_keyspace", query.getKeyspace());
    Assert.assertEquals("master", query.getTabletType());
    Assert.assertEquals(null, query.getBindVars());
    Assert.assertEquals(1, query.getKeyspaceIds().size());
View Full Code Here

  }

  @Test
  public void testValidQueryWithKeyRanges() {
    String sql = "select 1 from dual";
    QueryBuilder builder =
        new QueryBuilder("select 1 from dual", "test_keyspace", "master").addKeyRange(KeyRange.ALL);
    Query query = builder.build();
    Assert.assertEquals(sql, query.getSql());
    Assert.assertEquals("test_keyspace", query.getKeyspace());
    Assert.assertEquals("master", query.getTabletType());
    Assert.assertEquals(null, query.getBindVars());
    Assert.assertEquals(1, query.getKeyRanges().size());
View Full Code Here

    Assert.assertEquals(null, query.getKeyspaceIds());
  }

  @Test
  public void testNoKeyspaceIdOrKeyrange() {
    QueryBuilder builder = new QueryBuilder("select 1 from dual", "test_keyspace", "master");
    try {
      builder.build();
      Assert.fail("did not raise IllegalStateException");
    } catch (IllegalStateException e) {
      Assert.assertEquals("query must have either keyspaceIds or keyRanges", e.getMessage());
    }
  }
View Full Code Here

    }
  }

  @Test
  public void testBothKeyspaceIdAndKeyrange() {
    QueryBuilder builder = new QueryBuilder("select 1 from dual", "test_keyspace", "master")
        .addKeyRange(KeyRange.ALL).addKeyspaceId(KeyspaceId.valueOf("80"));
    try {
      builder.build();
      Assert.fail("did not raise IllegalStateException");
    } catch (IllegalStateException e) {
      Assert.assertEquals("query cannot have both keyspaceIds and keyRanges", e.getMessage());
    }
  }
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);
View Full Code Here

  @Test
  public void testTimeout() throws ConnectionException, DatabaseException {
    VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 200);
    // Check timeout error raised for slow query
    Query sleepQuery = new QueryBuilder("select sleep(0.5) from dual", testEnv.keyspace, "master")
        .setKeyspaceIds(testEnv.getAllKeyspaceIds()).build();
    try {
      vtgate.execute(sleepQuery);
      Assert.fail("did not raise timeout exception");
    } catch (ConnectionException e) {
    }
    vtgate.close();
    vtgate = VtGate.connect("localhost:" + testEnv.port, 2000);
    // Check no timeout error for fast query
    sleepQuery = new QueryBuilder("select sleep(0.01) from dual", testEnv.keyspace, "master")
        .setKeyspaceIds(testEnv.getAllKeyspaceIds()).build();
    vtgate.execute(sleepQuery);
    vtgate.close();
  }
View Full Code Here

      for (int i = 0; i < 25; i++) {
        VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);
        vtgates.add(vtgate);
        vtgate.begin();
        // Run a query to actually begin a transaction with the tablets
        Query query = new QueryBuilder("delete from vtgate_test", testEnv.keyspace, "master")
            .addKeyRange(KeyRange.ALL).build();
        vtgate.execute(query);
      }
    } catch (DatabaseException e) {
      if (e.getMessage().contains("tx_pool_full")) {
View Full Code Here

  @Test
  public void testShutdownServerWhileStreaming() throws Exception {
    Util.insertRows(testEnv, 1, 2000);
    VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);
    String selectSql = "select A.* from vtgate_test A join vtgate_test B";
    Query joinQuery = new QueryBuilder(selectSql, testEnv.keyspace, "master")
        .setKeyspaceIds(testEnv.getAllKeyspaceIds()).setStreaming(true).build();
    Cursor cursor = vtgate.execute(joinQuery);

    int count = 0;
    try {
View Full Code Here

  @Test
  public void testStreamCursorType() throws Exception {
    VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);
    String selectSql = "select * from vtgate_test";
    Query allRowsQuery = new QueryBuilder(selectSql, testEnv.keyspace, "master")
        .setKeyspaceIds(testEnv.getAllKeyspaceIds()).setStreaming(true).build();
    Cursor cursor = vtgate.execute(allRowsQuery);
    Assert.assertEquals(StreamCursor.class, cursor.getClass());
    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.