Solved

how to generate UUID bases on timestamp

  • 3 March 2023
  • 5 replies
  • 421 views

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 

icon

Best answer by Bikram 3 March 2023, 20:34

View original

5 replies

Userlevel 5
Badge +1

@akanshajain6793 

 

kindly try this.

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

@bikram

 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

@akanshajain6793 

 

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 = datetime.now().strftime('%Y%m-%d%H-%M%S')
eventid = date_time + str(uuid4())

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

  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');
    hexString.append(hex);
    }
 
    String encryptedSignature = hexString.toString();
    String encryptHash = encryptedSignature.replace("-","");
    encryptHash = encryptHash.toUpperCase();
    
    record.value['encryptHash']
    output.write(record)

 

using ths but not able to get the output getting error 

Reply