@Override public Object generate(Client<?> client, String dataType) { CqlResult cqlResult = ((CassandraClientBase) client).execute("SELECT NOW() FROM system_schema.columns LIMIT 1", ((CassandraClientBase) client).getRawClient(SYSTEM)); CqlRow cqlRow = cqlResult.getRowsIterator().next(); TimeUUIDType t = TimeUUIDType.instance; UUID timeUUID = t.compose(ByteBuffer.wrap(cqlRow.getColumns().get(0).getValue())); switch (dataType.toLowerCase()) { case UUID: return timeUUID; default: return java.util.UUID.randomUUID(); } }
@Test public void timeUUIDComparison() { TimeUUIDType ti = TimeUUIDType.instance; UUID zu = UUID.fromString(z); UUID vu = UUID.fromString(v); ByteBuffer zb = ti.decompose(zu); ByteBuffer vb = ti.decompose(vu); assertEquals(-1, ti.compare(zb, vb)); assertEquals(1, zu.compareTo(vu)); assertEquals(1, ti.compare(vb, zb)); assertEquals(-1, vu.compareTo(zu)); } }
public int compareCustom(ByteBuffer b1, ByteBuffer b2) { // Compare for length int s1 = b1.position(), s2 = b2.position(); int l1 = b1.limit(), l2 = b2.limit(); // should we assert exactly 16 bytes (or 0)? seems prudent boolean p1 = l1 - s1 == 16, p2 = l2 - s2 == 16; if (!(p1 & p2)) { assert p1 | (l1 == s1); assert p2 | (l2 == s2); return p1 ? 1 : p2 ? -1 : 0; } long msb1 = b1.getLong(s1); long msb2 = b2.getLong(s2); msb1 = reorderTimestampBytes(msb1); msb2 = reorderTimestampBytes(msb2); assert (msb1 & topbyte(0xf0L)) == topbyte(0x10L); assert (msb2 & topbyte(0xf0L)) == topbyte(0x10L); int c = Long.compare(msb1, msb2); if (c != 0) return c; // this has to be a signed per-byte comparison for compatibility // so we transform the bytes so that a simple long comparison is equivalent long lsb1 = signedBytesToNativeLong(b1.getLong(s1 + 8)); long lsb2 = signedBytesToNativeLong(b2.getLong(s2 + 8)); return Long.compare(lsb1, lsb2); }
public ByteBuffer fromString(String source) throws MarshalException { // Return an empty ByteBuffer for an empty string. if (source.isEmpty()) return ByteBufferUtil.EMPTY_BYTE_BUFFER; ByteBuffer idBytes = null; // ffffffff-ffff-ffff-ffff-ffffffffff if (regexPattern.matcher(source).matches()) { UUID uuid = null; try { uuid = UUID.fromString(source); idBytes = decompose(uuid); } catch (IllegalArgumentException e) { throw new MarshalException(String.format("Unable to make UUID from '%s'", source), e); } if (uuid.version() != 1) throw new MarshalException("TimeUUID supports only version 1 UUIDs"); } else { throw new MarshalException(String.format("Unknown timeuuid representation: %s", source)); } return idBytes; }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { return new Constants.Value(fromString((String) parsed)); } catch (ClassCastException exc) { throw new MarshalException( String.format("Expected a string representation of a timeuuid, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
long reorder1 = TimeUUIDType.reorderTimestampBytes(msb1); long reorder2 = TimeUUIDType.reorderTimestampBytes(msb2);
public int compareCustom(ByteBuffer b1, ByteBuffer b2) { // Compare for length int s1 = b1.position(), s2 = b2.position(); int l1 = b1.limit(), l2 = b2.limit(); // should we assert exactly 16 bytes (or 0)? seems prudent boolean p1 = l1 - s1 == 16, p2 = l2 - s2 == 16; if (!(p1 & p2)) { assert p1 | (l1 == s1); assert p2 | (l2 == s2); return p1 ? 1 : p2 ? -1 : 0; } long msb1 = b1.getLong(s1); long msb2 = b2.getLong(s2); msb1 = reorderTimestampBytes(msb1); msb2 = reorderTimestampBytes(msb2); assert (msb1 & topbyte(0xf0L)) == topbyte(0x10L); assert (msb2 & topbyte(0xf0L)) == topbyte(0x10L); int c = Long.compare(msb1, msb2); if (c != 0) return c; // this has to be a signed per-byte comparison for compatibility // so we transform the bytes so that a simple long comparison is equivalent long lsb1 = signedBytesToNativeLong(b1.getLong(s1 + 8)); long lsb2 = signedBytesToNativeLong(b2.getLong(s2 + 8)); return Long.compare(lsb1, lsb2); }
@Override public ByteBuffer fromStringCQL2(String source) throws MarshalException { // Return an empty ByteBuffer for an empty string. if (source.isEmpty()) return ByteBufferUtil.EMPTY_BYTE_BUFFER; ByteBuffer idBytes = null; // ffffffff-ffff-ffff-ffff-ffffffffff if (regexPattern.matcher(source).matches()) { UUID uuid = null; try { uuid = UUID.fromString(source); idBytes = decompose(uuid); } catch (IllegalArgumentException e) { throw new MarshalException(String.format("unable to make UUID from '%s'", source), e); } if (uuid.version() != 1) throw new MarshalException("TimeUUID supports only version 1 UUIDs"); } else { idBytes = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes(TimestampSerializer.dateStringToTimestamp(source))); } return idBytes; }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { return new Constants.Value(fromString((String) parsed)); } catch (ClassCastException exc) { throw new MarshalException( String.format("Expected a string representation of a timeuuid, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
long reorder1 = TimeUUIDType.reorderTimestampBytes(msb1); long reorder2 = TimeUUIDType.reorderTimestampBytes(msb2);
public int compareCustom(ByteBuffer b1, ByteBuffer b2) { // Compare for length int s1 = b1.position(), s2 = b2.position(); int l1 = b1.limit(), l2 = b2.limit(); // should we assert exactly 16 bytes (or 0)? seems prudent boolean p1 = l1 - s1 == 16, p2 = l2 - s2 == 16; if (!(p1 & p2)) { assert p1 | (l1 == s1); assert p2 | (l2 == s2); return p1 ? 1 : p2 ? -1 : 0; } long msb1 = b1.getLong(s1); long msb2 = b2.getLong(s2); msb1 = reorderTimestampBytes(msb1); msb2 = reorderTimestampBytes(msb2); assert (msb1 & topbyte(0xf0L)) == topbyte(0x10L); assert (msb2 & topbyte(0xf0L)) == topbyte(0x10L); int c = Long.compare(msb1, msb2); if (c != 0) return c; // this has to be a signed per-byte comparison for compatibility // so we transform the bytes so that a simple long comparison is equivalent long lsb1 = signedBytesToNativeLong(b1.getLong(s1 + 8)); long lsb2 = signedBytesToNativeLong(b2.getLong(s2 + 8)); return Long.compare(lsb1, lsb2); }
private void executeTraceNextQuery() throws TException { if (!CliMain.isConnected()) return; UUID sessionId = TimeUUIDType.instance.compose(thriftClient.trace_next_query()); sessionState.out.println("Will trace next query. Session ID: " + sessionId.toString()); }
public ByteBuffer trace_next_query() throws TException { UUID sessionId = UUIDGen.getTimeUUID(); state().getQueryState().prepareTracingSession(sessionId); return TimeUUIDType.instance.decompose(sessionId); }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { return new Constants.Value(fromString((String) parsed)); } catch (ClassCastException exc) { throw new MarshalException( String.format("Expected a string representation of a timeuuid, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
long reorder1 = TimeUUIDType.reorderTimestampBytes(msb1); long reorder2 = TimeUUIDType.reorderTimestampBytes(msb2);
public int compareCustom(ByteBuffer b1, ByteBuffer b2) { // Compare for length int s1 = b1.position(), s2 = b2.position(); int l1 = b1.limit(), l2 = b2.limit(); // should we assert exactly 16 bytes (or 0)? seems prudent boolean p1 = l1 - s1 == 16, p2 = l2 - s2 == 16; if (!(p1 & p2)) { assert p1 | (l1 == s1); assert p2 | (l2 == s2); return p1 ? 1 : p2 ? -1 : 0; } long msb1 = b1.getLong(s1); long msb2 = b2.getLong(s2); msb1 = reorderTimestampBytes(msb1); msb2 = reorderTimestampBytes(msb2); assert (msb1 & topbyte(0xf0L)) == topbyte(0x10L); assert (msb2 & topbyte(0xf0L)) == topbyte(0x10L); int c = Long.compare(msb1, msb2); if (c != 0) return c; // this has to be a signed per-byte comparison for compatibility // so we transform the bytes so that a simple long comparison is equivalent long lsb1 = signedBytesToNativeLong(b1.getLong(s1 + 8)); long lsb2 = signedBytesToNativeLong(b2.getLong(s2 + 8)); return Long.compare(lsb1, lsb2); }
public UUID newSession(Map<String,ByteBuffer> customPayload) { return newSession( TimeUUIDType.instance.compose(ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes())), TraceType.QUERY, customPayload); }
public ByteBuffer trace_next_query() throws TException { UUID sessionId = UUIDGen.getTimeUUID(); state().getQueryState().prepareTracingSession(sessionId); return TimeUUIDType.instance.decompose(sessionId); }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { return new Constants.Value(fromString((String) parsed)); } catch (ClassCastException exc) { throw new MarshalException( String.format("Expected a string representation of a timeuuid, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
long reorder1 = TimeUUIDType.reorderTimestampBytes(msb1); long reorder2 = TimeUUIDType.reorderTimestampBytes(msb2);