Tuesday, 13 March 2018

Qlikview Architecture - One Tier Solution

Introduction
Many things have been said about which architecture to follow when developing Qlikview Apps. The overall winner so far has been the 3-tier architecture. This is simple 3 apps that do different things. The first 2 apps act as an ETL process and the third app will be the visualisation layer. Therefore, the first app, Tier 1, will only get source data from wherever and store it into different QVD's. The second app uses the QVD's from Tier 1 and does all the modelling and transformations and stores this into a more star schema structure. Tier 3 will then just read these QVDs and display the analytics as we need.

The above process is the basic 3-tier process followed in developing Qlikview Apps that are reusable and mostly for long term projects that will need maintenance and are going to be used long term. but, what if you need to complete a quick POC for someone. One wonders if this process is still necessary. In this post, we will discuss the merits of using a 1-tier architecture as well as the situations whereby this would be needed.

When to Use
When is it advantageous to use a 1-tier architecture? The answer should be never as we are trying to build scalable, maintainable Qlikview Apps and we need to separate processes. It is also important that Apps are separated for debugging purposes as well as code refactoring for future use. However, the above mentioned are in the case where a project has been accepted and ready to be implemented. What happens if you must create a simple POC for a client?

This, changes everything because you should ask whether you would need a proper 3-tier architecture for this, especially is the source is simple excel sheets. Therefore, in this case, a 1-tier architecture is warranted especially if the code will not be re-used and you just need to show the client some of the benefits of Qlikview. This is the elevator speech of Qlikview. It also highlights the power of Qlikview should get an App up and working relatively quick.

Another place where a 1-tier architecture can be used is when the source is already in a good schema state. Basically, when we do not need to make any transformations to data and would like to just display the data in the database in a business-friendly manner.
So back to the question of using a 1-tier architecture, the answer should be, “Sometimes when needed”.

Advantages
·        To get a POC off the ground

·        When there is limited data to analyse

·        Perfect to use when dealing with excel data

·        When just loading from one source data (When transformations are not needed)

Disadvantages
·        Depending on the data, performance could be impacted

·        Maintainability and re-use of the script could become complicated

·        Many points of failure without being able to know what exactly failed

·        Script could become complicated if transformations are needed to be done on the data

·        Transformations will impact overall user experience

Conclusion
In conclusion, there is a use for a 1-tier architecture. It is useful when conducting a potential POC as well as when the database is already in a good schema – sits on top of the database for visualization purposes - when all that is needed is to import data and use it to answer business questions visually. It is not useful when we need to conduct an ETL process because this could make the process cumbersome and make the code unreadable and difficult to maintain.

Tuesday, 30 May 2017

One Table To Rule Them All


Introduction


In Business Intelligence and data science there has always been this debate about whether a star schema is better than a snowflake schema or vice versa. This post, is not about that argument. This is a discussion that comes after the choice has been made. 

Once you have chosen whether to go star or snowflake, there is the next question which is: "Is there a case whereby lumping everything into the fact with a few dimensions is better than having a streamlined fact table with many dimensions? "

In this discussion, I will try arguing for both cases from my experience thus far. For my debate regarding star vs snowflake, you may want to look at:


Big Fact, few dimensions


Many people can argue to put everything into the fact table. This is not necessarily wrong per se. It takes all the hard work out of modelling correctly and making sure the data links together properly.
There is a case for this, the case to join everything into one gigantic, monstrous Fact table. 

For example: If the de-normalising of an ultra-normalised database makes it hard to de-normalise, the pressure is there to just lump almost everything into the Fact and have a few dimensions. There are advantages and disadvantages.

Advantages

-        All needed data is found in the Fact
-        It is easier to query one table for fields instead of having many hops through dimensions.
Disadvantages

-        Increases the size of the Fact table
-        Reduces performance of a dashboard
-        Reload time increases due to the huge volumes of the Fact table
-        Un used fields are loaded into the dashboard
-        Incorrect measures could be calculated due to potential duplicates arising from joins

Small Fact, Many Dimensions

 

As mentioned above, best practice is to have a Fact table with links/keys to dimensions and measures that will be used on the dashboard. The Business Intelligence tool, Power BI, does this well. Although other tools and cubes should also be built in this manner. Building your model like this also promotes a separation of concern. 

