Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <sstream>
- #include <iostream>
- #include <stdlib.h>
- #include <set>
- #include <vector>
- #include <tr1/memory>
- #include <string>
- #include <stdio.h>
- #include <transport/TSocket.h>
- #include <transport/TBufferTransports.h>
- #include <protocol/TBinaryProtocol.h>
- #include "gclocal/Cassandra.h"
- using namespace apache::thrift;
- using namespace apache::thrift::protocol;
- using namespace apache::thrift::transport;
- using namespace std;
- using namespace org::apache::cassandra;
- using namespace boost;
- //Tried both localhost and 127.0.0.1... same result for both :(
- const string host("localhost");
- const int port= 9160;
- int64_t uuid_to_time(string uuid) {
- cout << "UUID Sent: " << uuid << endl;
- for ( int i = 0; i < uuid.length(); i++)
- {
- if (uuid[i] =='-')
- {
- uuid.replace(i,1,"");
- i += 1;
- }
- }
- string tsFromUUID = uuid.substr(13, 3) + uuid.substr(8, 4) + uuid.substr(0, 8);
- //cout << "UUID No Hyphens: " << uuid << endl;
- //cout << "Timestamp in hex: " << tsFromUUID << endl;
- int64_t x;
- std::stringstream ss;
- ss << std::hex << tsFromUUID;
- ss >> x;
- //cout << "Which should be: " << x << endl;
- int64_t perhapsx = (x - 122192928000000000)/10000;
- cout << "Timestamp: " << perhapsx << endl;
- return perhapsx;
- }
- int64_t createTimestamp()
- {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (int64_t) tv.tv_sec * 1000000 + (int64_t) tv.tv_usec;
- }
- int main()
- {
- try {
- boost::shared_ptr<TSocket> socket(new TSocket(host, port));
- boost::shared_ptr<TTransport> transport(new TFramedTransport(socket));
- boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
- CassandraClient client(protocol);
- transport->open();
- client.set_keyspace("Crawldata");
- cout << "selected" << endl;
- KeyRange kr;
- kr.start_key = "fetched_201011091330";
- kr.end_key = "fetched_201011091330";
- SlicePredicate sp;
- //could set sp.column_names here if we cared about column names
- //Set .start if we want to not get the whole thing, sames goes for .end
- //sr.start = <<CURRENT_TIMESTAMP_AS_UUID>>
- //SliceRange *sr = new SliceRange();
- SliceRange sr;
- sr.start = "";
- sr.count = 1000000;
- sp.slice_range = sr;
- sp.__isset.slice_range = true;
- kr.__isset.start_key = true;
- kr.__isset.end_key = true;
- ColumnParent cp;
- cp.column_family = "FetchedURLs";
- ConsistencyLevel cl = ONE;
- vector<KeySlice> ks;
- client.get_range_slices(ks, cp, sp, kr, cl);
- cout << "Got this many keys: " << ks.size() << endl;
- for (int i = 0; i < ks.size(); i++) {
- vector<ColumnOrSuperColumn> cols = ks[i].columns;
- cout << "This many columns: " << cols.size() << endl;
- }
- int64_t ts64 = uuid_to_time(string("96a6d87e-ec2f-11df-9dc2-90e6baebb7ee"));
- cout << "ts64: " << ts64 << endl;
- transport->close();
- } catch (org::apache::cassandra::InvalidRequestException &ire) {
- cout << "InvalidRequestException: " << ire.why << endl;
- } catch (apache::thrift::transport::TTransportException &tte) {
- cout << "TTransportException: " << tte.what() << endl;
- } catch (TException &te) {
- cout << "TException: " << te.what() << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement