Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dss77 opened this issue May 10, 2018 · 0 comments
Open

Comments

@dss77
Copy link

dss77 commented May 10, 2018

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

@dss77 dss77 changed the title Can't get a record with a TimeUUID value as primary key Can't get a record by id when it has a TimeUUID value as primary key May 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant