Euphoria Audio, LLC

Audio, Video and Data Consulting

Hypertable C++ Thrift Tutorial

No Comments »

Usage

Below is a simple example of how to use the MyHypertable class to read and write data.

int mainHT(int argc, char *argv[]){
	MyHypertable ht("localhost", 38080, "MyTest");

	vector<MyKV> data;
	for (int i=0; i<100; i++){
		struct MyKV kv;
		kv.key = str(format("MyRow:%d") % i);
		kv.value = lexical_cast<string>(i);
	}

	if (!ht.Write_Data("MyCF", data))
		fprintf(stderr, "Unable to write data to Hypertable\n");
	else
		fprintf(stdout, "Wrote 100 rows to Hypertable\n");

	data.clear();
	if (!ht.Read_Data("MyRow:50", "MyRow:59", data))
		fprintf(stderr, "Unable to write data to Hypertable\n");
	else{
		for (size_t x=0; x<data.size(); x++){
			fprintf(stdout, "Key [%s]  Value [%s]\n", data[x].key.c_str(), data[x].value.c_str());
		}
	}
}

Conclusion

This is very simple, inefficient code with only a few generic exception handlers. Make sure to check for other possible exceptions in your code. Always set the __isset flag whenever you modify a variable. And before you start storing data in a Big Table system, make sure to read up on key naming conventions as you can easily create hot-spots on servers and slow your application to a crawl.

Download MyHypertable.zip

Pages:  1   2   3   4   5 

Leave a Reply