Question

If i use UUID1 for my column names and then retrieve them with php how can i convert that UUID to readable string so i could insert that string to the HTML and then later on use it to select that same column by converting that string back to UUID? Is that even possible?

I could go with UTF8 or something else but i want to avoid collisions and get ordered wide rows, and i really need to store those column names to the HTML, i can't see any other way to do it.

I'm using phpcassa.

Was it helpful?

Solution

You can cast UUID objects to strings to get a nice printable version. That same string can be used with UUID::import() to create an identical UUID object again:

use phpcassa\UUID;

$uuid = UUID::uuid1();
$pretty_uuid = (string)$uuid;
echo("Printable version: " . $pretty_uuid . "\n");
$uuid_copy = UUID::import($pretty_uuid);
assert ($uuid == $uuid_copy);

OTHER TIPS

Assuming you are getting the UUID as byte[], you can use something like this:

    public Object convertFromNoSqlImpl(byte[] value) {
        byte[] timeArray = new byte[8];
        byte[] clockSeqAndNodeArray=new byte[8];
        System.arraycopy(value,0,timeArray,0,8);
        System.arraycopy(value,8,clockSeqAndNodeArray,0,8);
        long time = StandardConverters.convertFromBytes(Long.class, timeArray);
        long clockSeqAndNode = StandardConverters.convertFromBytes(Long.class, clockSeqAndNodeArray);
        UUID ud = new UUID(time,clockSeqAndNode);
        return ud;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top