We should always keep in mind that dimensions are for describing entities. Just as we have in development, a class should describe an object so too we have in Data warehousing that dimensions describe entities and the Fact is used to link all of them together with its measures.

Advantages

-        The size of the Fact table is smaller
-        Performance of a dashboard is faster
-        Reload time decreases due to the low volumes of the Fact table
-        Un used fields are not loaded into the dashboard
-        Duplicates in Dimensions should not be allowed therefore more accurate measures

Disadvantages

-        Linking to the Fact table must be precise
-        Some measures could be incorrect if linking is not done well

Conclusion

 

In hindsight, it should be stated that that it is not best practice to do this. A Fact table should consist of several keys linking to different dimensions with many measures. This takes the burden off the fact table.
 

The dimensions should be used to describe an entity and the fact should be freed of this. The role of the Fact table should be to contain keys and measures. This measure will then be used to determine KPI’s on the front-end of the dashboard.

Modelling is 80% and creating the dashboard is only 20% of the whole work

Friday, 24 February 2017

Improving Performance In Qlikview Apps

Introduction

 

In all development areas, performance becomes an important consideration. Performance is a good efficiency measure that should be taken seriously. Some might say that just throw hardware at any performance issue and that will fix the issue but sadly that is not the case. Qlikview is a memory intense Business Intelligence tool itself and granted, throwing more memory at it would fix the problem but there are still many considerations to think about because you find in some organisations that budgets could be an issue so it’s important to streamline the model as much as possible.
In some cases, as the data grows, you find that there is a need to optimise your model but in principle, performance should be at the top of your agenda during development anyway.

Method 

 

To effectively get all the areas needed for performance improvement, we would need a way to see the metadata of the model. Effectively this is all the information such as tables, dimensions, expressions, etc. that would map to the total usage of memory used. Rob Wunderlich, has written a document analyser that would allow us to do this.


Steps:
1.     Go to: http://qlikviewcookbook.com/tools/#squelch-taas-accordion-shortcode-content-3 and download the QV Document Analyser.
2.     Store it anywhere on your disk but preferably, where the model is stored
3.     Create a copy, one that will have metadata before analysis and the other will have analysis after performance changes.
4.     Open the analyser and point it to the model you want to improve.
a.     In our case, we will be doing the Unit Testing model I built before.

Results

 

The data used for this test comes from the MySQL localhost sample data. There is roughly around 4000 rows in the largest table. Although the data is not substantial, it is enough to show the concepts that we are trying to pass through in this post. An increased sized data model would show this better.


Before Tuning


1.     The analysis took 5 seconds
2.     It took 1.3 seconds to open the document
3.     28 fields were used. (In Client models, you’d find a fair number of fields being loaded but never used)
4.     It takes 141 milliseconds to open an object
5.     Uses 1.07MB of RAM

 


 

As we can see with the recommendations, there are a few things we can do to improve this model and that is to autonumber two of the keys in the model. In a bigger model, the recommendations will be so much more, each showing the amount of memory you could save by implementing the changes.

 

 

 The memory used before the recommendations were implemented stood at: 1,118,049 bytes.

 

After Tuning

1.     The analysis took 5 seconds
2.     It took 1.3 seconds to open the document
3.     28 fields were used. (In Client models, you’d find a fair number of fields being loaded but never used)
4.     It takes 125 milliseconds to open an object
5.     Uses 1.07MB of RAM

 
 

The memory used after the recommendations were implemented now stands at: 1,117,571 bytes  



  

Analysis

 

The results above show the power of using the document analyser to improve your model. But this is just not the only way to improve performance. There are a number of other things that one can go about looking at to improve performance.


Remove Synthetic Keys

Synthetic keys are formed if there two or more tables have common columns exist. To solve this, we can rename the concerned fields, join the tables concerned or just not load the fields depending on the need of the model.


Use of Autonumber

