posulliv / libcassandra

A high level C++ client for Cassandra
http://github.com/posulliv/libcassandra
Other
60 stars 66 forks source link

Unable to use TimeUUID as Column Name #6

Open themanatuf opened 14 years ago

themanatuf commented 14 years ago

I haven't been able to use a TimeUUID as a column name because TimeUUID's are supposed to be exactly 16 bytes. I've been reading through the libcassandra code and it looks like everything is getting converted into a std::string which is fine for everything except TimeUUID. Is there another way to use this as a column name or am I missing something? I'll dig deeper into the code to see if there is a quick way to fix it (although I do not think there is).

themanatuf commented 14 years ago

Ok, I think I found it - libgenthrift/cassandra_types.cpp. I took the warning at the top in the comments to heart, but I couldn't resist :)

ColumnPath::write function at (or near) line 687. For both this->super_column and this->column I added the .c_str() to return the character array rather than writing the string struct. The new function should look as follows:

uint32_t ColumnPath::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  xfer += oprot->writeStructBegin("ColumnPath");
  xfer += oprot->writeFieldBegin("column_family", ::apache::thrift::protocol::T_STRING, 3);
  xfer += oprot->writeString(this->column_family);
  xfer += oprot->writeFieldEnd();
  if (this->__isset.super_column) {
    xfer += oprot->writeFieldBegin("super_column", ::apache::thrift::protocol::T_STRING, 4);
    xfer += oprot->writeBinary(this->super_column.c_str());
    xfer += oprot->writeFieldEnd();
  }
  if (this->__isset.column) {
    xfer += oprot->writeFieldBegin("column", ::apache::thrift::protocol::T_STRING, 5);
    xfer += oprot->writeBinary(this->column.c_str());
    xfer += oprot->writeFieldEnd();
  }
  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}

I haven't thoroughly tested this, but I AM able to add a column (or super column) with TimeUUID name. I hope this receives everyone well.

themanatuf commented 14 years ago

Ok, disregard my comment/changes earlier. I was not assigning my strings properly in C++ to accomodate TimeUUID's. Here is the proper way (in C++) to assign a TimeUUID to a string and have it get added successfully into Cassandra:

uuid_t uu;
string suu;

uuid_generate_time(uu);
suu.assign((char *)uu, 16);
key_space->insertColumn(row_key, cf, suu, col, val);

Hope that helps someone else in the future. Sorry for any confusion with my earlier posts.