Forum Discussion
22 Replies
- DivyaNew Contributor
You can use pipe.ruuid function. It is unique for each run I assume.
- smudassirEmployee
If user wants to generate unique id once in pipeline then pipe.ruuid is sufficient. However, if they want multiple unique ids then I would say use script snap with python and use uuid library to generate.
- vincenrNew Contributor III
I saw your comment about generating multiple unique ids (GUID) in April of 2019. I’m using a REST POST to send a SQL query to another system, which works fine except that I haven’t figured out how to generate a unique GUID for every row in my query? When I insert Math.randomUUID() as one of the columns it generates the same GUID for every single row in my results, not different UUIDs, one for each row. How can I do this? A call to a user defined function? How would I implement that, if a user defined function is the answer?
- tlikarishEmployee
There is UUID function you can call using the expression language.
- Sowmya_RayavaraNew Contributor III
Thank you @tlikarish @Divya @smudassir
- koryknickEmployee
In an expression:
Math.randomUUID()
For example, in a Mapper snap:
- vincenrNew Contributor III
I’m doing the following but it only gives ONE unique value, the same value, for ALL rows:
[Entry].EntryID, ‘" + Math.randomUUID() + "’ as [Blank Number], [EntAppSts].
I need a unique value for each row in my SQL query, not one unique value. Using the mapper snap will only give one unique value and won’t work for all rows in my query, unless I’m missing something?
- koryknickEmployee
That is because the expression to build the SQL is inserting the random value only once when the SQL statement is generated and parsed for the Select statement that is executed, so SQL Server is treating it like a static string. Try moving it to a Mapper snap after the Execute snap.
Otherwise, you may need to find the syntax for SQL Server to generate a GUUID.
- vincenrNew Contributor III
Ok, so I am using a mapper snap to get the path for the json splitter like:
jsonPath($, “$response.entity.feed.entry[*].content.Record”)
So, not to clear about how I would use the function for the columns embedded in each record?
- vincenrNew Contributor III
Yes, and just about every version to do the same thing for Oracle, MySQL, PostGres etc… I’m querying against a proprietary system and don’t know what DB they are using.
- koryknickEmployee
I’m not familiar with your exact details, but attached is a sample pipeline that demonstrates the flow as I understand you want to do it.
Generate Guid per row_2022_07_05.slp (6.0 KB)- vincenrNew Contributor III
So does it somehow add the UUID to every row in the response from the POST?
- koryknickEmployee
Yes - the Mapper would add the value to the returned results.
With that said, depending on how the API returns the results, there may be additional steps before the Mapper to add the GUID value. For example, if the API returns an array of values in the response, you may need to use a JSON Splitter to split the array into individual documents.
- koryknickEmployee
Add a Mapper snap as shown between the JSON Splitter and CSV Formatter:
- vincenrNew Contributor III
I finally got it working… Might not be the simplest solution, but I found a forum where someone was trying to do manipulations on a column after the data was returned by the REST POST. So here’s what I did, and it works.
The ‘Map columns’ is where I manipulate the one column to make it a UUID. The Group By was indicated by the forum I read as needed to “put it back together”, but then I had to add a second splitter after that…
- vincenrNew Contributor III
Can someone explain how I would get a unique GUID for every row in a SQL query I’m sending using a REST POST snap?
- koryknickEmployee
Can you add a Mapper after your API call to generate the unique ID? Or does it need to be generated from within the database?
- vincenrNew Contributor III
I don’t know how to do it so it generates a separate unique id for every row. Is there a post that explains how to do this? I’m brand new to SnapLogic. Specifically, I’m referring to from within the mapper snap.