05-27-2022 07:01 AM
Hi Team,
I have found one of the transformational rules applied on “date field” not getting exported to the final output file (i.e. excel file) when the pipeline has been executed.
Output preview on the snap does show the right data (i.e. expected one), pipeline validation also shows the right data however the file which gets generated after pipeline execution doesn’t get those details.
I have tried the following:
shift+validate
It’s a simple pipeline consisting of
Snowflake Execute --> Mapper --> Excel Formatter --> File Writer
Sharing some screenshots to help it understand better:
(1) Pipeline with 4 snaps
(2) Snowflake execute output preview in JSON format (highlighted yellow fields needs transformation)
(3) Transformation Rules on Date fields
(4) Transformation Rule: $Expire_Date.toString().replace('{Timestamp=',"").replace('.000+0000}',"Z")
(5) Output preview after transformational rule
(6) Mapper output preview shows different data
→ I’ve observed certain times that the transformation rules won’t work so I go inside the mapper, modify the rule a bit, bring it back to default rule so that I can save it (save is not enabled if there is no change thus this workaround)
(7) As shift+validate
didn’t work, had to change the transformation rule, save it and then this is the output preview on mapper snap:
(8) Settings under excel formatter snap for reference:
(9) Settings under File Writer snap for reference:
(10) File generated with default 50 records due to validate & execute
on File writer snap
(11) Downloaded the file that gets generated in step 10 and below is the output (expected)
(12) Executed Pipeline
(13) Output File of Executed pipeline
I’ve seen this happening numerous times particularly to fields containing timestamp in other pipelines too, am I doing something wrong over here? Any settings that needs to be changed either in Mapper, Excel Formatter or File Writer snap?
Thanking in advance for your valuable time and suggestions on this one.
Best Regards,
DT
Solved! Go to Solution.
05-30-2022 11:42 AM
The Snowflake snaps have a setting called Handle Timestamp and Date Time Data
. Unfortunately, its default setting, Default Date Time format in UTC Time Zone
, has less-than-ideal behavior. The object type of the timestamp objects is java.sql.Timestamp, which will result in the odd inconsistencies you’re seeing between validation vs execution, and it’s also not a very usable type on the SnapLogic expression language.
I suggest changing this setting to the other option, SnapLogic Date Time format in Regional Time Zone
. This will convert the timestamps to the type org.joda.time.DateTime, the type that the SnapLogic EL functions are designed to deal with.
This option will also produce a DateTime with the default time zone of the plex node, which can complicate things if the node’s default timezone isn’t UTC. But based on what you’ve shown, your node’s default timezone is UTC, so this shouldn’t be a problem for you, fortunately.
After changing that setting, try using an expression like $Expire_Date.toLocaleDateTimeString({format: "yyyy-MM-dd'T'HH:mm:ss'Z'"})
.
Hope that helps.
05-31-2022 11:15 AM
I wouldn’t say either is clearly better than the other, but there’s certainly no reason to use both. Pick one.
05-31-2022 11:19 AM
Actually, there’s an assumption with both of these expressions that the platform’s default time zone is UTC. If that were to change, the first expression’s replace wouldn’t do anything because the string wouldn’t end with ‘Z’. That’s probably a good thing, since you’d discover the problem more quickly. The second expression would just format the timestamp as if it were in UTC when it’s really not, so this would be a much more subtle problem to detect and fix.
05-31-2022 11:20 AM
Super, thanks @ptaylor for your assistance on this one. Your help is really appreciated.
05-31-2022 11:28 AM
Summarizing the solution as per this use case:
Snowflake execute snap Settings > Handle Timestamp and Date Time Data > SnapLogic Date Time format in Regional Time Zone
$Expire_Date.toLocaleDateTimeString({format: "yyyy-MM-dd'T'HH:mm:ss'Z'"})
$Expire_Date.toString().replace('.000Z',"Z")
Works only for this use case, before using expressions, check the raw data and then put the transformation rule as per the raw data and expected data.
Signing off from this thread. Thanks again everyone (@j.angelevski, @robin and @ptaylor) for your help.