“This script function returns a unique integer value for each distinct evaluated value of expression encountered during the script execution.” (https://help.qlik.com/en-US/qlikview/12.1/Subsystems/Client/Content/Scripting/CounterFunctions/autonumber.htm)
Using this function, we can create keys based on integers instead of strings or other data type that would use more system resources.


Model Towards a Star Schema

Although in some cases, there is a need for a snowflake schema because of the structure of the data, having a star schema greatly influences the performance of the model. This all has to do with the number of hops that Qlikview has to do. Please see: https://analyticsandeverythingelse.blogspot.co.za/2016/03/star-schema-vs-snowflake.html regarding hops.


Using Simple Expressions

It is worth noting that all complicated expressions should be done in the backend script, preferably in a Tier 2 model whereby all the heavy lifting will be done. The model will perform so much better if for example we had an expression such as: sum ({<isCalculated = {‘Yes’}>} Sales) instead of the whole calculation if isCalculated.


Dropping Temp tables and unused fields

By dropping unused fields and temporary tables, the model will remove these from memory and thus making it more efficient to use. If we load these, these will just reside in memory while not doing anything constructive to the overall usage of the model. Also, if left unattended, these could mess up your model and you could end up with a slow model.


Circular Loops

It is undesirable to have multiple common keys across multiple tables ia a Qlikview data structure. this may cause Qlikview to use Circular references to generate the connections in the data structure. Circular references are generally resource heavy and may slow down calculations and, in extreme cases, overload the application.To avoid this, we can:
  • Comment the fields in the load script
  • Rename the fields in the load script
  • Rename the fields using the UNQUALIFY operator

 

Conclusion

 

Performance is very important. In the case of Qlikview, this is important as Qlikview relies heavily memory. It is crucial that we do not build models that would otherwise kill over the machine. Having a lean, memory efficient model could be the difference in business making crucial decisions and being delayed due to the performance of an ill-designed model.

Thursday, 7 July 2016

NodeXL: A way to show engagement

Introduction

 

NodeXL Basic is a free and open-source network analysis and visualization software package for Microsoft Excel 2007/2010/2013/2016. (Wikipedia, 2016)

It is in short, a visualisation plugin for Microsoft Excel that takes data from different social media outlets and puts it together in groups depending on the user requirements. This helps in identifying gaps in businesses that rely on social media as a means for marketing. Using this tool, one can see who is exactly talking about their products/services/business and with this information, the company can target all those who are talking about the business and encourage them to influence all the others that are not talking about the business.

Setting Up 

  1. Go to the nodexl.org website and download the plugin. Find it at: https://nodexl.codeplex.com/downloads/get/806203. It automatically comes up a download link for NodeXL
  2. Once downloaded, double click on the file. This automatically puts it as a plugin in excel.

         3. To start, go to start->search and then type in "node" and it should show up as below

                 
 

 Getting Started

  1. Open the excel template for nodeXL.
  2. Wait for it to finish loading up. 
  3. Once the application has loaded, you should see the below:
 

    4. To start with your search for a trending topic, go to the NodeXL basic tab on the ribbon. Then choose import. See below:


   5. In the options, you will see where you should enter 1. the trending term, 2. Check if your already gave the application the chance to use your twitter settings and 3. the number of tweets to bring back. For the basic version, only maximum 2000 tweets are allowed. See below image:

    6. Press OK. This will take a while to populate all the relevant  sheets in the application. Once it is done with that,you can do some analysis. 1. Go to the NodeXL basic tab again then 2.graph Metrics. A dialog opens and in the dialog, choose select all and 4. Press Calculate Metrics. See Below:


    7. The next part is to group the data together. Go to 1. Groups and then 2. choose cluster. This will cluster all the data that is the same together. See Below:

     8. Then just press the show graph option on the ribbon in the NodeXL Basic tab on the ribbon. The initial graph you will see will be mashed up so you will need to add some more detail. As from the below image, to get something like this, you just have to play around with the Graph options as well as the layout options


Conclusion

NodeXL is a very useful tool for marketers of to find sentiment among a large network. It is not only limited to Twitter, it also caters for Facebook and Flicker as well.

In the above final image, we used the rocking ribs promo that Spur was using. As can be seen, there was a huge conversation and people tweeting about it. NodeXL also shows who is saying what and therefore, the concerned party can actually see what people are saying about their product.

Thursday, 23 June 2016

Heroes and villains – Different but the same

Introduction

 

In this post, I will be discussing something that is different from what I usually crap on about. This is something that has nothing to do with politics. Something to do with super heroes and most importantly, the villains. Villains are usually frowned upon. They are the evil that should be expunged from the earth and be put away somewhere far away where they cannot harm any innocence. But have you ever thought from the side of the villain? Usually we want and thrive when villains in movies and books are destroyed and killed but in comics, this is usually not the case.

Super heroes never want to take the lives of villains. There are a number of factored in my opinion that explain this phenomenon. For one, heroes need villains and villains need heroes. It is basically ying and yang, opposites of the same coin. Another reason is that, heroes understand villains, they sympathise with the villains on a level that we the innocent, would never understand. They know where the villains have been and they are willing to save them or try to save them. In this post, I will discuss both of these points of the hero vs villain.

Like Campbell’s hero journey, the hero goes through a number of transitions himself before he is who he is at the end of the journey. These stages are: “Departure”, “Initiation” and “Return”. These stages are for heroes and could equally be applied to the villain. The same stages that a hero goes through, a villain goes through but in the case of the villain, the opposite effect happens.


Campbell’s Hero Journey?

 

The hero journey has a total of 7 stages. These are categorised by the abovementioned stages. In the Departure stage, we have: The call to adventure, refusal of the call, supernatural aid, crossing the threshold and belly of the whale. 

The Initiation stage include: The road of trials, the meeting with the Goddess, Women as Temptress, atonement with the father, Apotheosis and the ultimate Boon. The Last category, Return, include: Refusal of the return, the magic flight, rescue from without, the crossing of the return threshold, master of two worlds and freedom to live. 

For the above, the original Star Wars trilogy is a good example as well as the first Matrix movie.
A whole essay could be written, and I have, on Campbell’s hero journey and it is important to read up on it if some of the things I cover do not make much sense. I briefly touched on it because it is important for analysis.


Who needs who?

 

So in this world of good versus evil. Who exactly needs whom? In my opinion, they need each other. Without villains, there can be no heroes. Without heroes, there can be no villains. And in fact, the more powerful the hero, the more powerful villain is needed. Think of it this way, if Spiderman only had petty thieves and care robbers to stop, he would never grow his powers. He could never grow in imagination and thinking. He would eventually get bored and be the villain himself. Without a challenge, one’s life becomes boring, uneventful and meaningless. We can all use this in our lives. Challenges and hardships are important in order for a person to grow.

The villain as well, needs the challenge of beating the hero. After every defeat, the villain learns from his mistakes and uses this to better himself. Albeit, an evil road, the villain does not see what he does as evil, instead, he sees this growth. As contributing to the very nature of life. Contributing to the balance that is the life. In conclusion, the hero needs the villain and vice versa. You cannot have one without the other.


Understanding the Villain

 

In most comics, the villain never truly dies. They always come back. It is only recently in comic book movies that the villain dies. This for all intents and purposes is a mistake by the movie makers. Heroes should never and don’t kill villains because truly, the heroes see themselves.

Let me explain what I mean with an example. Spiderman was born of his parents. His parents died and he was raised by his aunt and uncle. His uncle and aunt then became his moral centres where he could learn wrong from right. Imagine if instead of his aunt and uncle, Peter Parker was raised in an orphanage or by an uncle who abuses him all the time. Would he still be the same Peter we know who knows right from wrong?

In all the hero origins, the villains come from some place that is broken and eventually get to where they are. There is a deep seeded need for acceptance and belonging. The super hero understands this need and tries to show the villain the error of his ways. A good example of this is in Dragon Ball Z whereby Goku, no matter how evil his opponent, always tries to appeal to their good side. This is because he knows that the villain was not born that way, it is but circumstances that have led to this.

So next time you see a villain, remember that there could be a deeply soul crushing story that has led to that. Nobody is born evil, it the events in our lives that shape who we turn into. The same can be said about life. One’s life is shaped by their environment, if you were born with a silver spoon in your mouth, chances are, and you will go through life without so much challenges. But if you were born in a shack, life becomes harder and changing your circumstances, especially if you have no talent and are academically weak, becomes that much harder.

Conclusion

 

Villains are not born, they are made. From the moment we are born as humans, we face challenges that are contributed to by the environments that we are in. An environment can mould you into greatness, heroism or into a villainous life filled with pain and anguish. 

Villains can teach us many things about life. They are the model that shows us everything that is wrong with the world. Heroes come in and try to make the struggle of the villain more visible. Without heroes, villains would be somewhat unpresentable to the world. Villains and heroes indeed need each other, worthy villains bring out the best in heroes and vice versa.