Skip to main content
Skip table of contents

Creating Views

This section explains how to create a view in CData Virtuality by combining data retrieved from different database tables.

What is a View

In CData Virtuality, a view is a virtual table created by combining the results of queries from multiple data sources (e.g., a table in MySQL and a table in PostgreSQL). Views provide a way to unify and analyze data across diverse systems. This is how it works:

Diagram showing Customers data from MySQL and Orders data from PostgreSQL combined into a CustomersOrder virtual view in CData Virtuality.

The created view is stored within a schema space in CData Virtuality, making it accessible for further querying and analysis.

Creating a View

This guide provides step-by-step instructions to create a view in both the CData Virtuality Web Interface / SaaS and the Studio.

We use sample data to illustrate the process. For instructions on connecting to the sample data, please see the corresponding guide.

Creating a View in the CData Virtuality Web UI

  1. Open the Code Editor and click the View Builder button in the toolbar:

att_14_for_568787028.pngScreenshot showing a code editor with SQL statements for creating connections and data sources and a toolbar icon highlighted for creating a view
  1. In the View Builder window, click the Open a table selection dialog button in the menu on the left side:

att_4_for_568787028.pngScreenshot showing a view builder dialog with a table selection list including data sources virtual schemas and system schemas and an Add button
  1. The Table Selection screen will appear. Select the Customers table from MySQL and the Orders table from PostgreSQL, both available in the sample databases, and click the Add button:

att_5_for_568787028.pngScreenshot showing a table selection dialog with expanded MySQL and Postgres data sources and selected tables including Customers and Orders with an Add button visible
  1. Return to the View Builder screen. Confirm that the two tables, Customers (from MySQL) and Orders (from PostgreSQL), have been successfully added:

att_6_for_568787028.pngScreenshot showing the view builder canvas with Customers and Orders tables displayed side by side including column names and data types for each table
  1. Drag the customerid field in the Customers table and drop it onto the customerid field in the Orders table. The Join Setting screen will appear. Click the Save button, keeping the following default settings:

  • Join Type: Inner Join

  • "Customers" table column: customerid:integer, Cast

  • Operator: =

  • "Orders" table column: customerid:integer, Cast

    att_2_for_568787028.pngScreenshot showing join settings with an inner join configured between Customers and Orders using the customerid column
  1. Verify that a relationship has been successfully created between the Customers and Orders tables. Select the desired items (fields) to retrieve from Customers and Orders and click the Create View button in the left menu:

att_7_for_568787028.pngScreenshot showing a view builder canvas with Customers and Orders tables connected by a join on the customerid column
  1. Select the schema, enter a name for the view (e.g. CustomersOrder), and click the Create View button:

Screenshot showing the Create View dialog with schema selection and a view name entered for a joined Customers and Orders view
Screenshot showing a confirmation message indicating that the CustomersOrder view has been successfully created
  1. To retrieve the data from the created view, click the Browser tab -> Virtual Schemas -> Views in the left menu. Click on the three vertical dots on the right of the view name (e.g., CustomersOrder), and select Generate Statement from the context menu to retrieve the data:

Screenshot showing the context menu for the CustomersOrder view with options such as Set Permissions, Set Description, Generate Statement, Materialize, and Create New Job
  1. The following SQL will be generated in the Code Editor:

SQL
SELECT "customerid", "companyname", "address", "country", "city", "sector", "industry", "city_id", "orderid", "orderdate", "cost", "subtotal", "taxes", "total", "uuid_group", "segment" FROM "views.CustomersOrder";;
Screenshot showing a query editor running a SELECT query on the CustomersOrder view with the view columns listed in the browser panel and an empty results area below
  1. Click the Run Script button. The Result area will display the result of the combined data from the Customers table in MySQL and the Order table in PostgreSQL:

Screenshot showing a SELECT query executed on the CustomersOrder view with query results displayed in a table below the editor and multiple rows returned
  1. Click the Data Lineage button in the menu:

Screenshot showing a SELECT query on the CustomersOrder view with query results displayed and the Data Lineage button highlighted in the editor toolbar
  1. The Data Lineage screen will appear. It provides a graphical representation of the data sources from which the query (SELECT) retrieved the data:

Screenshot showing the Data Lineage diagram with a query connected to the CustomersOrder view and underlying Customers and Orders tables
  1. Close the Data Lineage screen and click the Query Plan button in the menu:

Screenshot highlighting the Query Plan button for the CustomersOrder query with query results displayed below
  1. The Query Plan screen will appear. It provides a graphical representation of the execution plan of the query. In this example, the query shows that the data retrieved from each table in the data source is joined using a MERGE JOIN during an INNER JOIN operation:

Query Plan diagram showing a ProjectNode followed by an inner join and two source access nodes for mysql and postgres data sources
  1. Close the Query Plan screen. In the Virtual Schema views section on the left side, click the three vertical dots on the right side of the view name, and select Edit from the context menu to modify the view:

Context menu for the CustomersOrder view with the Edit option highlighted, showing available actions such as permissions, materialization, and job creation.
  1. A new Code Editor tab will open and the following SQL will be generated. It can be modified as needed and executed to change the view definition:

SQL
CREATE OR REPLACE VIEW "views.CustomersOrder" AS 
  SELECT
  "Customers.customerid", "Customers.companyname", "Customers.address", "Customers.country", "Customers.city", "Customers.sector"," Customers.industry", "Customers.city_id", "Orders.orderid", "Orders.orderdate", "Orders.cost", "Orders.subtotal", "Orders.taxes", "Orders .total", "Orders.uuid_group", "Orders.segment".
  FROM
   "mysql.Customers" INNER JOIN "postgres.Orders" ON "Customers.customerid" = "Orders.customerid" 
  ;;

