healthcareai-py icon indicating copy to clipboard operation
healthcareai-py copied to clipboard

Deployed scripts: raise good error if a column has been renamed

Open Aylr opened this issue 7 years ago • 0 comments

Background

  • Our scripts might be in a position to detect if columns have been renamed in a SAM.
  • create a safe way to get data for catalyst-specific deploys that can raise a reasonable error
  • this can help the infrastructure be more robust at detecting upstream failures

TODO

  • [ ] implement something like the select_data funciton in the r tools that will spit out a dataframe given sql. This will have error handling built in (see below)
  • [ ] update examples

Working code chunk

import records
import sqlalchemy

connetion_string = "asdfasfdsadf"
db = records.Database(connection_string)
db_engine = create_engine(connection_string)

try:
    rows = db.query('select TOP 10 LastLoadDTS, fake_column from dbo.HCPyDeployClassificationBASE;')
    print(rows.all())
except sqlalchemy.exc.ProgrammingError as e:
#     print(sys.exc_info())
    
    statement = e.statement
    original_error = str(e.orig)
    bad_column = re.findall(r'(?<=Invalid column name \').*(?=\'. )', original_error)
    
    print('There was a problem with the column {} in this statement: {}\nPlease verify that this column exists.\n{}'.format(bad_column, statement, original_error))

Aylr avatar May 16 '17 05:05 Aylr