Package com.facebook.thrift.transport

Examples of com.facebook.thrift.transport.TSocket


        databasename = parts[1];
        port = Integer.parseInt(hostport[1]);
      }
      catch (Exception e) {
      }
      TTransport transport = new TSocket(host, port);
      TProtocol protocol = new TBinaryProtocol(transport);
      client = new HiveClient(protocol);
      transport.open();
    }
  }
View Full Code Here


  }

  public void open(URI store) throws TException {
    this.open = false;
    if(store.getScheme().equals("thrift")) {
      transport = new TSocket(store.getHost(), store.getPort());
      ((TSocket)transport).setTimeout(2000);
      TProtocol protocol = new TBinaryProtocol(transport);
      client = new ThriftMetaStore.Client(protocol);

      for(int i = 0; i < retries && !this.open; ++i) {
View Full Code Here

  protected void setUp() throws Exception {
    super.setUp();
    if (standAloneServer) {
      try {
        transport = new TSocket(host, port);
        TProtocol protocol = new TBinaryProtocol(transport);
        client = new HiveClient(protocol);
        transport.open();
      }
      catch (Throwable e) {
View Full Code Here

    LOG.info("Connected to metastore.");
  }
  private void openStore(URI store) throws MetaException {
    open = false;
    transport = new TSocket(store.getHost(), store.getPort());
    ((TSocket)transport).setTimeout(20000);
    TProtocol protocol = new TBinaryProtocol(transport);
    client = new ThriftHiveMetastore.Client(protocol);

    for(int i = 0; i < retries && !this.open; ++i) {
View Full Code Here

    }
  }
 
  private void run() throws IOError, TException, NotFound, IllegalArgument,
      AlreadyExists {
    TTransport transport = new TSocket("localhost", port);
    TProtocol protocol = new TBinaryProtocol(transport, true, true);
    Hbase.Client client = new Hbase.Client(protocol);

    transport.open();

    byte[] t = bytes("demo_table");
   
    //
    // Scan all tables, look for the demo table and delete it.
    //
    System.out.println("scanning tables...");
    for (byte[] name : client.getTableNames()) {
      System.out.println("  found: " + utf8(name));
      if (utf8(name).equals(utf8(t))) {
        System.out.println("    deleting table: " + utf8(name))
        client.deleteTable(name);
      }
    }
   
    //
    // Create the demo table with two column families, entry: and unused:
    //
    ArrayList<ColumnDescriptor> columns = new ArrayList<ColumnDescriptor>();
    ColumnDescriptor col = null;
    col = new ColumnDescriptor();
    col.name = bytes("entry:");
    col.maxVersions = 10;
    columns.add(col);
    col = new ColumnDescriptor();
    col.name = bytes("unused:");
    columns.add(col);

    System.out.println("creating table: " + utf8(t));
    try {
      client.createTable(t, columns);
    } catch (AlreadyExists ae) {
      System.out.println("WARN: " + ae.message);
    }
   
    System.out.println("column families in " + utf8(t) + ": ");
    AbstractMap<byte[], ColumnDescriptor> columnMap = client.getColumnDescriptors(t);
    for (ColumnDescriptor col2 : columnMap.values()) {
      System.out.println("  column: " + utf8(col2.name) + ", maxVer: " + Integer.toString(col2.maxVersions));
    }
   
    //
    // Test UTF-8 handling
    //
    byte[] invalid = { (byte) 'f', (byte) 'o', (byte) 'o', (byte) '-', (byte) 0xfc, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1 };
    byte[] valid = { (byte) 'f', (byte) 'o', (byte) 'o', (byte) '-', (byte) 0xE7, (byte) 0x94, (byte) 0x9F, (byte) 0xE3, (byte) 0x83, (byte) 0x93, (byte) 0xE3, (byte) 0x83, (byte) 0xBC, (byte) 0xE3, (byte) 0x83, (byte) 0xAB};

    // non-utf8 is fine for data
    client.put(t, bytes("foo"), bytes("entry:foo"), invalid);

    // try empty strings
    client.put(t, bytes(""), bytes("entry:"), bytes(""));
   
    // this row name is valid utf8
    client.put(t, valid, bytes("entry:foo"), valid);
   
    // non-utf8 is not allowed in row names
    try {
      client.put(t, invalid, bytes("entry:foo"), invalid);
      System.out.println("FATAL: shouldn't get here");
      System.exit(-1);
    } catch (IOError e) {
      System.out.println("expected error: " + e.message);
    }
   
    // Run a scanner on the rows we just created
    ArrayList<byte[]> columnNames = new ArrayList<byte[]>();
    columnNames.add(bytes("entry:"));
   
    System.out.println("Starting scanner...");
    int scanner = client
        .scannerOpen(t, bytes(""), columnNames);
    try {
      while (true) {
        ScanEntry value = client.scannerGet(scanner);
        printEntry(value);
      }
    } catch (NotFound nf) {
      client.scannerClose(scanner);
      System.out.println("Scanner finished");
    }
   
    //
    // Run some operations on a bunch of rows
    //
    for (int i = 100; i >= 0; --i) {
      // format row keys as "00000" to "00100"
      NumberFormat nf = NumberFormat.getInstance();
      nf.setMinimumIntegerDigits(5);
      nf.setGroupingUsed(false);
      byte[] row = bytes(nf.format(i));
     
      client.put(t, row, bytes("unused:"), bytes("DELETE_ME"));
      printRow(row, client.getRow(t, row));
      client.deleteAllRow(t, row);

      client.put(t, row, bytes("entry:num"), bytes("0"));
      client.put(t, row, bytes("entry:foo"), bytes("FOO"));
      printRow(row, client.getRow(t, row));

      Mutation m = null;     
      ArrayList<Mutation> mutations = new ArrayList<Mutation>();
      m = new Mutation();
      m.column = bytes("entry:foo");
      m.isDelete = true;
      mutations.add(m);
      m = new Mutation();
      m.column = bytes("entry:num");
      m.value = bytes("-1");
      mutations.add(m);
      client.mutateRow(t, row, mutations);
      printRow(row, client.getRow(t, row));
     
      client.put(t, row, bytes("entry:num"), bytes(Integer.toString(i)));
      client.put(t, row, bytes("entry:sqr"), bytes(Integer.toString(i * i)));
      printRow(row, client.getRow(t, row));

      // sleep to force later timestamp
      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        // no-op
      }
     
      mutations.clear();
      m = new Mutation();
      m.column = bytes("entry:num");
      m.value = bytes("-999");
      mutations.add(m);
      m = new Mutation();
      m.column = bytes("entry:sqr");
      m.isDelete = true;
      client.mutateRowTs(t, row, mutations, 1); // shouldn't override latest
      printRow(row, client.getRow(t, row));

      ArrayList<byte[]> versions = client.getVer(t, row, bytes("entry:num"), 10);
      printVersions(row, versions);
      if (versions.size() != 4) {
        System.out.println("FATAL: wrong # of versions");
        System.exit(-1);
      }
     
      try {
        client.get(t, row, bytes("entry:foo"));
        System.out.println("FATAL: shouldn't get here");
        System.exit(-1);
      } catch (NotFound nf2) {
        // blank
      }

      System.out.println("");
    }
   
    // scan all rows/columnNames
   
    columnNames.clear();
    for (ColumnDescriptor col2 : client.getColumnDescriptors(t).values()) {
      columnNames.add(col2.name);
    }
   
    System.out.println("Starting scanner...");
    scanner = client.scannerOpenWithStop(t, bytes("00020"), bytes("00040"),
        columnNames);
    try {
      while (true) {
        ScanEntry value = client.scannerGet(scanner);
        printEntry(value);
      }
    } catch (NotFound nf) {
      client.scannerClose(scanner);
      System.out.println("Scanner finished");
    }
   
    transport.close();
  }
View Full Code Here

  }
 
  private void run() throws IOError, TException, NotFound, IllegalArgument,
      AlreadyExists {
   
    TTransport transport = new TSocket("localhost", port);
    TProtocol protocol = new TBinaryProtocol(transport, true, true);
    Hbase.Client client = new Hbase.Client(protocol);

    transport.open();

    byte[] t = bytes("demo_table");
   
    //
    // Scan all tables, look for the demo table and delete it.
    //
    System.out.println("scanning tables...");
    for (byte[] name : client.getTableNames()) {
      System.out.println("  found: " + utf8(name));
      if (utf8(name).equals(utf8(t))) {
        System.out.println("    disabling table: " + utf8(name));
        if (client.isTableEnabled(name))
          client.disableTable(name);
        System.out.println("    deleting table: " + utf8(name));
        client.deleteTable(name);
      }
    }
   
    //
    // Create the demo table with two column families, entry: and unused:
    //
    ArrayList<ColumnDescriptor> columns = new ArrayList<ColumnDescriptor>();
    ColumnDescriptor col = null;
    col = new ColumnDescriptor();
    col.name = bytes("entry:");
    col.maxVersions = 10;
    columns.add(col);
    col = new ColumnDescriptor();
    col.name = bytes("unused:");
    columns.add(col);

    System.out.println("creating table: " + utf8(t));
    try {
      client.createTable(t, columns);
    } catch (AlreadyExists ae) {
      System.out.println("WARN: " + ae.message);
    }
   
    System.out.println("column families in " + utf8(t) + ": ");
    Map<byte[], ColumnDescriptor> columnMap = client.getColumnDescriptors(t);
    for (ColumnDescriptor col2 : columnMap.values()) {
      System.out.println("  column: " + utf8(col2.name) + ", maxVer: " + Integer.toString(col2.maxVersions));
    }
   
    //
    // Test UTF-8 handling
    //
    byte[] invalid = { (byte) 'f', (byte) 'o', (byte) 'o', (byte) '-', (byte) 0xfc, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1 };
    byte[] valid = { (byte) 'f', (byte) 'o', (byte) 'o', (byte) '-', (byte) 0xE7, (byte) 0x94, (byte) 0x9F, (byte) 0xE3, (byte) 0x83, (byte) 0x93, (byte) 0xE3, (byte) 0x83, (byte) 0xBC, (byte) 0xE3, (byte) 0x83, (byte) 0xAB};

    ArrayList<Mutation> mutations;
    // non-utf8 is fine for data
    mutations = new ArrayList<Mutation>();
    mutations.add(new Mutation(false, bytes("entry:foo"), invalid));
    client.mutateRow(t, bytes("foo"), mutations);

    // try empty strings
    mutations = new ArrayList<Mutation>();
    mutations.add(new Mutation(false, bytes("entry:"), bytes("")));
    client.mutateRow(t, bytes(""), mutations);

    // this row name is valid utf8
    mutations = new ArrayList<Mutation>();
    mutations.add(new Mutation(false, bytes("entry:foo"), valid));
    client.mutateRow(t, bytes("foo"), mutations);
   
    // non-utf8 is not allowed in row names
    try {
      mutations = new ArrayList<Mutation>();
      mutations.add(new Mutation(false, bytes("entry:foo"), invalid));
      client.mutateRow(t, invalid, mutations);
      System.out.println("FATAL: shouldn't get here");
      System.exit(-1);
    } catch (IOError e) {
      System.out.println("expected error: " + e.message);
    }
   
    // Run a scanner on the rows we just created
    ArrayList<byte[]> columnNames = new ArrayList<byte[]>();
    columnNames.add(bytes("entry:"));
   
    System.out.println("Starting scanner...");
    int scanner = client.scannerOpen(t, bytes(""), columnNames);
    try {
      while (true) {
        TRowResult entry = client.scannerGet(scanner);
        printRow(entry);
      }
    } catch (NotFound nf) {
      client.scannerClose(scanner);
      System.out.println("Scanner finished");
    }
   
    //
    // Run some operations on a bunch of rows
    //
    for (int i = 100; i >= 0; --i) {
      // format row keys as "00000" to "00100"
      NumberFormat nf = NumberFormat.getInstance();
      nf.setMinimumIntegerDigits(5);
      nf.setGroupingUsed(false);
      byte[] row = bytes(nf.format(i));
     
      mutations = new ArrayList<Mutation>();
      mutations.add(new Mutation(false, bytes("unused:"), bytes("DELETE_ME")));
      client.mutateRow(t, row, mutations);
      printRow(client.getRow(t, row));
      client.deleteAllRow(t, row);

      mutations = new ArrayList<Mutation>();
      mutations.add(new Mutation(false, bytes("entry:num"), bytes("0")));
      mutations.add(new Mutation(false, bytes("entry:foo"), bytes("FOO")));
      client.mutateRow(t, row, mutations);
      printRow(client.getRow(t, row));

      Mutation m = null;
      mutations = new ArrayList<Mutation>();
      m = new Mutation();
      m.column = bytes("entry:foo");
      m.isDelete = true;
      mutations.add(m);
      m = new Mutation();
      m.column = bytes("entry:num");
      m.value = bytes("-1");
      mutations.add(m);
      client.mutateRow(t, row, mutations);
      printRow(client.getRow(t, row));
     
      mutations = new ArrayList<Mutation>();
      mutations.add(new Mutation(false, bytes("entry:num"), bytes(Integer.toString(i))));
      mutations.add(new Mutation(false, bytes("entry:sqr"), bytes(Integer.toString(i * i))));
      client.mutateRow(t, row, mutations);
      printRow(client.getRow(t, row));

      // sleep to force later timestamp
      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        // no-op
      }
     
      mutations.clear();
      m = new Mutation();
      m.column = bytes("entry:num");
      m.value = bytes("-999");
      mutations.add(m);
      m = new Mutation();
      m.column = bytes("entry:sqr");
      m.isDelete = true;
      client.mutateRowTs(t, row, mutations, 1); // shouldn't override latest
      printRow(client.getRow(t, row));

      List<TCell> versions = client.getVer(t, row, bytes("entry:num"), 10);
      printVersions(row, versions);
      if (versions.size() != 4) {
        System.out.println("FATAL: wrong # of versions");
        System.exit(-1);
      }
     
      try {
        client.get(t, row, bytes("entry:foo"));
        System.out.println("FATAL: shouldn't get here");
        System.exit(-1);
      } catch (NotFound nf2) {
        // blank
      }

      System.out.println("");
    }
   
    // scan all rows/columnNames
   
    columnNames.clear();
    for (ColumnDescriptor col2 : client.getColumnDescriptors(t).values()) {
      System.out.println("column name is " + new String(col2.name));
      System.out.println(col2.toString());
      columnNames.add((utf8(col2.name) + ":").getBytes());
    }
   
    System.out.println("Starting scanner...");
    scanner = client.scannerOpenWithStop(t, bytes("00020"), bytes("00040"),
        columnNames);
    try {
      while (true) {
        TRowResult entry = client.scannerGet(scanner);
        printRow(entry);
      }
    } catch (NotFound nf) {
      client.scannerClose(scanner);
      System.out.println("Scanner finished");
    }
   
    transport.close();
  }
View Full Code Here

  }

  public void open(URI store) throws TException {
    this.open = false;
    if(store.getScheme().equals("thrift")) {
      transport = new TSocket(store.getHost(), store.getPort());
      ((TSocket)transport).setTimeout(2000);
      TProtocol protocol = new TBinaryProtocol(transport);
      client = new ThriftMetaStore.Client(protocol);

      for(int i = 0; i < retries && !this.open; ++i) {
View Full Code Here

    LOG.info("Connected to metastore.");
  }
  private void openStore(URI store) throws MetaException {
    open = false;
    transport = new TSocket(store.getHost(), store.getPort());
    ((TSocket)transport).setTimeout(20000);
    TProtocol protocol = new TBinaryProtocol(transport);
    client = new ThriftHiveMetastore.Client(protocol);

    for(int i = 0; i < retries && !this.open; ++i) {
View Full Code Here

    }
  }
 
  private void run() throws IOError, TException, NotFound, IllegalArgument,
      AlreadyExists {
    TTransport transport = new TSocket("localhost", port);
    TProtocol protocol = new TBinaryProtocol(transport, true, true);
    Hbase.Client client = new Hbase.Client(protocol);

    transport.open();

    byte[] t = bytes("demo_table");
   
    //
    // Scan all tables, look for the demo table and delete it.
    //
    System.out.println("scanning tables...");
    for (byte[] name : client.getTableNames()) {
      System.out.println("  found: " + utf8(name));
      if (utf8(name).equals(utf8(t))) {
        System.out.println("    deleting table: " + utf8(name))
        client.deleteTable(name);
      }
    }
   
    //
    // Create the demo table with two column families, entry: and unused:
    //
    ArrayList<ColumnDescriptor> columns = new ArrayList<ColumnDescriptor>();
    ColumnDescriptor col = null;
    col = new ColumnDescriptor();
    col.name = bytes("entry:");
    col.maxVersions = 10;
    columns.add(col);
    col = new ColumnDescriptor();
    col.name = bytes("unused:");
    columns.add(col);

    System.out.println("creating table: " + utf8(t));
    try {
      client.createTable(t, columns);
    } catch (AlreadyExists ae) {
      System.out.println("WARN: " + ae.message);
    }
   
    System.out.println("column families in " + utf8(t) + ": ");
    AbstractMap<byte[], ColumnDescriptor> columnMap = client.getColumnDescriptors(t);
    for (ColumnDescriptor col2 : columnMap.values()) {
      System.out.println("  column: " + utf8(col2.name) + ", maxVer: " + Integer.toString(col2.maxVersions));
    }
   
    //
    // Test UTF-8 handling
    //
    byte[] invalid = { (byte) 'f', (byte) 'o', (byte) 'o', (byte) '-', (byte) 0xfc, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1 };
    byte[] valid = { (byte) 'f', (byte) 'o', (byte) 'o', (byte) '-', (byte) 0xE7, (byte) 0x94, (byte) 0x9F, (byte) 0xE3, (byte) 0x83, (byte) 0x93, (byte) 0xE3, (byte) 0x83, (byte) 0xBC, (byte) 0xE3, (byte) 0x83, (byte) 0xAB};

    // non-utf8 is fine for data
    client.put(t, bytes("foo"), bytes("entry:foo"), invalid);

    // try empty strings
    client.put(t, bytes(""), bytes("entry:"), bytes(""));
   
    // this row name is valid utf8
    client.put(t, valid, bytes("entry:foo"), valid);
   
    // non-utf8 is not allowed in row names
    try {
      client.put(t, invalid, bytes("entry:foo"), invalid);
      System.out.println("FATAL: shouldn't get here");
      System.exit(-1);
    } catch (IOError e) {
      System.out.println("expected error: " + e.message);
    }
   
    // Run a scanner on the rows we just created
    ArrayList<byte[]> columnNames = new ArrayList<byte[]>();
    columnNames.add(bytes("entry:"));
   
    System.out.println("Starting scanner...");
    int scanner = client
        .scannerOpen(t, bytes(""), columnNames);
    try {
      while (true) {
        ScanEntry value = client.scannerGet(scanner);
        printEntry(value);
      }
    } catch (NotFound nf) {
      client.scannerClose(scanner);
      System.out.println("Scanner finished");
    }
   
    //
    // Run some operations on a bunch of rows
    //
    for (int i = 100; i >= 0; --i) {
      // format row keys as "00000" to "00100"
      NumberFormat nf = NumberFormat.getInstance();
      nf.setMinimumIntegerDigits(5);
      nf.setGroupingUsed(false);
      byte[] row = bytes(nf.format(i));
     
      client.put(t, row, bytes("unused:"), bytes("DELETE_ME"));
      printRow(row, client.getRow(t, row));
      client.deleteAllRow(t, row);

      client.put(t, row, bytes("entry:num"), bytes("0"));
      client.put(t, row, bytes("entry:foo"), bytes("FOO"));
      printRow(row, client.getRow(t, row));

      Mutation m = null;     
      ArrayList<Mutation> mutations = new ArrayList<Mutation>();
      m = new Mutation();
      m.column = bytes("entry:foo");
      m.isDelete = true;
      mutations.add(m);
      m = new Mutation();
      m.column = bytes("entry:num");
      m.value = bytes("-1");
      mutations.add(m);
      client.mutateRow(t, row, mutations);
      printRow(row, client.getRow(t, row));
     
      client.put(t, row, bytes("entry:num"), bytes(Integer.toString(i)));
      client.put(t, row, bytes("entry:sqr"), bytes(Integer.toString(i * i)));
      printRow(row, client.getRow(t, row));

      // sleep to force later timestamp
      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        // no-op
      }
     
      mutations.clear();
      m = new Mutation();
      m.column = bytes("entry:num");
      m.value = bytes("-999");
      mutations.add(m);
      m = new Mutation();
      m.column = bytes("entry:sqr");
      m.isDelete = true;
      client.mutateRowTs(t, row, mutations, 1); // shouldn't override latest
      printRow(row, client.getRow(t, row));

      ArrayList<byte[]> versions = client.getVer(t, row, bytes("entry:num"), 10);
      printVersions(row, versions);
      if (versions.size() != 4) {
        System.out.println("FATAL: wrong # of versions");
        System.exit(-1);
      }
     
      try {
        client.get(t, row, bytes("entry:foo"));
        System.out.println("FATAL: shouldn't get here");
        System.exit(-1);
      } catch (NotFound nf2) {
        // blank
      }

      System.out.println("");
    }
   
    // scan all rows/columnNames
   
    columnNames.clear();
    for (ColumnDescriptor col2 : client.getColumnDescriptors(t).values()) {
      columnNames.add(col2.name);
    }
   
    System.out.println("Starting scanner...");
    scanner = client.scannerOpenWithStop(t, bytes("00020"), bytes("00040"),
        columnNames);
    try {
      while (true) {
        ScanEntry value = client.scannerGet(scanner);
        printEntry(value);
      }
    } catch (NotFound nf) {
      client.scannerClose(scanner);
      System.out.println("Scanner finished");
    }
   
    transport.close();
  }
View Full Code Here

  }
 
  private void run() throws IOError, TException, NotFound, IllegalArgument,
      AlreadyExists {
   
    TTransport transport = new TSocket("localhost", port);
    TProtocol protocol = new TBinaryProtocol(transport, true, true);
    Hbase.Client client = new Hbase.Client(protocol);

    transport.open();

    byte[] t = bytes("demo_table");
   
    //
    // Scan all tables, look for the demo table and delete it.
    //
    System.out.println("scanning tables...");
    for (byte[] name : client.getTableNames()) {
      System.out.println("  found: " + utf8(name));
      if (utf8(name).equals(utf8(t))) {
        if (client.isTableEnabled(name)) {
          System.out.println("    disabling table: " + utf8(name));
          client.disableTable(name);
        }
        System.out.println("    deleting table: " + utf8(name));
        client.deleteTable(name);
      }
    }
   
    //
    // Create the demo table with two column families, entry: and unused:
    //
    ArrayList<ColumnDescriptor> columns = new ArrayList<ColumnDescriptor>();
    ColumnDescriptor col = null;
    col = new ColumnDescriptor();
    col.name = bytes("entry:");
    col.maxVersions = 10;
    columns.add(col);
    col = new ColumnDescriptor();
    col.name = bytes("unused:");
    columns.add(col);

    System.out.println("creating table: " + utf8(t));
    try {
      client.createTable(t, columns);
    } catch (AlreadyExists ae) {
      System.out.println("WARN: " + ae.message);
    }
   
    System.out.println("column families in " + utf8(t) + ": ");
    Map<byte[], ColumnDescriptor> columnMap = client.getColumnDescriptors(t);
    for (ColumnDescriptor col2 : columnMap.values()) {
      System.out.println("  column: " + utf8(col2.name) + ", maxVer: " + Integer.toString(col2.maxVersions));
    }
   
    //
    // Test UTF-8 handling
    //
    byte[] invalid = { (byte) 'f', (byte) 'o', (byte) 'o', (byte) '-', (byte) 0xfc, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1 };
    byte[] valid = { (byte) 'f', (byte) 'o', (byte) 'o', (byte) '-', (byte) 0xE7, (byte) 0x94, (byte) 0x9F, (byte) 0xE3, (byte) 0x83, (byte) 0x93, (byte) 0xE3, (byte) 0x83, (byte) 0xBC, (byte) 0xE3, (byte) 0x83, (byte) 0xAB};

    ArrayList<Mutation> mutations;
    // non-utf8 is fine for data
    mutations = new ArrayList<Mutation>();
    mutations.add(new Mutation(false, bytes("entry:foo"), invalid));
    client.mutateRow(t, bytes("foo"), mutations);

    // try empty strings
    mutations = new ArrayList<Mutation>();
    mutations.add(new Mutation(false, bytes("entry:"), bytes("")));
    client.mutateRow(t, bytes(""), mutations);

    // this row name is valid utf8
    mutations = new ArrayList<Mutation>();
    mutations.add(new Mutation(false, bytes("entry:foo"), valid));
    client.mutateRow(t, valid, mutations);
   
    // non-utf8 is not allowed in row names
    try {
      mutations = new ArrayList<Mutation>();
      mutations.add(new Mutation(false, bytes("entry:foo"), invalid));
      client.mutateRow(t, invalid, mutations);
      System.out.println("FATAL: shouldn't get here");
      System.exit(-1);
    } catch (IOError e) {
      System.out.println("expected error: " + e.message);
    }
   
    // Run a scanner on the rows we just created
    ArrayList<byte[]> columnNames = new ArrayList<byte[]>();
    columnNames.add(bytes("entry:"));
   
    System.out.println("Starting scanner...");
    int scanner = client.scannerOpen(t, bytes(""), columnNames);
    try {
      while (true) {
        TRowResult entry = client.scannerGet(scanner);
        printRow(entry);
      }
    } catch (NotFound nf) {
      client.scannerClose(scanner);
      System.out.println("Scanner finished");
    }
   
    //
    // Run some operations on a bunch of rows
    //
    for (int i = 100; i >= 0; --i) {
      // format row keys as "00000" to "00100"
      NumberFormat nf = NumberFormat.getInstance();
      nf.setMinimumIntegerDigits(5);
      nf.setGroupingUsed(false);
      byte[] row = bytes(nf.format(i));
     
      mutations = new ArrayList<Mutation>();
      mutations.add(new Mutation(false, bytes("unused:"), bytes("DELETE_ME")));
      client.mutateRow(t, row, mutations);
      printRow(client.getRow(t, row));
      client.deleteAllRow(t, row);

      mutations = new ArrayList<Mutation>();
      mutations.add(new Mutation(false, bytes("entry:num"), bytes("0")));
      mutations.add(new Mutation(false, bytes("entry:foo"), bytes("FOO")));
      client.mutateRow(t, row, mutations);
      printRow(client.getRow(t, row));

      Mutation m = null;
      mutations = new ArrayList<Mutation>();
      m = new Mutation();
      m.column = bytes("entry:foo");
      m.isDelete = true;
      mutations.add(m);
      m = new Mutation();
      m.column = bytes("entry:num");
      m.value = bytes("-1");
      mutations.add(m);
      client.mutateRow(t, row, mutations);
      printRow(client.getRow(t, row));
     
      mutations = new ArrayList<Mutation>();
      mutations.add(new Mutation(false, bytes("entry:num"), bytes(Integer.toString(i))));
      mutations.add(new Mutation(false, bytes("entry:sqr"), bytes(Integer.toString(i * i))));
      client.mutateRow(t, row, mutations);
      printRow(client.getRow(t, row));

      // sleep to force later timestamp
      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        // no-op
      }
     
      mutations.clear();
      m = new Mutation();
      m.column = bytes("entry:num");
      m.value = bytes("-999");
      mutations.add(m);
      m = new Mutation();
      m.column = bytes("entry:sqr");
      m.isDelete = true;
      client.mutateRowTs(t, row, mutations, 1); // shouldn't override latest
      printRow(client.getRow(t, row));

      List<TCell> versions = client.getVer(t, row, bytes("entry:num"), 10);
      printVersions(row, versions);
      if (versions.size() != 4) {
        System.out.println("FATAL: wrong # of versions");
        System.exit(-1);
      }
     
      try {
        client.get(t, row, bytes("entry:foo"));
        System.out.println("FATAL: shouldn't get here");
        System.exit(-1);
      } catch (NotFound nf2) {
        // blank
      }

      System.out.println("");
    }
   
    // scan all rows/columnNames
   
    columnNames.clear();
    for (ColumnDescriptor col2 : client.getColumnDescriptors(t).values()) {
      System.out.println("column with name: " + new String(col2.name));
      System.out.println(col2.toString());
      columnNames.add((utf8(col2.name) + ":").getBytes());
    }
   
    System.out.println("Starting scanner...");
    scanner = client.scannerOpenWithStop(t, bytes("00020"), bytes("00040"),
        columnNames);
    try {
      while (true) {
        TRowResult entry = client.scannerGet(scanner);
        printRow(entry);
      }
    } catch (NotFound nf) {
      client.scannerClose(scanner);
      System.out.println("Scanner finished");
    }
   
    transport.close();
  }
View Full Code Here

TOP

Related Classes of com.facebook.thrift.transport.TSocket

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.