Forum Discussion
Coyote - Sorry that our SnapGPT currently isn't working well for this case. I have submitted an internal message to our SnapGPT support group and they will look into it.
In the meantime, I've created a sample pipeline to do what you're looking for. It's basically just two snaps: a Mapper to generate an array with the start/end timeframes, then a JSON Splitter to convert the array of objects into individual JSON documents.
Please download the attached ZIP file, decompress it, then import the SLP to your Designer.
Let me take just a moment to explain the expression in the Mapper as it contains a few pieces you may not be familiar with:
sl.range(0, Math.ceil(($end - $start) / (1000 * 60 * 60)))
.map(x =>
{ "start" : $start.plusHours(x)
, "end" : ($start.plusHours(x+1) > $end ? $end : $start.plusHours(x+1))
}
)
sl.range is a built-in function that creates an array with incrementing values from start to stop.
Math.ceil is another built-in function that rounds up a float value to the next integer value.
Note that you can perform date-difference logic, with the result as number of milliseconds between.
Next is an Array.map() method that allows you to update the entries in an array.
The syntax that I used in the map method is creating an object with the desired start/end date-time values
The Date.plusHours() method adds the appropriate number of hours generated by sl.range() function
Finally, note the ternary operator syntax used to ensure the final "end" timestamp doesn't go past the current time (given to us in the input document)
Hope this helps!
If the dynamic nature of the pipeline parameter depends on the consumer/caller of that pipeline, then you could try something like when such pipeline is created as a task - say if it is an API task in the form of Ultra task. The consumer of that task should passed the needed value that will override what's there in the pipeline-parameter or task parameter. That's one possible way having a dynamic pipeline parameter. Otherwise, it takes what's is defined in the pipeline parameter - that's what I have seen when I work with pipelines.
- Aleksandar_A2 years agoContributor III
Hello rahulmvaidya,
You can try with the following expression in a Mapper Snap:
{[_target_column_name]:$value}
Also, you can refer to the sample attached pipeline below.
Please let me know if this helps you!
Regards,
Aleksandar!