コード例 #1
0
ファイル: HBaseDeamon.cpp プロジェクト: korechika/Deamon
static void
createTableFunc(std::string t, HbaseClient client)
{
    // Create the demo table with two column families, entry: and unused:
    ColVec columns;
    columns.push_back(ColumnDescriptor());
    columns.back().name = "entry:";
    columns.back().maxVersions = 10;
    columns.push_back(ColumnDescriptor());
    columns.back().name = "unused:";

    std::cout << "creating table: " << t << std::endl;
    try {
      // テーブル t の作成, カラムは上で作成
      client.createTable(t, columns);
    } catch (const AlreadyExists &ae) {
      std::cerr << "WARN: " << ae.message << std::endl;
    }
}
コード例 #2
0
ファイル: gnc-address-sql.cpp プロジェクト: Bob-IT/gnucash
template<> void
GncSqlColumnTableEntryImpl<CT_ADDRESS>::add_to_table(ColVec& vec) const noexcept
{
    for (auto const& subtable_row : col_table)
    {
        auto buf = std::string{m_col_name} + "_" + subtable_row->m_col_name;
        GncSqlColumnInfo info(buf.c_str(), BCT_STRING, subtable_row->m_size,
                              true, false, m_flags & COL_PKEY, m_flags & COL_NNUL);
        vec.emplace_back(std::move(info));
    }
}
コード例 #3
0
ファイル: testput.cpp プロジェクト: bbfoot/hbase-thrift
int main(int argc, char** argv) {
  if (argc < 6) {
    std::cerr << "Invalid arguments!\n" << "Usage: testput host port key_len val_len list_num" << std::endl;
    return -1;
  }
  HbCli myhbcli(argv[1], argv[2]);
 
  myhbcli.connect();
   
  std::string table("test_table");
  ColVec columns;
  columns.push_back(ColumnDescriptor());
  columns.back().name = "entry:";
  columns.back().maxVersions = 1;
  columns.back().compression = "LZO";
  columns.back().inMemory = true;
  columns.back().blockCacheEnabled = true;
  columns.back().bloomFilterType = "ROW";
  columns.back().timeToLive = 3 * 24 * 3600;
  if (!myhbcli.tableExists(table))
    myhbcli.createTable(table, columns);
 
  int klen = atoi(argv[3]);
  int vlen = atoi(argv[4]);
  int lnum = atoi(argv[5]);
  long actual_ms = 0;
  struct timeval tvstart, tvend;
  gettimeofday(&tvstart, NULL);
  if (lnum == 1)
    actual_ms = test_row_put(myhbcli, table, klen, vlen);
  else
    actual_ms = test_row_put_list(myhbcli, table, klen, vlen, lnum);
  gettimeofday(&tvend, NULL);
  long total_ms = gen_ms(tvstart, tvend);
  std::cout << "total time in ms: " << total_ms << std::endl;
  std::cout << "actual time in ms: " << actual_ms << std::endl;
  std::cout << "qps in total time: " << (long)(COUNT*1000)/total_ms << std::endl;
  std::cout << "qps in actual time: " << (long)(COUNT*1000)/actual_ms << std::endl;
  
  myhbcli.deleteTable(table);
  
  myhbcli.disconnect();
}
コード例 #4
0
ファイル: createdata.cpp プロジェクト: gbc0224/nprobe
extern "C" int test_table()
{
    char buf[8][1024];
    int i;
    bool isFramed = false;
    bool tmptable = false;
    boost::shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
    boost::shared_ptr<TTransport> transport;
    if (isFramed)
    {
        transport.reset(new TFramedTransport(socket));
    }
    else
    {
        transport.reset(new TBufferedTransport(socket));
    }
    boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));

    const std::map<Text, Text>  dummyAttributes; // see HBASE-6806 HBASE-4658
    HbaseClient client(protocol);
    try
    {
        transport->open();
        std::string t[]= {"T1","T2","T3","T4","T5","T6","T7","T8"};
        StrVec tables;
        client.getTableNames(tables);

        for(i=0; i<8; i++)
        {
            tmptable = false;
            StrVec::const_iterator it = tables.begin();
            for (StrVec::const_iterator it = tables.begin(); it != tables.end(); ++it)
            {
                if (t[i] == *it)
                {
                    tmptable = true;
                }
            }
            if(!tmptable)//创建表
            {
                ColVec columns;
                columns.push_back(ColumnDescriptor());
                columns.back().name = "PROTOCOL";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "INPUT_SNMP";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "OUTPUT_SNMP";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "IN_PKTS";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "IN_BYTES";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "SRC_TOS";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "SRC_AS";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "DST_AS";
                columns.push_back(ColumnDescriptor());
                columns.back().name = "TCP_FLAGS";
                std::cout << "creating table: " << t[i] << std::endl;
                try
                {
                    client.createTable(t[i], columns);
                }
                catch (const AlreadyExists &ae)
                {
                    std::cerr << "WARN: " << ae.message << std::endl;
                }
            }
        }
    }
    catch (const TException &tx)
    {
        std::cerr << "ERROR: " << tx.what() << std::endl;
    }
    return 0;
}
コード例 #5
0
ファイル: DemoClient.cpp プロジェクト: wanji/dicaf
int 
main(int argc, char** argv) 
{
  if (argc < 3) {
    std::cerr << "Invalid arguments!\n" << "Usage: DemoClient host port" << std::endl;
    return -1;
  }

  boost::shared_ptr<TTransport> socket(new TSocket(argv[1], boost::lexical_cast<int>(argv[2])));
  boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
  boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
  HbaseClient client(protocol);

  try {
    transport->open();

    std::string t("demo_table");

    //
    // Scan all tables, look for the demo table and delete it.
    //
    std::cout << "scanning tables..." << std::endl;
    StrVec tables;
    client.getTableNames(tables);
    for (StrVec::const_iterator it = tables.begin(); it != tables.end(); ++it) {
      std::cout << "  found: " << *it << std::endl;
      if (t == *it) {
        if (client.isTableEnabled(*it)) {
          std::cout << "    disabling table: " << *it << std::endl;
          client.disableTable(*it);
        }
        std::cout << "    deleting table: " << *it << std::endl;
        client.deleteTable(*it);
      }
    }

    //
    // Create the demo table with two column families, entry: and unused:
    //
    ColVec columns;
    columns.push_back(ColumnDescriptor());
    columns.back().name = "entry:";
    columns.back().maxVersions = 10;
    columns.push_back(ColumnDescriptor());
    columns.back().name = "unused:";

    std::cout << "creating table: " << t << std::endl;
    try {
      client.createTable(t, columns);
    } catch (const AlreadyExists &ae) {
      std::cerr << "WARN: " << ae.message << std::endl;
    }

    ColMap columnMap;
    client.getColumnDescriptors(columnMap, t);
    std::cout << "column families in " << t << ": " << std::endl;
    for (ColMap::const_iterator it = columnMap.begin(); it != columnMap.end(); ++it) {
      std::cout << "  column: " << it->second.name << ", maxVer: " << it->second.maxVersions << std::endl;
    }

    //
    // Test UTF-8 handling
    //
    std::string invalid("foo-\xfc\xa1\xa1\xa1\xa1\xa1");
    std::string valid("foo-\xE7\x94\x9F\xE3\x83\x93\xE3\x83\xBC\xE3\x83\xAB");
    std::map<std::string, std::string> attrs;

    // non-utf8 is fine for data
    std::vector<Mutation> mutations;
    mutations.push_back(Mutation());
    mutations.back().column = "entry:foo";
    mutations.back().value = invalid;
    client.mutateRow(t, "foo", mutations, attrs);

    // try empty strings
    mutations.clear();
    mutations.push_back(Mutation());
    mutations.back().column = "entry:";
    mutations.back().value = "";
    client.mutateRow(t, "", mutations, attrs);

    // this row name is valid utf8
    mutations.clear();
    mutations.push_back(Mutation());
    mutations.back().column = "entry:foo";
    mutations.back().value = valid;
    client.mutateRow(t, valid, mutations, attrs);

    // non-utf8 is now allowed in row names because HBase stores values as binary
    mutations.clear();
    mutations.push_back(Mutation());
    mutations.back().column = "entry:foo";
    mutations.back().value = invalid;
    client.mutateRow(t, invalid, mutations, attrs);

    // Run a scanner on the rows we just created
    StrVec columnNames;
    columnNames.push_back("entry:");

    std::cout << "Starting scanner..." << std::endl;
    int scanner = client.scannerOpen(t, "", columnNames, attrs);
    try {
      while (true) {
        std::vector<TRowResult> value;
        client.scannerGet(value, scanner);
        if (value.size() == 0)
          break;
        printRow(value);
      }
    } catch (const IOError &ioe) {
      std::cerr << "FATAL: Scanner raised IOError" << std::endl;
    }

    client.scannerClose(scanner);
    std::cout << "Scanner finished" << std::endl;

    //
    // Run some operations on a bunch of rows.
    //
    for (int i = 100; i >= 0; --i) {
      // format row keys as "00000" to "00100"
      char buf[32];
      sprintf(buf, "%05d", i);
      std::string row(buf);
      std::vector<TRowResult> rowResult;

      mutations.clear();
      mutations.push_back(Mutation());
      mutations.back().column = "unused:";
      mutations.back().value = "DELETE_ME";
      client.mutateRow(t, row, mutations, attrs);
      client.getRow(rowResult, t, row, attrs);
      printRow(rowResult);
      client.deleteAllRow(t, row, attrs);

      mutations.clear();
      mutations.push_back(Mutation());
      mutations.back().column = "entry:num";
      mutations.back().value = "0";
      mutations.push_back(Mutation());
      mutations.back().column = "entry:foo";
      mutations.back().value = "FOO";
      client.mutateRow(t, row, mutations, attrs);
      client.getRow(rowResult, t, row, attrs);
      printRow(rowResult);

      // sleep to force later timestamp 
      poll(0, 0, 50);

      mutations.clear();
      mutations.push_back(Mutation());
      mutations.back().column = "entry:foo";
      mutations.back().isDelete = true;
      mutations.push_back(Mutation());
      mutations.back().column = "entry:num";
      mutations.back().value = "-1";
      client.mutateRow(t, row, mutations, attrs);
      client.getRow(rowResult, t, row, attrs);
      printRow(rowResult);

      mutations.clear();
      mutations.push_back(Mutation());
      mutations.back().column = "entry:num";
      mutations.back().value = boost::lexical_cast<std::string>(i);
      mutations.push_back(Mutation());
      mutations.back().column = "entry:sqr";
      mutations.back().value = boost::lexical_cast<std::string>(i*i);
      client.mutateRow(t, row, mutations, attrs);
      client.getRow(rowResult, t, row, attrs);
      printRow(rowResult);

      mutations.clear();
      mutations.push_back(Mutation());
      mutations.back().column = "entry:num";
      mutations.back().value = "-999";
      mutations.push_back(Mutation());
      mutations.back().column = "entry:sqr";
      mutations.back().isDelete = true;
      client.mutateRowTs(t, row, mutations, 1, attrs); // shouldn't override latest
      client.getRow(rowResult, t, row, attrs);
      printRow(rowResult);

      CellVec versions;
      client.getVer(versions, t, row, "entry:num", 10, attrs);
      printVersions(row, versions);
      assert(versions.size());
      std::cout << std::endl;

      try {
        std::vector<TCell> value;
        client.get(value, t, row, "entry:foo", attrs);
        if (value.size()) {
          std::cerr << "FATAL: shouldn't get here!" << std::endl;
          return -1;
        }
      } catch (const IOError &ioe) {
        // blank
      }
    }

    // scan all rows/columns

    columnNames.clear();
    client.getColumnDescriptors(columnMap, t);
    std::cout << "The number of columns: " << columnMap.size() << std::endl;
    for (ColMap::const_iterator it = columnMap.begin(); it != columnMap.end(); ++it) {
      std::cout << " column with name: " + it->second.name << std::endl;
      columnNames.push_back(it->second.name);
    }
    std::cout << std::endl;

    std::cout << "Starting scanner..." << std::endl;
    scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames, attrs);
    try {
      while (true) {
        std::vector<TRowResult> value;
        client.scannerGet(value, scanner);
        if (value.size() == 0)
          break;
        printRow(value);
      }
    } catch (const IOError &ioe) {
      std::cerr << "FATAL: Scanner raised IOError" << std::endl;
    }

    client.scannerClose(scanner);
    std::cout << "Scanner finished" << std::endl;

    transport->close();
  } catch (const TException &tx) {
    std::cerr << "ERROR: " << tx.what() << std::endl;
  }
}