0

I have a column family in cassandra which records all the events emitted by a particular user over a specified time period.

I'm using a composite column consisting of a UUID1 and a UTF8 string. I'd like to select all the columns after a paticular time.

// Code to create the column family.
use phpcassa\SystemManager;

$sys = new SystemManager('127.0.0.1');

$sys->create_column_family($keyspace, 'UserActivity', array(
    "comparator_type" => "CompositeType(LexicalUUIDType, UTF8Type)",
    "key_validation_class" => "UTF8Type"
));

In the code below I try to read the data. Initially I tried creating an array with just the event type set at the 1 index, however although this seemed to work I got lots of errors in the log. Now, I'm trying to set a timestamp in the past and base a UUID1 on it. No errors - but no data either.

// Code to read data
$activityFam = new ColumnFamily($this->pool, 'UserActivity');
$activityFam->insert_format = ColumnFamily::ARRAY_FORMAT;
$activityFam->return_format = ColumnFamily::ARRAY_FORMAT;


$fiveMinPrev = $this->dateFactory->getDateTime();
$fiveMinPrev->sub(new \DateInterval("PT5M"));

$uuid = \phpcassa\UUID::uuid1(null, $fiveMinPrev->getTimestamp());
// Get the most recent SESSION event from the users activity log.
$slice = new ColumnSlice(array(0 => $uuid, 1=>self::EVENT_SESSION));

$columns = $activityFam->get($someUserId, $slice);

How do I achieve selecting columns from a specified time onwards?

Thanks,

Ben Waine
  • 1,650
  • 3
  • 21
  • 34
  • None that if you're actually using LexicalUUIDType, you'll want to switch that to TimeUUIDType in order to have proper column sorting. – Tyler Hobbs Jun 24 '13 at 17:56

1 Answers1

0

Bah!

I realised this is exactly the correct approach to take however it seems I wasn't using a timestamp generated by my 'DateFactory' (which allows me to freeze and manipulate time during testing) to base the timestamp on when I actually inserted the record.

Thus producing incorrect results!

Ben Waine
  • 1,650
  • 3
  • 21
  • 34