How to automate interface view creation over base views
You can translate the document:Introduction
Interface views are used to abstract the underlying data model and provide a clear, reusable, and semantically meaningful representation of data to business users or downstream applications. They serve as a bridge between the technical details of data sources and the high-level requirements of users.
Why do we need interface views on top of base views?
- Changes in the structure or implementation of base views (e.g., adding fields or changing query logic) do not affect downstream consumers if they access data via interface views. The base layer remains protected from unexpected changes.
- When underlying data sources or schemas change, you only need to update the corresponding base views, while interface views can remain consistent. This modularity reduces the maintenance overhead and minimizes the risk of breaking business applications or dependent views.
- Consumers will no longer be required to be given access to the base views in order to create derived views. The interface views built on top of the base views can be used to build derived views on top of it. By granting access to interface views rather than base views, you ensure sensitive data remains protected.
- Defined Associations between Interfaces can help users understand your Data Model’s relationships and model in a self service way. It also allows the Query Plan Optimizer to do a better job
Automation is required when you are working in a scenario where you have hundreds of base views created in Denodo. Creating interface views for each base view can be very time consuming. Base interface views could be prefixed with “i_”, then, selection/derived views could be created on top of the base interface views which used the original name of the table - which is what end-users were currently referring to the views in Denodo by - to ensure consistency and mitigate any impact in how end-users were interacting with Denodo.
Let’s see how we can create an interface view on a set of base views.
- Create a folder to store interface views.
|
CREATE OR REPLACE FOLDER '/create_interface_views'; |
- Create a view using the stored procedure get_view_columns().
|
CREATE OR REPLACE VIEW view_columns FOLDER = '/create_interface_views' AS SELECT * FROM get_view_columns(); |
- Create another view using the view created in the previous step.
|
CREATE OR REPLACE VIEW interface_view_columns FOLDER = '/create_interface_views' AS SELECT view_columns.input_database_name AS input_database_name, view_columns.input_view_name AS input_view_name, view_columns.database_name AS database_name, view_columns.view_name AS view_name, view_columns.column_name AS column_name, view_columns.column_vdp_type AS column_vdp_type, view_columns.column_sql_type AS column_sql_type, view_columns.column_sql_type_code AS column_sql_type_code, view_columns.column_size AS column_size, view_columns.column_decimals AS column_decimals, view_columns.column_radix AS column_radix, view_columns.column_is_primary_key AS column_is_primary_key, view_columns.column_is_nullable AS column_is_nullable, view_columns.column_remarks AS column_remarks, view_columns.column_is_autoincrement AS column_is_autoincrement, view_columns.column_is_generated AS column_is_generated, view_columns.ordinal_position AS ordinal_position, view_columns.column_vdp_type_database AS column_vdp_type_database, (((view_columns.column_name||':')||view_columns.column_vdp_type)||coalesce(((((((((' (sourcetypedecimals = '''||column_decimals)||''', sourcetyperadix = ''')||column_radix)||''', sourcetypesize = ''')||view_columns.column_size)||''', sourcetypeid = ''')||view_columns.column_sql_type_code)||''')'), ' ')) AS interface_columns FROM view_columns; |
- Now, we will create our final view on top of the view created in step 3 which will generate the VQL for the interface views on top of given base views.
|
CREATE OR REPLACE VIEW interface_vql FOLDER = '/create_interface_views' DESCRIPTION = 'The interface_vql view is designed to facilitate the bulk creation of interface views based on existing base views. It provides VQL output that can be executed or imported to create these derived views. The view is configured to generate interface views prefixed with "i_" from base views prefixed with "bv_". It includes fields to specify the target view name, database, and folder, as well as the implementation view and database name. This view could be used for automating the process of generating multiple interface views in a structured and efficient manner. By providing VQL statements for the creation of these views, it streamlines workflows for users needing to establish consistent interface views across various databases and folders.' AS SELECT (((((((((('CREATE OR REPLACE INTERFACE VIEW i_'||substring(target_view_name, 3))||' (')||group_concat(', ', interface_view_columns.interface_columns))||') SET IMPLEMENTATION ')||interface_view_columns.database_name)||'.')||interface_view_columns.view_name)||' ')||coalesce((('FOLDER = '''||target_folder_name)||''''), ''))||';') AS create_interface_view_vql, target_view_name, target_database_name, target_folder_name, implementation_view_name, implementation_database_name FROM interface_view_columns WHERE (implementation_view_name = input_view_name AND implementation_database_name = input_database_name) GROUP BY interface_view_columns.database_name, interface_view_columns.view_name, target_view_name, target_database_name, target_folder_name USING PARAMETERS ( target_view_name : text, target_database_name : text NULL, target_folder_name : text NULL, implementation_view_name : text, implementation_database_name : text); |
- To create base interface views, from a given set of base views, execute the following in a VQL Shell:
|
SELECT create_interface_view_vql FROM interface_vql a INNER JOIN GET_VIEWS() b ON a.target_view_name = b.name AND b.name = a.implementation_view_name AND b.database_name = a.implementation_database_name WHERE target_folder_name = '<FOLDER_TO_PLACE_TARGET_VIEWS>' AND target_database_name = '<DATABASE_TO_PLACE_TARGET_VIEWS>' and b.folder = '<FOLDER_TO_FIND_SOURCE_VIEWS>'; |
- For example, let’s create interface views VQL over base views stored under admin virtual database:
- The output VQL can be copied and executed in the target virtual database. You can also use Denodo Scheduler to automatically execute this VQL over a VDP server.
References
The information provided in the Denodo Knowledge Base is intended to assist our users in advanced uses of Denodo. Please note that the results from the application of processes and configurations detailed in these documents may vary depending on your specific environment. Use them at your own discretion.
For an official guide of supported features, please refer to the User Manuals. For questions on critical systems or complex environments we recommend you to contact your Denodo Customer Success Manager.
