Skip to content

Can't get a record by id when it has a TimeUUID value as primary key #4

@dss77

Description

@dss77

It’s not possible to search a record when the key is a Timeuuid value. For example the URL

 http://192.168.1.1/api/v2/cassandra_db/_table/test_table/af45eab0-5364-11e8-a43b-93f2b8ecce07

returns the following error:

 'TIME UUID type can only be set with null, or seconds, or valid formatted time.'

The problem is that the file df-cassandra/src/Database/Schema/Schema.php only allow to create Timeuuid from integers and dates. The problem here is that Timeuuids for the same timestamp but generated on different machines are different because of the mac address part, therefore a record can’t be found if the timeeuid was generated in another machine.

case DbSimpleTypes::TYPE_TIME_UUID:
    if (is_numeric($value)) {
        return new \Cassandra\Timeuuid((int)$value); // must be seconds
    } elseif (empty($value) || (0 === strcasecmp($value, 'now()'))) {
        return new \Cassandra\Timeuuid();
    } elseif (false !== $seconds = strtotime($value)) {
        return new \Cassandra\Timeuuid($seconds);
    } else {
        throw new BadRequestException('TIME UUID type can only be set with null, or seconds, or valid formatted time.');
    }
    break;

There were a known limitation to generate a Timeuuid from a string representation in the Cassandra PHP driver but it was solved in 2017 (See: https://github.com/datastax/php-driver/pull/113/files). The problem is solved with the following code:

case DbSimpleTypes::TYPE_TIME_UUID:
    if (is_numeric($value)) {
        return new \Cassandra\Timeuuid((int)$value); // must be seconds
    } elseif (empty($value) || (0 === strcasecmp($value, 'now()'))) {
        return new \Cassandra\Timeuuid();
    } elseif (false !== $seconds = strtotime($value)) {
        return new \Cassandra\Timeuuid($seconds);
    } else {
        // UPDATE THIS LINE
        return new \Cassandra\Timeuuid($value);
    }
    break;

Hope it helps.

Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions