❖ Oracle

If your data is available in an Oracle database, you can directly connect to it in order to extract the data and metadata. Later, you can use the same connections to write the data back to a database.

We support the following database versions: Oracle 18c, Oracle 19c, Oracle 21c, and Oracle 23ai.

Installation

SDV Enterprise Bundle. This feature is available as part of the AI Connectors Bundle, an optional add-on to SDV Enterprise. For more information, please visit the AI Connectors Bundle page.

To use this feature, please make sure you have installed the bundle with the optional db-oracle dependency. For more information, see the SDV Enterprise Installation guide.

pip install -U bundle-ai-connectors[db-oracle] --index-url https://pypi.datacebo.com

* OracleConnector

Use this connector to create a connection to your database.

from sdv.io.database import OracleConnector

connector = OracleConnector()

Parameters (None)

Output A connector object that you can use to import data and metadata

Importing Real Data

Import your real data from a database to use with SDV.

* set_import_config

Use this function to authenticate into the project and database you'd like to import from.

connector.set_import_config(
    auth={
        ...
    },
    schema_name='my_schema_name'
)

Parameters

  • (required) auth: A dictionary with your authentication credentials (for details, see Authentication)

  • schema_name: A string with the name of your schema. Please add this if your database tables are in a named schema.

    • (default) None: You can omit this parameter if you have not set up a schema name. In this case, the connector will use whatever schema name your database assigns as a default. For Oracle, this is your username.

Output (None)

* create_metadata

Use this function to create metadata based on the connection to your database.

metadata = connector.create_metadata(
    table_names=['users', 'transactions', 'sessions'])

Parameters

  • table_names: A list of strings representing the table names that you want to create metadata for

    • (default) None: Create metadata for all the tables in the database

  • infer_sdtypes: A boolean describing whether to infer the sdtypes of each column

    • (default) True: Infer the sdtypes based on the data

    • False: Do not infer the sdtypes. All columns will be marked as unknown, ready for you to manually update

  • infer_keys: A string describing whether to infer the primary and/or foreign keys. Options are:

    • (default) 'primary_and_foreign': Infer the primary keys in each table, and the foreign keys in other tables that refer to them

    • 'primary_only': Infer only the primary keys of each table

    • None: Do not infer any keys

Output A Metadata object representing your metadata

* import_random_subset

Use this function to import a random subset of your data from the database and inferred metadata. The size of the subset is automatically determined.

data = connector.import_random_subset(
    metadata=metadata,
    verbose=True
)

Parameters

  • (required) metadata: A Metadata object that describes the data you want to import

  • fixed_seed: A boolean that controls the determinism of the random subset

    • (default) False: Different random data will be imported every time you call the function

    • True: The same data will be imported every time you import

  • verbose: A boolean describing whether to print out details about the progress of the import

    • (default) True: Print out the table names and number of rows being imported

    • False: Do not print any details

Output A dictionary that maps each table name of your database (string) to the data, represented as a pandas DataFrame.

* import_optimized_subset

Use this function to import a subset of your data, optimized specifically for a given table. You can also control the size.

data = connector.import_optimized_subset(
    metadata=metadata, 
    main_table_name='users',
    num_rows=5000
)

Parameters

  • (required) metadata: A Metadata object that describes the data you want to import

  • (required) main_table_name: A string containing the name of the most important table of your database. This table will generally represent the entity that is most critical to your application or business. It must be one of the tables listed in your metadata object.

  • num_rows: The number of rows to sample from the main table. The size of every other table is automatically determined by its connection to the main table.

  • fixed_seed: A boolean that controls the determinism of the random subset

    • (default) False: Different random data will be imported every time you call the function

    • True: The same data will be imported every time you import

  • verbose: A boolean describing whether to print out details about the progress of the import

    • (default) True: Print out the table names and number of rows being imported

    • False: Do not print any details

Output A dictionary that maps each table name of your database (string) to the data, represented as a pandas DataFrame.

After importing the data and metadata, you are now ready to create an SDV synthesizer.

Exporting synthetic data

Export synthetic data into a new database.

* set_export_config

Use this function to specify which project and database you'd like to export data to. Also provide your authentication credentials.

connector.set_export_config(
    auth={
        ...
    },
    schema_name='my_schema_name',
)

Parameters

  • (required) auth: A dictionary with your authentication credentials (for details, see Authentication)

  • schema_name: A string with the name of your schema. Please add this if your database tables are in a named schema.

    • (default) None: You can omit this parameter if you have not set up a schema name. In this case, the connector will use whatever schema name your database assigns as a default. For Oracle, this is your username.

Output (None)

* export

Use this function to export your synthetic data into a database

connector.export(
    data=synthetic_data,
    mode='write',
    verbose=True)

Parameters

  • (required) synthetic_data: A dictionary that maps each table name to the synthetic data, represented as a pandas DataFrame

  • mode: The mode of writing to use during the export

    • (default) 'write': Write a new database from scratch. If the database or data already exists, then the function will error out.

    • 'append': Append rows to existing tables in the database

    • 'overwrite': Remove any existing tables in the database and replace them with this data

  • verbose: A boolean describing whether to print out details about export

    • (default) True: Print the details

    • False: Do not print anything

Output (None) Your data will be written to the database and ready for use by your downstream application!

FAQ

Authentication & Credentials

Provide an auth dictionary with your credentials. See below for the required keys and values.

How do you pass auth credentials?

Instructions (recommended approach): Provide a dictionary with your credentials. See below for the required keys and values.

connector.set_import_config(
    schema_name='my_schema_name',
    auth={
        'username': 'my_username', # required
        'password': 'my_password', # required
        'dsn': 'my_dsn' # required
    }
)

Instructions (alternative approach): Instead of providing all the different key-value pairs, you can also create a connection string to pass in your credentials.. For more information, see Oracle's Easy Connect syntax.

connector.set_import_config(
    schema_name='my_schema_name',
    auth={
         'connection_string': 'user:password@hostname:port/?service_name=service_name_string'
    }
)

If you are providing a connection string, please do not include the prefix (oracle+cx_oracle://).

Other FAQs

Which permissions are needed for importing and exporting?

Importing data requires read access. For importing data, you'll need access for running the following commands: CREATE SESSION, SELECT, and SELECT ON SYS.DBA_USERS.

Exporting data requires write access. For exporting data, you'll need the same access as importing plus access for following commands: INSERT ANY, ALTER ANY, DROP ANY, and RESOURCE.

For more information, see the Oracle SQL reference guide.

Last updated