how to generate UUID bases on timestamp

  • 3 March 2023
  • 5 replies

Hi Team


I have a date datefield storing current datetime in it want to create a UUID using same column how i can create . currently using groovy script to create UUID but want to use same column and create it 


Best answer by Bikram 3 March 2023, 20:34

View original

5 replies

Userlevel 5
Badge +1



kindly try this.

String timeuuid = com.datastax.driver.core.utils.UUIDs.timeBased().toString();


 thanks for the response as always


but before this am creating a dateinhour column to store current date and i want to use that column to generate UUID is that possible to pass that in parameter for above function ?

Userlevel 5
Badge +1



I tried this in jython , kindly try it in your pipeline and let me know if it helps.


from datetime import datetime
from uuid import uuid4
date_time ='%Y%m-%d%H-%M%S')
eventid = date_time + str(uuid4())

for record in sdc.records:
    record.value['data'] = eventid
    # Write record to processor output

  except Exception as e:
    # Send record to error
    sdc.error.write(record, str(e))

Thanks possible to share solution using groovy stage? we are using same and other transformation also

    MessageDigest mac = MessageDigest.getInstance("SHA-256");
    byte[] signatureBytes = mac.digest(dateInHour.getBytes(StandardCharsets.UTF_8));
    StringBuffer hexString = new StringBuffer();
    for (int j=0; j<signatureBytes.length; j++) {
    String hex=Integer.toHexString(0xff & signatureBytes[j]);
    if(hex.length()==1) hexString.append('0');
    String encryptedSignature = hexString.toString();
    String encryptHash = encryptedSignature.replace("-","");
    encryptHash = encryptHash.toUpperCase();


using ths but not able to get the output getting error