Esempio n. 1
0
static void
writeRowFunc(std::string t, char rowbuf[ROW_SIZE], char colbuf[COLUMN_SIZE], char valbuf[VALUE_SIZE], HbaseClient client, HPacket *hpacket)
{
    std::vector<Mutation> mutations;
	std::string row(rowbuf);
	std::string column(colbuf);
	std::string value(valbuf);
	const std::map<Text, Text>  dummyAttributes; // see HBASE-6806 HBASE-4658
	int i = 1;

    mutations.clear();
    mutations.push_back(Mutation());
	mutations.back().column = "entry:" + column;
	// mutations.back().column = column;
	mutations.back().value = value;
    //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);
    // std::cout << "row:" << row << "column:" << column << "value:" << value << std::endl;
    client.mutateRow(t, row, mutations, dummyAttributes);
	// mutateRowTsは、最新を上書きせずに更新
    // client.mutateRowTs(t, row, mutations, 1, dummyAttributes); // shouldn't override latest
}
Esempio n. 2
0
// static void 
std::string
getRowFunc(std::string table, char rowbuf[ROW_SIZE], std::vector<TRowResult> rowResult, HbaseClient client, HPacket *hpacket)
{
	std::string row(rowbuf);
	const std::map<Text, Text>  dummyAttributes; // see HBASE-6806 HBASE-4658
	client.getRow(rowResult, table, row, dummyAttributes);
	return returnValue(rowResult, hpacket);
}
Esempio n. 3
0
// 全テーブルを取得し、string t と一致するテーブルのみを削除
static void
initTableFunc(std::string t, HbaseClient client)
{
    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);
      }
    }
}
Esempio n. 4
0
auto createFrameHBase(const std::string& rowkey, const std::string& table,  HbaseClient& client) {
    std::vector<TRowResult> res;
    std::map<Text, Text>  attributes;
    client.getRow(res, table, rowkey,attributes);

    boost::shared_ptr<Frame<T>> frame(new Frame<T>()) ;

    //binary converter
    converter<int64_t> c_int64;
    converter<double> c_double;

    for(int i=0; i<res.size(); i++) {
        //foreach particle get its coordinates
        TRowResult a = res[i];
        for(auto it = a.columns.begin(); it != a.columns.end() ; ++it ) {
            std::string key = it->first;

            if(key.find("M:c") != std::string::npos) { //coordinate info for the particle
                //get the particle ID
                Particle<T>* p = new Particle<T>();

                std::string key_suffix = key.substr(10,8); //binario long long
                int64_t p_id =  c_int64.fromBytes(reinterpret_cast<const unsigned char*>(key_suffix.c_str()),true);
                p->id = p_id;

                //read coordinate ffor particle p_id
                std::string value= a.columns.at(key).value; //24 bytes: 3 double




                //firstr coordinate
                std::string value_suffix = value.substr(0,8);
                double res_value =  c_double.fromBytes(reinterpret_cast<const unsigned char*>(value_suffix.c_str()),true);
                p->p.x = res_value;

                //second coordinate
                value_suffix = value.substr(8,8);
                res_value =  c_double.fromBytes(reinterpret_cast<const unsigned char*>(value_suffix.c_str()),true);
                p->p.y = res_value;

                //third coordinate
                value_suffix = value.substr(16,8);
                res_value =  c_double.fromBytes(reinterpret_cast<const unsigned char*>(value_suffix.c_str()),true);
                p->p.z = res_value;

                frame->particles.push_back(*p);
                printf("Coordinate for particle %i are [%.2f,%.2f,%.2f]\n",p->id,p->p.x,p->id,p->p.y,p->id,p->p.z);

            }
        }

    }
    return frame;
}
Esempio n. 5
0
/**
Print info about table name + Y if enabled (N if not)
*/
void printTablesStatus(HbaseClient &client) {
    std::vector<std::string> table_names;
    client.getTableNames(table_names);
    auto f = [&] (std::string &s, int& acc)
    {
        std::string enabled = " N";
        if(client.isTableEnabled(s)) {
            enabled = " Y";
            std::cout<<acc<<" Table "<<s<<" - "<<enabled<<std::endl;

        }
        std::vector<TRegionInfo> regionOfTable;
        client.getTableRegions(regionOfTable,s);
        print(regionOfTable.begin(),regionOfTable.end() , 100000,"\n");
        return ++acc;

    };

    int a = fold(table_names.begin(),table_names.end(),0, f);
    std::cout<<"Velue is "<<a<<std::endl;
}
Esempio n. 6
0
// scannerOpenとscannerCloseした方がいいかもしれない。
// けど今のところ問題ないのでこのままいく
std::string 
scanRowFunc(std::string t, char startrowbuf[ROW_SIZE], char stoprowbuf[ROW_SIZE], char colbuf[COLUMN_SIZE], std::vector<TRowResult> rowResult, HbaseClient client, HPacket *hpacket)
{
	const std::map<Text, Text>  dummyAttributes; // see HBASE-6806 HBASE-4658
	std::string startrow(startrowbuf);
	std::string stoprow(stoprowbuf);
	std::string col(colbuf);
	std::vector<Text> column;
	int scannerID;
	int maxRowNum = 10;

	// column.push_back(colbuf);
	column.push_back("entry:" + col);

	// scannerID = client.scannerOpen (t, startrow, column, dummyAttributes);
	scannerID = client.scannerOpenWithStop (t, startrow, stoprow, column, dummyAttributes);
	client.scannerGetList (rowResult, scannerID, maxRowNum);
	
	// client.scannerGet (rowResult, scannerID);
	return returnValue(rowResult, hpacket);
}
Esempio n. 7
0
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;
    }
}