Skip to main content
Version: 0.17.19

Manage SQL Data Assets

A Data Asset is a collection of records within a Data Source that define how Great Expectations (GX) organizes data into Batches. Use the information provided here to connect GX to SQL tables and data returned by SQL database queries and learn how to organize Batches in a SQL Data Asset.

Great Expectations (GX) uses SQLAlchemy to connect to SQL source data, and most of the SQL dialects supported by SQLAlchemy are also supported by GX. For more information about the SQL dialects supported by SQLAlchemy, see Dialects.

Datasources defined with the block-config method

If you're using a Data Source created with the block-config method, see How to configure a SQL Data Source with the block-config method.

Connect to a SQL table

Connect GX to a SQL table to access source data.

The following code examples use a previously defined Data Source named "my_datasource" to connect to a SQL database.

Prerequisites

Import GX and instantiate a Data Context

Run the following Python code to import GX and instantiate a Data Context:

import great_expectations as gx

context = gx.get_context()

Retrieve a SQL Data Source

Run the following Python code to retrieve the Data Source:

datasource = context.get_datasource("my_datasource")

Add a table to the Data Source as a Data Asset

You create a Data Asset to identify the table to connect to.

Run the following Python code to define the name and table_name variables:

table_asset = datasource.add_table_asset(name="my_asset", table_name=my_table_name)

Add additional tables (Optional)

To connect to additional tables in the same SQL Database, repeat the previous steps to add them as table Data Assets.