Skip to main content
Version: 0.18.21

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 Data Assets, 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.

Connect to a SQL table

Connect GX to a SQL table to access Data Assets.

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:

    Python
    import great_expectations as gx

    context = gx.get_context()

    Retrieve a SQL Data Source

    Run the following Python code to retrieve the Data Source:

    Python
    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:

    Python
    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.