MAQL: Powerful Analytical Querying Made Simple
Tags: sql, analytics, docker, productivity
Published: 2021-11-29 16:05:28

If you are reading this you may know what MAQL is and want to know more or, alternatively, you may have never heard of MAQL but are keen to find out what it is. Either way, welcome and let me introduce you to MAQL.

## What Is MAQL?
MAQL is GoodData's analytical querying language, which simplifies querying over multidimensional data and provides predefined functions that allow simple queries, such as simple aggregations, or more complex functions like skewness or kurtosis.

You’re probably thinking that the same thing can be done using SQL, and you would be right, but MAQL makes it significantly easier. When you are carrying out multidimensional analysis using SQL, you have to be careful about querying and joining your data. MAQL, on the other hand, uses a semantic model that allows you to omit many of these things, making querying much easier. With this in mind, let me first tell you what the semantic model is and why it is essential.

## Semantic Model
When a database is being modeled, the first thing which is done is a conceptual model. The conceptual model is there for database architects to understand the structure of the database. MAQL uses this knowledge as well and calls it a semantic model. [The semantic model](https://www.gooddata.com/blog/deliver-efficient-data-consumption-semantic-model/?utm_medium=blogpost&utm_source=dev.to&utm_campaign=gooddatacn_maql_29112021&utm_content=autor_jan) is the same as the conceptual model for database architects: It gives MAQL the power and knowledge of the database, its attributes, and relationships between tables. The inside is very crucial for efficient and user-friendly querying of data. 

## MAQL Syntax and Usage
MAQL syntax is similar to SQL syntax but with one main difference; MAQL does away with keywords like FROM and JOIN. Why? Due to the presence of the semantic model, they are simply not required: The semantic model has the knowledge of relations and the occurrence of attributes. Let's take a look at an example.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ci9rtcp69vifq2usig10.gif)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ihisukozjq6ddcyz3fg.gif)

As can be seen in the above, MAQL significantly simplifies the querying process. All we need to know with MAQL is what we want to do: The rest is up to the MAQL engine, which uses the semantic model to query our data. A MAQL query is called a metric; an aggregation producing a single number.

Another crucial advantage of MAQL is that you can specify the "ground truth analysis" (i.e., single source of truth) of your data by creating and storing metrics. Stored metrics can be reused in other metrics, as can be seen below. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/97waul5tpd2l456alp21.png)

Another use for stored metrics is to provide results to other data consumers such as data analysts, data scientists, data engineers, and the relevant data consumption tools. The main idea can be seen in the picture below, where these tools access stored metrics using API, and all data consumers are using the same "ground truth analysis". This approach prevents the creation of duplicate analysis and simplifies work for data consumers.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oqkf369e5z9hd9u53109.png)

## Ready to Learn More?
MAQL forms part of the [headless BI](https://www.gooddata.com/headless-bi/?utm_medium=blogpost&utm_source=dev.to&utm_campaign=gooddatacn_maql_29112021&utm_content=autor_jan) family, with headless BI providing consistent, real-time insights to an array of different data consumers. To try out MAQL and see it in action, simply pull the GoodData.CN docker image. For help and further info, see the [MAQL documentation](https://www.gooddata.com/developers/cloud-native/doc/?utm_medium=blogpost&utm_source=dev.to&utm_campaign=gooddatacn_maql_29112021&utm_content=autor_jan), step-by-step tutorials, community forum, and community slack channel. I think it is worth trying it on demo data which are included in the docker image or your own data or any data you can find. Get as creative as you like.