Article | Vectors, Strings and Transform Functions

Hardly, one would find blogs/articles/tutorials on Ab Initio transformation functions. I introduce you to another set of functions which will make you understands vectors in a different way.


Suppose, there is data file whose record format has 5 fields, namely A, B, C and D. Let us give them useful meaning, A – student_id, B – student_nm, C – sem_num, D – subject_name, E – marks.

There will be a possibility that combination of A, B remains the same across several records in the data, whereas remaining columns may change. For instance, student Mr. X has 3 subjects in semester 1, whereas Mr. Y has 4 subjects in semester 2 and Mr. Z also having 4 subjects, but in semester 2.

What if there’s a need to consolidate so much information in a single record and present it as a report. This report must have Student Name, Student Id, Semesters covered so far (comma-delimited), Courses taken (pipe-delimited) and Average Marks.

Transformation Function

The following transformation rule uses string_join() and vector_sort_dedup_first() to solve the purpose, i.e. to get an output string of pipe-delimited vector elements.

out.target_field :: string_join(vector_sort_dedup_first(in), "|");

One can create user-defined function which wraps the above functionality, which would be generic enough to be used in any transformation where vectors are involved.

out :: get_delim_vec_ele(input_vec, delim)
   out :: string_join(vector_sort_dedup_first(input_vec), delim);

This function takes 2 arguments, input vector and delimiter to form delimited string of vector elements as output. So, your actual transformation can now look like;

out.target_field :: get_delim_vec_ele(in, "|");

Hope this helps 🙂


One thought on “Article | Vectors, Strings and Transform Functions

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s