maandag 20 december 2010

Quipu : Groovy templates

In a discussion on the Sourceforge.net website, i learned that Quipu uses the GStringTemplateEngine of Groovy. The GStringTemplateEngine processes template sourcefiles (but in case of Quipu it’s stored in a table)  by substituting variables and expressions into placeholders to produce the desired output using a streaming approach.

The template engine uses JSP style <% %> and <%=%> expression or Gstring style expression. The JSP style/Gstring Style coding reminds me of asp/php- and C coding. On one of the webpages , i found an example. For instance <%= firstname %> is replaced with a instance of a firstname and ${accepted ? ‘accepted’ : ‘rejected’} reminds me of C coding ( if accepted then ‘accepted’ else ‘rejected’).
When you want to edit the templates it's not advisavle doing this directly in the database (like i did initially) but with the ‘back end web GUI’ (http://localhost:8080/qp/). Starting this url will show the following window:

image

With this window you can browse the different available controllers in Quipu. On the left screen the numbers of controllers and the number of domains are shown. The number of available controllers on the window, is equal to the number of domains (33). Domains are a subset of controllers?


image

I already inserted a record (808) in the database (before i knew that there was a front end available) : SQL dialect ANSI SQL 92 Custom. Lets take a look into this template by clicking on ‘808’:

image

And here you can see the template. The next thing we can do is trying to modify the Groovy template by pressing ‘Wijzigen’.

image

And now it’s possible to edit the template text. I installed notepad++ on my VM and copied the Groovy template in notepad++:

image

And this template generates the following ANSI SQL code:

image

Okay, let’s try to change this script into something like this (DROP/CREATE Stored procedure):

image

At first i was a bit ambitious about creating to many code at once and the following error occurred :

image

After some debugging of the code, i managed to create a new template with the DROP/CREATE Stored procedure.

image

So this template creates stored procedures in SQL Server.

Conclusion:
  • Debugging the code is a problem. Editing the code in notepad++, copy the code in the Quipu back end, generating the stage (or datavault) and then hoping that it will execute, is a labour full job. If a name of a object is miss spelled, it will still execute and a null appears in the generated code. The coding would speed up, if there is some sort of direct feedback whether the code is correct (intellisense?).
  • I think that the names (of the fields of the table) are equal to the objects/properties. Still, it would help if the objectmodel and their properties is described.

Overall, it is great to have the ability to edit the templates and generating all kinds of code. Anything is possible! Mastering Groovy is inevitable to create powerful scripts.

Perhaps it should be possible to write the generated code into a file or a database. At this moment, there is an extra step involved: retrieving the generated code from the qp_sql_step table or copy the generated code in a tool, for instance Integration Services.

Greetz,
Hennie

3 opmerkingen:

  1. Zijn er ook bepaalde redenen te bedenken waarom je de standaard templates wilt aanpassen? Ben je niet bang dat je dan de standaard datavault methodiek verandert doordat sql code niet meer conform dv is?

    BeantwoordenVerwijderen
  2. Hi Ronald,

    Goeie vraag. Niet zozeer Datavault methodiek zou ik willen aanpassen, maar dan wel de vorm waarin de Datavault wordt gegenereerd door Quipu.

    Gr,
    Hennie

    BeantwoordenVerwijderen
  3. Thanks for sharing this post. Your post is really very helpful its students. Power BI Online Training

    BeantwoordenVerwijderen