Skip to main content

Hi, as a relatvie newcomer to Streamsets, I am trying to use ‘time:dateAddition’ function, in data collector. I am using an engine version 5.6.1, but get the same issues with 5.5.0

I am basically trying to use time:Now(), to calculate yesterdays date (or at least a different date), but getting nowhere.

I even tried using the example in the docs “${time:dateAddition("MONTH", 2, 2007-10-03T10:15:30)}”

but get the error

‘EXPR_00 - Invalid expression '${time:dateAddition("MONTH", 2, 2007-10-03T10:15:30)}': com.streamsets.pipeline.api.el.ELEvalException: CTRCMN_0101 - Error parsing expression ${time:dateAddition("MONTH", 2, 2007-10-03T10:15:30)}: javax.servlet.jsp.el.ELException: Encountered "T10", expected one of e".", ">", "gt", "<", "lt", "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", ")", ",", ")", "+", "-", "*", "/", "div", "%", "mod", "and", "&&", "or", "||", "?"]’

This function seems to be new with 5.5.0

Could someone help please.

You are trying to use an unquoted string as a “Date” type object for the third argument, but that won’t work. The third argument needs to be created using time:createDateFromStringTZ. Below is the example from the docs.

https://docs.streamsets.com/portal/platform-datacollector/latest/datacollector/UserGuide/Expression_Language/Functions.html

For example, the following expression adds ten months to the datetime value and returns the value 2012-03-05 00:00:00:

${time:dateAddition("MONTH", 10, time:createDateFromStringTZ("2011-05-05 00:00:00", "Pacific/Honolulu","yyyy-MM-dd HH:mm:ss"))}

The following expression adds ten months to the datetime value and returns a value that is ten months from the time of the Data Collector machine when the expression is run:

${time:dateAddition("MONTH", 10, time.now())}

@sam 

I attempted to implement the example provided in the StreamSets documentation, but it continues to generate an error. It seems there could be an issue with one of the function parameters or some bug in the function.

Kindly let me know if you get any chance to try it in your StreamSets  work space . If it works for you , kindly let me know which version SDC it works  ,so i can give a try on it.

Error details:

EXPR_03 - Cannot evaluate expression '${time:dateAddition("MONTH", 10, time:now())}' for record 'rawData::0': com.streamsets.pipeline.api.el.ELEvalException: CTRCMN_0100 - Error evaluating expression ${time:dateAddition("MONTH", 10, time:now())}: javax.servlet.jsp.el.ELException: Attempt to coerce a value of type "java.util.Date" to type "java.time.LocalDateTime"

 

EXPR_03 - Cannot evaluate expression '${time:dateAddition("MONTH", 10, time:createDateFromStringTZ("2011-05-05 00:00:00", "Pacific/Honolulu","yyyy-MM-dd HH:mm:ss"))}' for record 'rawData::0': com.streamsets.pipeline.api.el.ELEvalException: CTRCMN_0100 - Error evaluating expression ${time:dateAddition("MONTH", 10, time:createDateFromStringTZ("2011-05-05 00:00:00", "Pacific/Honolulu","yyyy-MM-dd HH:mm:ss"))}: javax.servlet.jsp.el.ELException: Attempt to coerce a value of type "java.util.Date" to type "java.time.LocalDateTime"

 

Thanks & Regards

Bikram_


In version 5.6.1, both of those work for me (using the Docker container). I see you already caught the typo that time.now should be time:now

At this point, reaching out to the support team will probably get you a faster answer. They can dig into any details about your environment such as the Java version to see if those could make the type wrong.


 

@southwr62 

 

A bug was identified in the dateAddition function, and the solution has been included in version 5.6.0. Here are the particulars.

 

  • The time:dateAddition and time:dateDifference functions fail to validate because they expect datetime values in the LocalDateTime date format, which the StreamSets expression language cannot interpret.

Reply