how to retrieve the structure of an OLAP cube - mdx

I have access to an OLAP catalog, but I am not familiar with MDX. I am looking for the MDX equivalent of SQL:
SHOW DATABASES;
SHOW TABLES;
I was looking at MDX language reference, but I could not find a way of getting the schema, the cube metadata. Thanks for helping.

You can use the $SYSTEM database to query your objects.
Use SELECT * FROM $SYSTEM.DISCOVER_SCHEMA_ROWSETS to get a list of things you can query. In your case it would most likely be DBSCHEMA_CATALOG, DBSCHEMA_TABLES and MDSCHEMA_CUBES.
This is very rough information, and using stuff like Preet suggests might be favorable in the end.

There is answer List dimension members with MDX query to show how list dimensions.
This open source project (TSSASM) shows how to query access the cube structure from a TSQL database.
However I think you may need XMLA commands to see what you need.

Related

How do we know if aggregations on the SSAS cube are unused?

Sql server version: 2016
Is there a way to know if aggregation on the cube is unused ? I have tried to get the information on the DMVs $system.discover_object_activity (gives me count of aggregations on a partitions/measure groups being hit or missed) and $system.discover_partition_stat (aggregation name and its processed state). I have read articles on SSAS specific DMVs and challenges in joining the DMVs to get combine data from DMVs to get useful information. But I am not able to get information if a aggregation is left unused, like a list of aggregations which have been used/unused
The cube which is being investigated has over 200 aggregations. It is cumbersome to manually go through each one of them and check for the combinations. Any help is appreciated.

How to represent an SQL query graphically

I have a SQL Select query with many joins between tables, I want to know which kind of diagram could represent it graphically in order to visualise the joins between tables and their types (differentiate between INNERs and LEFTs) ?
I did this simple schema to represent my query but I'm searching for a known and better type of diagram :
I believe what you're looking for is a variation of an Entity Relationship Diagram, where the different line-ends indicate the relationship type. When structuring a database, I believe this type of model is most common and easily understood.
You can use crow's foot notation for Enitity Relationship Diagram where you can specify the relationship(one to many, one to one) as well as the optionality(enitityA has exactly one of enitityB OR enitityA has 0 or 1 of enitityB). In your case optionality might represent the type of join you need to do. Why exactly you need to specify the join types in an ERD?
I'm baffled why this isn't something that exists already, and even more baffled why more developers aren't screaming their heads off demanding this. There is an undeniable need for dynamically created visual representations of sql queries. Trying to understand a single 300 line sql procudure is difficult enough without column names obfuscating their business representation using names like "AsecRemFortsKilnNumAttr".
When there are hundreds of columns in a procedure with names like this, but subtly different, like "AsecRemAgsKilnNumAttr" and "AsecRemFortsKilnNumV" as well then the task is impossible.
Anyway, here are a couple I've found: -
https://sqldep.com/sql-parser/
http://queryviz.com/
https://sourceforge.net/projects/revj/
The last one contains a Python utility that you can use to improve and extend if you know how.
Other than that the only other tool that may allow what you're looking for is Informatica Developer 10 which allows you to create a mapping from imported sql queries.
SQL queries are usually represented in tree form, structured based on how the query is parsed (logical plan) or how the query engine will execute the query (physical plan)
See abstract syntax tree (AST) https://en.wikipedia.org/wiki/Abstract_syntax_tree as an example

Advice on creating analytical query (SQL) generator

We are migrating from Microsoft's Analysis Services (SSAS) to HP Vertica database as our OLAP solution. Part of that involves changing our query language from MDX to SQL. We had a custom MDX query generator which allowed others to query for data through api or user interface by specifying needed dimensions and facts (outputs). Generated MDX queries were ok and we didn't have to handle joins manually.
However, now we are using SQL language and since we are keeping data in different fact tables we need to find a way how to generate those queries using same dimension and fact primitives.
Eg. if a user wants to see a client name together with a number of sales, we might take a request:
dimensions: { 'client_name' }
facts: { 'total_number_of_sales' }
and generate a query like this:
select clients.name, sum(sales.total)
from clients
join sales on clients.id = sales.client_id
group by 1
And it gets more complicated really quickly.
I am thinking about graph based solution which would store the relations between dimension and fact tables and I could build the required joins by finding shortest path between the nodes in a graph.
I would really appreciate any information on this subject including any keywords i should use searching for a solution to this type of problem or 3rd party products which could solve it. I have tried searching for it, but the problems were quite different.
You can use free Mondrian OLAP engine which can execute queries written in the MDX language on the top of relational database (RDBMS).
For a reporting you can try Saiku or Pentaho BI server on the of Mondrian OLAP.

Why use sql language instead of mdx language in ssrs?

I was looking at pluralsight´s SSRS-training and they used regular sql to get data to the datasets. I am just learning mdx and when I work with datasets I so far only use mdx to get data. Should/could I mix this, should I use SQL instead of mdx? I don´t want to, now that I started to enjoy mdx..
MDX is often used against multidimensional cubes and have some commands specifically for this purpose which SQL does not have. If your datasource is a database, and not a cube however SQL is most commonly used as far as I know.
Comparison of SQL and MDX: http://msdn.microsoft.com/en-us/library/aa216779%28v=sql.80%29.aspx
MDX language = OLAP Cubes (SSAS)
SQL language = Relational databases.
OLAP cubes are used for reporting and performance reasons. When data or information is needed and it involves large aggregations of data or calculations of large amounts of data from a relational database, a OALP cube can be created to sometimes better handle the demands of the data requirements. MDX is the query language used to pull data from the cube.
Here's an example to help. You need to pull some data for a report. You could use a SQL statement or a cube (MDX) for this data. You test using a SQL statement, but the query takes 5 minutes to run. Or with a cube, you could add the equivalent of the SQL statement into the cube design where it will make the equivalent of the SQL query results available instantly. How is this possible? Cube's are relational databases full of pre-run calculations and aggregations of data. Pre-run, meaning they were run or processed at some earlier time, likely at night when everyone was home.
MDX is specific to only one reporting program, SQL Server Reporting Services (SSRS). SQL is tied to multiple different database programs. Usually people who know MDX are already an expert or very familiar with SQL. I'd learn SQL first since there are many more applications for it than MDX>

Mixing MDX Drillthrough statement and SQL joins

I want to use an MDX drill through command but i also want to join it to some SQL tables as well.
that is there will be an Id in the fact table and not a lot of other data I want to join this on to another table or view and produce a report based on those ID's returned in the drill down.
Ideas?
MDX won't do this directly. The only way I can think of doing this would be to retrieve the recordset from the drillthrough (which can be done with ADO), load it into a temporary table and join it against whatever else you want in a query.
The other option is to widen the drillthrough (if the dimensions have the data you need) and get the fields from that. Note that SSAS2005+ can support multiple drillthrough actions.
This MSDN article has some code snippets that demonstrate working with record sets returned from a drillthrough.