Creating a View in the CData Virtuality Studio

  1. Start the CData Virtuality Studio. From the Data Explorer on the left, open Virtual Schemas -> Views -> Tables / Views. If views have previously been created using the CData Virtuality Web UI, those views will be displayed. If no views are displayed, click the Refresh the views / Refresh the datasources button in the upper right corner to update the list:

This screenshot shows the CustomersOrder virtual view listed under the views virtual schema in the Data Explorer, confirming that the view was successfully created and is available in CData Virtuality Studio.
  1. Click the Open View builder icon in the upper toolbar menu:

This screenshot shows the CustomersOrder view selected in the Data Explorer, with its SQL definition displayed and the Open View Builder option highlighted for editing the view.
  1. Select Schema and enter a view name (e.g., CustomersOrder_builder). Please note that the view name must be unique:

This screenshot shows the View Builder dialog with the target schema and view name set, prompting the user to add at least one source table before creating the view.
  1. Click the + button to open the Create virtual views screen. Select the Customers table from MySQL and the Orders table from PostgreSQL, both provided as sample databases, and click the Add button:

This screenshot shows the table selection dialog where source tables are chosen to create a virtual view.
  1. Return to the View Builder screen. Confirm that the two tables, Customers (from MySQL) and Orders (from PostgreSQL), have been successfully added:

This screenshot shows the view builder with Customers and Orders tables added and ready for joining.
  1. Drag the customerid field in the Customers table and drop it at the location of the customerid field in Orders:

This screenshot shows configuring a join by linking the Customers and Orders tables using the customerid column.
  1. The Join Setting screen will appear. Click the Save button, keeping the following default settings:

  • Join Type: Inner Join

  • "Customers" table column: customerid:integer

  • Operator: =

  • "Orders" table column: customerid:integer

This screenshot shows the completed INNER JOIN between the Customers and Orders tables, based on matching customerid values.
  1. Verify that a relationship has been successfully created between the Customers and Orders tables. Select the desired items (fields) to retrieve from Customers and Orders and click the Create View button in the left menu:

This screenshot shows the View Builder with specific columns selected from the Customers and Orders tables to define the view output.
  1. When a dialog box appears confirming that the view was created successfully, click the OK button:

Confirmation dialog indicating that the virtual view CustomersOrder_builder has been created in the views schema.
  1. Click the Refresh current views button in the upper right corner of the Views window. Ensure that the newly created view is displayed in the list:

The refreshed view list shows both CustomersOrder and the newly created CustomersOrder_builder virtual views under the views schema.
  1. To retrieve the data from the created view, right-click the name of the created view (e.g., CustomersOrder_builder), and select Generate Statement from the context menu to retrieve the data:

The context menu for the CustomersOrder_builder virtual view, showing options such as viewing dependencies, lineage, generating a SELECT statement, materializing the view, and managing permissions.
  1. The following SQL will be generated in the Code Editor:

SQL
SELECT "customerid", "companyname", "address", "country", "city", "sector", "industry", "city_id", "iso3_country_code", "orderid", "Orders_ customerid", "orderdate", "cost", "subtotal", "taxes", "total", "uuid_group", "segment" 
FROM "views.CustomersOrder_builder";;; "order_name", "country", "city", "sector", "industry", "city_id", "iso3_country_code", "orderid", "Orders_Order_builder
The SQL Editor in CData Virtuality Studio displaying a SELECT query against the views.CustomersOrder_builder virtual view.
  1. Click the green Play button to run the script. The Result area will display the result of the combined data from the Customers table in MySQL and the Order table in PostgreSQL:

The SQL Editor in CData Virtuality Studio showing query results returned from the CustomersOrder_builder virtual view.
  1. Click the Data Lineage button in the menu. The Data Lineage screen will appear. It provides a graphical representation of the data sources from which the query (SELECT) retrieved the data:

Data lineage diagram for the CustomersOrder_builder virtual view, including the Customers and Orders source tables.
  1. Close the Data Lineage screen and click the Show Query Plan button in the menu. The Query Plan screen will appear. It provides a graphical representation of the execution plan of the query. In this example, the query shows that the data retrieved from each table in the data source is joined using a MERGE JOIN during an INNER JOIN operation.

  2. Navigate back to the Views list tab and select the created view. The definition of the view will be displayed in the Definition field:

SQL
CREATE OR REPLACE VIEW "views.CustomersOrder_builder" AS 
SELECT 
	"Customers.customerid", "customerid".
	"Customers.companyname", "Customers.
	"Customers.address", "Customers.address".
	"Customers.country", "Customers".
	"Customers.city", "Customers".
	"Customers.sector", "Customers.sector".
	"Customers.industry", "Customers".
	"Customers.city_id", "Customers.
	"Customers.iso3_country_code", "iso3_country_code".
	"Orders.orderid", "orderid".
	"Orders.customerid" AS "Orders_customerid", "Orders.
	"Orders.orderdate", "orderdate".
	"Orders.cost", "Orders.cost".
	"Orders.subtotal", "Orders.subtotal".
	"Orders.taxes", "Orders.taxes".
	"Orders.total", "Orders.total".
	"Orders.uuid_group", "Orders.
	"Orders.segment".
FROM 
	"mysql.Customers" INNER JOIN "postgres.Orders" ON "Customers.customerid" = "Orders.customerid"

See Also

Create View for more in-depth information on how to create a view

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.