Select Page

We have been playing around with Trifacta a lot recently, you can see all our Trifacta coverage here. As we know Trifacta = I can code (well, sort of). But as with any code we want to be able to save it, store it in Git and reuse it. Here is a short tutorial on how to get your script out of, and then back into, Trifacta Wrangler.

Exporting

Exporting from Trifacta Wrangler is easy!

Pop open the script view from the right
ScriptOpen w Circle

Once this is open click the save button
ScriptSave w Circle

Then Wrangle Script and save in the desired location
WrangleScript

Once done you should have a script a bit like this:

splitrows col: column1 on: '\r\n'
keep row: matches([column1], `{alpha}+ {lower}+ {lower}+:`)
delete row: matches([column1], `Log file created:`)
extract col: column1 on: `[{upper}{4,6}]`
extract col: column1 on: `{lower}+-{lower}+-{digit}+` after: `{delim}`
rename col: column3 to: 'region'
rename col: column2 to: 'log_level'
extract col: column1 after: `{delim}`
rename col: column2 to: 'message'
extract col: column1 from: `\(` to: `\)`
rename col: column2 to: 'error_message'
drop col: column1

Importing

Importing a saved script into Trifacta Wrangler’s free version is a bit more tedious though no more difficult.

Create a Dataset, Select the Data and open the Transform view.
TransformView

Now for every line in the script (except the first line in most cases) copy and paste into the Transform Expression box and click add to script.
AddToScript

Once this has been done for every line in the script we are ready to go!
Results

What now?

Now that we know how to get a script out of Trifacta what can we do with it? The easy answer is put it somewhere safe, for example Git. My favorite thing to do is use this recipe somewhere else like Python to take more direct control of my data. We might hear more about that later. Until then have fun with your precious Trifacta scripts.

Coffee to Code – Tim Gray

Tim blogs about the sharp end of code and the languages we write in.

You can Tim’s post, Converting Trifacta Recipes to Python here or all of Tim’s blogs here.

We run regular business intelligence courses in both Wellington and Auckland. Find out more here.

%d bloggers like this: