Denormalizing Models
The denormalization process (SQL to NoSQL model conversion) embeds one or more objects into other objects based on the following logic:
-
One-to-one relationships are converted to Object datatype.
-
One-to-many relationships are converted to an ArrayOfObject datatype.
You can also denormalize models when you derive a new model from an existing model.
This section walks you through the denormalization process and its outcome for the conversion of SQL models to NoSQL models. For example, the following process demonstrates the conversion of the standard SQL model, eMovies to a MongoDB model.
To denormalize models, follow these steps:
-
Open your SQL model.
In this example, navigate to C:\Program Files\erwin\Data Modeler r10\BackupFiles\Samples\Standard and open the eMovies model.
Observe that the physical model contains 9 tables and 20 relationships.
The logical model has 9 entities and 13 relationships.
-
In the Physical view mode, on the ribbon, click Actions > Target Database.
-
Change the Database from SQL Server to MongoDB and click OK.
The embedding process starts.
After the embedding process completes, the eMovies model is converted to a MongoDB model. Based on the relationships in the SQL model, the parent-child embedding process occurs. Based on this process, the MongoDB physical model has 4 collections and 0 relationships.
The logical model retains relationships and does not contain any hierarchical datatypes. Thus, keeping the logical and physical models completely separate.
To summarize, post denormalization process, the logical model remains as a normalized model, whereas the physical model is converted to it denormalized form.
Logical to Physical Model Denormalization
Due to the complete logical-physical model separation, the logical mode always maintains the normalized form and the physical side always maintains the denormalized form. Whenever you switch from the logical model to the physical model, the model is auto-denormalized, and based on parent-child relationships in the logical model, the embedding process runs.
For example, consider the following logical MongoDB model.
In this model:
-
E/1 and E/2 have a non-identifying parent-child relationship with its cardinality set to Zero, One or More.
-
E/1 and E/3 have a non-identifying parent-child relationship with its cardinality set to Zero or One (Z).
Now, when you switch to the physical model, auto-denormalization occurs. Based on the parent-child relationships in the logical model, E/2 and E/3 are embedded into E/1.
One-to-one relationship is converted to Object datatype and one-to-many relationship is converted to an ArrayOfObject datatype.
Also, any changes you make to the logical model are maintained in the physical model and vice-a-versa.
DynamoDB
The conversion logic applied to DynamoDB models is:
-
One-to-one relationships are converted to Map datatype.
-
One-to-many relationships are converted to List datatype.
Parquet
The conversion logic applied to Parquet models is:
-
One-to-one relationships are converted to Record/Struct datatype.
-
One-to-many relationships are converted to Record/Struct datatype with the Mode set to Repeated/Array
Exceptions in Google BigQuery
The conversion logic applied to Google BigQuery models is:
-
One-to-one relationships are converted to Record/Struct datatype.
-
One-to-many relationships are converted to Record/Struct datatype with the Mode set to Repeated/Array.
Also, as Google BigQuery supports relationships when you switch from the logical model to physical model, auto-denormalization is not performed. However, this scenario has an exception. For example, consider a physical model as shown in the following image.
Switch to the logical model and add a relationship between E/2 and E/3. In this scenario, when you switch to physical model, auto-denormalization will be performed as E_2 does not exist in the physical model as a separate table.
Similar to denormalizing SQL models to NoSQL models by changing the target database, you can denormalize Amazon Keyspaces and Cassandra models using the Denormalization feature.
This section walks you through the denormalization options for a Cassandra model. To denormalize models, follow these steps:
-
Open your model.
-
On the ribbon, click Action > Denormalization.
This option is supported for Amazon Keyspaces and Cassandra.
The Denormalization Wizard appears.
-
In the Tables section, click the Target drop-down to select a target table. All the tables will be merged into the selected target table.
Select the Auto Denormalization option to merge tables with the target automatically. This embeds the tables in the model with one-to-one relationships as User Defined Type and one-to-many relationships as normal columns. If you use this option, do not configure any options on the Columns and Options tab. Click OK.
-
Under Available Tables, select one or more tables to merge. Then, click .
This moves the selected tables under Selected Tables.
-
Click Next.
The Columns section appears. It displays a list of available columns. -
Under Available Columns, select the columns that you want to merge. Then, click .
This moves the selected columns under Selected Columns section.
Once you have added the selected columns, you can use any of the following options:
- Merge ()
-
Use this option to merge the selected columns and create a new column under Selected Columns.
- Update ()
-
Use this option to edit column details such as column name, domain parent, and data type for a selected column.
- New ()
-
Use this option to add a new column under Selected Columns.
- Delete ()
-
Use this option to delete the selected columns.
-
Click Next.
The Options section appears. -
Select an Embedding Type.
You can select the following embedding options:
-
Embed as Auto: Use this option to embed tables through an auto-mechanism based on one-to-many and one-to-one relationships
-
One-to-many relationships are converted to normal columns.
-
One-to-one relationships are converted to User Defined Type (UDT) columns.
-
-
Embed as Normal: Use this option to embed collections using normal column styles.
-
Embed as UDT: Use this option to embed collections using UDT styles.
-
-
Select Relationships option to include table relationships to the model.
Relationships and Auto Cleanup options are mutually exclusive. As a best practice, always select only one of the options.
-
Select Cascading options to determine how multiple collections are merged into a single collection.
Use the following cascading options:-
All: Use this option to denormalize all relationship levels in a collection into a single collection.
-
Levels: Use this option to specify the number of levels up to which collections are denormalized into one collection. For example, if you set Level to 1, all the collections up to level 1 in the relationship hierarchy will be denormalized into a single collection.
-
Auto Cleanup: This option removes child collections after denormalization.
Relationships and Auto Cleanup options are mutually exclusive. As a best practice, always select only one of the options.
-
-
Click OK.
The denormalization process starts and displays objects based on selected options.
Alternatively, you can click Commit to apply changes to the model without exiting the Denormalization Wizard.
Copyright © 2024 Quest Software, Inc. |