예제 #1
0
def check_field_exists_in_table(table_name: str, field_name: str) -> None:
    if table_name in {
            # These are tables read by pipelines that are not in the sqlalchemy schema - skip this check
            "supervision_period_to_agent_association",
            "supervision_period_judicial_district_association",
            "state_race_ethnicity_population_counts",
            "us_mo_sentence_statuses",
            "persons_to_recent_county_of_residence",
            "incarceration_period_judicial_district_association",
            "state_race_ethnicity_population_counts",
    }:
        return

    matching_tables = {
        table
        for table in get_state_table_classes() if table.name == table_name
    }
    if not matching_tables:
        raise ValueError(f"No valid table with name: [{table_name}]")

    table = one(matching_tables)

    column_names = {
        sqlalchemy_column.name
        for sqlalchemy_column in table.columns
    }

    if field_name not in column_names:
        raise ValueError(
            f"Column {field_name} does not exist in table {table_name}.")
예제 #2
0
def check_field_exists_in_table(table_name: str, field_name: str) -> None:
    table = one({table for table in get_state_table_classes() if table.name == table_name})

    column_names = {sqlalchemy_column.name for sqlalchemy_column in table.columns}

    if field_name not in column_names:
        raise ValueError(f'Column {field_name} does not exist in table {table_name}.')
예제 #3
0
# Mapping from table name to a list of columns to be excluded for that table.
COUNTY_COLUMNS_TO_EXCLUDE = {
    'person': ['full_name', 'birthdate', 'birthdate_inferred_from_age']
}

######### STATE EXPORT VALUES #########

# History tables that should be included in the export
STATE_HISTORY_TABLES_TO_INCLUDE_IN_EXPORT = ['state_person_history']

# Excluding history tables
STATE_TABLES_TO_EXCLUDE_FROM_EXPORT = tuple(  # type: ignore
    # List tables to be excluded from export here. For example:
    # schema.FakePersonHistoryTable
    table for table in schema_utils.get_state_table_classes()
    if 'history' in table.name
    and table.name not in STATE_HISTORY_TABLES_TO_INCLUDE_IN_EXPORT)

# By default, all tables in the state schema.py module are exported
# unless listed in STATE_TABLES_TO_EXCLUDE_FROM_EXPORT above.
STATE_TABLES_TO_EXPORT = tuple(
    table for table in schema_utils.get_state_table_classes()
    if table not in STATE_TABLES_TO_EXCLUDE_FROM_EXPORT)

# As of right now, we aren't excluding any columns from the state schema export.
STATE_COLUMNS_TO_EXCLUDE: Dict[str, List[str]] = {}

STATE_BASE_TABLES_BQ_DATASET = 'state'