Physical Table Alias
In Oracle Analytics, you can create aliases for tables in the physical layer of your semantic model. Table aliases are useful when a single table has several different roles in the semantic model.
Best Practices
A single table often has multiple roles. Sometimes a table is used as a dimension, sometimes as a fact table, sometimes to extend another dimension to retrieve a specific attribute, and sometimes as a helper table to join two other tables together.
Often, each role comes with a different set of physical joins. If you configure all the joins on a single instance of the table, it results in data integrity issues. You can avoid such issues, if you use table aliases and follow some basic rules.
-
Use a consistent naming convention for aliases
The alias name should include both the name of the original table, and some indication of the role of the alias. This way on first sight, developers immediately know which table is being used and understands the purpose of the alias.
-
Don’t define any physical joins on the original table
Start by creating an alias. Each physical table should always have at least one alias. Only the alias will be used, not the original table. This way if you need new instances of the same table for other roles in the future, it’s easy to identify the differences and roles of each alias.
-
Create additional aliases when you need different physical joins depending on the context in which a table is used
Here are two common examples
Example 1
Description of the illustration ceal_table_alias_example1.jpgExample 1 shows an implementation of the Employee table. Table
W_MARKET_D
includes the key of the employee who is theMarket Manager
. TableW_PRODUCT_D
includes the key of the employee who is theProduct Manager
. Without any alias, tableW_EMPLOYEE_D
joins to bothW_MARKET_D
andW_PRODUCT_D
. If you create a report that selects the name of both theMarket Manager
andProduct Manager
, theWHERE
clause generated in the physical SQL would include the following statements:W_MARKET_D.EMP_ID=W_EMPLOYEE_D.ID
andW_PRODUT_D.EMP_ID=W_EMPLOYEE_D.ID
This means that the ID of the employee must at the same time equal the
Market Manager
ID andProduct Manager
ID. This isn’t possible because these managers are two different employees, so the query doesn’t return any records.Instead, as described on the diagram above, the solution is to have two aliases of the
Employee
table. One alias is joined with theMarket
table and the other is joined to theProduct
table. These two aliases are considered as if they are two different tables, completely independent from each other. By using two aliases, there is no conflict between the two joins.Example 2
Example 2 shows three tables. Table
W_ORDER_F
is used as a fact table for order metrics, a dimension for order attributes, and it includes theOrder Date
. There is also calendar tableW_DAY_D
, and invoice tableW_INVOICE_F
that includesOrder ID
andInvoice Date
. The invoice table is joined to the order table to retrieve order attributes as a dimension forInvoice Fact
metrics. Note that Oracle Analytics generates separate sub-queries for each fact table. Therefore, we must considerOrder Fact Star
andInvoice Fact Star
separately, as shown in the diagram.Without any aliases, the diagrams look like this:
Description of the illustration ceal_table_alias_example2.jpgThis configuration causes similar data integrity issues to the Employee example, that is, the
Order Date
is not equal toInvoice Date
but they are both joined to the same date column on the calendar table.The solution is to create two aliases for the Order table, one alias for the fact and the second alias for the dimension. With aliases, the diagrams look like this:
Description of the illustration ceal_table_alias_example2_with.jpgNow there's no conflict between the joins, as the dimension alias of the Order table is not joined to the calendar dimension.
Also note that there’s no need to join
Fact_W_ORDER_F
withDim_W_ORDER_D
. Except for rare specific situations, you should never join two aliases of the same table together. While doing so doesn’t impact data integrity, it does impact performance and it’s useless.Instead, create two logical table sources in the
Order Dimension
in the business model. Use one logical table source for theInvoice Fact Star
and the other for theOrder Fact Star
.
Description of the illustration ceal_table_alias_logical_tables.jpg
Summary
- Always create at least one alias for each physical table.
- If needed, create additional aliases based on the different roles of the table in your model and the different types of joins you require.
- Although there are exceptions, in most cases you shouldn’t join two aliases of the same table together.