natural_view_builder

class NaturalViewBuilder(xwalk_directory: str = './schema-xwalks/consolidated_and_validated')

A class used to build natural views for a database using crosswalks.

Parameters:

xwalk_directory (str) – The directory where the crosswalk files are stored. Defaults to “./schema-xwalks/consolidated_and_validated”.

Variables:
  • nat_label_lookup (dict) – A dictionary mapping naturalness levels to their labels.

  • nat_num_lookup (dict) – A dictionary mapping naturalness labels to their levels.

NaturalViewBuilder.initialize_db_nl_schema(database_name: str) None

Initializes the natural language schema in the specified database.

This method performs the following steps:

  1. Executes the SQL script to create the natural language schema.

  2. Executes the SQL script to create a within-database naturalness crosswalk

Parameters:

database_name (str) – The name of the database where the schema will be initialized.

Raises:

ProgrammingError – If there is an error executing the SQL script to create the schema.

Returns:

None

NaturalViewBuilder.populate_db_nl_tables(database_name: str, xwalk_directory: str = None) None

Populates the database natural language tables with cross-references between native and natural identifiers for tables and columns.

Parameters:
  • database_name (str) – The name of the database to populate.

  • xwalk_directory (str, optional) – The directory where the crosswalk Excel file is located. If not provided, defaults to self.xwalk_directory.

Returns:

None

NaturalViewBuilder.create_views_in_database(database_name: str, naturalness_level: str = None) None

Creates views in the specified database. If a naturalness level is provided, it creates a schema for that level and builds the views within that schema. Otherwise, it builds the views in the default schema.

Parameters:
  • database_name (str) – The name of the database where views will be created.

  • naturalness_level (str, optional) – The level of naturalness for the views. Defaults to None.

Returns:

None

NaturalViewBuilder.build_natural_view_queries(database_name: str, target_schema: str = 'dbo', xwalk_directory: str = None, view_schema_name: str = 'db_nl', naturalness_level: str = 'N1', xwalk_df: pandas.DataFrame = None) list

Builds SQL queries to create natural views for tables in a SQL Server database.

Parameters:
  • database_name (str) – The name of the database to query.

  • target_schema (str, optional) – The schema of the target tables. Defaults to “dbo”.

  • xwalk_directory (str, optional) – The directory containing the crosswalk files. Defaults to None.

  • view_schema_name (str, optional) – The schema name for the views. Defaults to “db_nl”.

  • naturalness_level (str, optional) – The level of naturalness for the identifiers. Defaults to “N1”.

  • xwalk_df (pandas.DataFrame, optional) – The crosswalk dataframe. If None, it reads from the Excel file. Defaults to None.

Returns:

A list of SQL view creation queries.

Return type:

list