Пример #1
0
    def find_by_parameters(self, parameter_1: str,
                           parameter_3: str) -> MLTestingDagRow:
        """ Returns MLTestingDagRow for parameters

        Raises:
            DBException: If ml_testing_dag with parameters does not exist in db

        """
        ml_testing_dag_dag_join = self.table.join(
            MLDagRepository.table).select().where(
                and_(MLDagRepository.table.c.parameter_1 == parameter_1,
                     self.table.c.parameter_3 ==
                     parameter_3)).execute().first()

        if ml_testing_dag_dag_join:
            return MLTestingDagRow(
                id=ml_testing_dag_dag_join[self.table.c.id],
                ml_dag=MLDagRow(
                    id=ml_testing_dag_dag_join[MLDagRepository.table.c.id],
                    parameter_1=ml_testing_dag_dag_join[
                        MLDagRepository.table.c.parameter_1]),
                parameter_3=ml_testing_dag_dag_join[self.table.c.parameter_3])
        else:
            raise DBException(
                f'ml_testing_dag with [parameter_1: {parameter_1}] and '
                f'[parameter_3: {parameter_3}] does not exists')
Пример #2
0
    def check_ml_dag_id(self, ml_dag_id: int) -> None:
        """ Checks if ml_dag run with ml_dag_id exists in db

        Raises:
            DBException: If ml_dag with ml_dag_id does not exist in db
        """
        first_row = self.table.select().where(
            self.table.c.id == ml_dag_id).execute().first()

        if first_row is None:
            raise DBException(f'ml_dag with id[{ml_dag_id}] does not exists')
Пример #3
0
    def insert_task_with_ml_dag_id(self, ml_dag_id: int) -> None:
        """ Inserts new sample with ml_dag_id and sample_id into DB

        Raises:
            DBException - if task with ml_dag_id already exists in DB
        """
        try:
            self.table.insert().values(ml_dag_id=ml_dag_id).execute()
        except IntegrityError:
            raise DBException(
                f'task with [ml_dag_id: {ml_dag_id}] already in DB')
Пример #4
0
    def _check_task_with_ml_dag_id(self, ml_dag_id: int) -> None:
        """ Checks if task with task with ml_dag_id exists in db

        Raises:
            DBException: If task with ml_dag_id does not exist in db
        """
        first_row = self.table.select().where(
            self.table.c.ml_dag_id == ml_dag_id).execute().first()

        if first_row is None:
            raise DBException(
                f'task with [ml_dag_id: {ml_dag_id}] doesnt exist')
Пример #5
0
    def find_by_id(self, id: int) -> MLDagRow:
        """ Returns MLDagRow for row with id = ml_dag_id

        Returns: MLDagRow with ml_dag_id

        Raises:
            DBException: If ml_dag with ml_dag_id does not exist in db

        """
        ml_dag = self.table.select().where(
            self.table.c.id == id).execute().first()
        if ml_dag:
            return MLDagRow(id=ml_dag.id, parameter_1=ml_dag.parameter_1)
        else:
            raise DBException(f'ml_dag with [id: {id}] does not exists')
Пример #6
0
    def find_by_parameter_1(self, parameter_1: str) -> MLDagRow:
        """ Returns MLDagRow for row with parameter_1 = parameter_1

        Returns: MLDagRow with parameter_1

        Raises:
            DBException: If ml_dag with parameter_1 does not exist in db

        """
        ml_dag = self.table.select().where(
            self.table.c.parameter_1 == parameter_1).execute().first()
        if ml_dag:
            return MLDagRow(id=ml_dag.id, parameter_1=ml_dag.parameter_1)
        else:
            raise DBException(
                f'ml_dag with [parameter_1: {parameter_1}] does not exists')
Пример #7
0
    def save(self, ml_training_dag: MLTrainingDagRow) -> MLTrainingDagRow:
        """ Inserts new ml_training_dag row in DB

        Args:
            ml_training_dag: MLTrainingDagRow for insertion

        Returns: Inserted MLTrainingDagRow

        """
        try:
            self.table.insert().values(ml_dag_id=ml_training_dag.ml_dag.id,
                                       parameter_2=ml_training_dag.parameter_2,
                                       datetime_created=datetime.datetime.utcnow()).execute()
        except IntegrityError:
            raise DBException(
                f'ml_testing_dag with [ml_dag_id: {ml_training_dag.ml_dag.id}] '
                f'and [parameter_3: {ml_training_dag.parameter_2}] already exists in DB')

        return self.find_by_parameters(
            parameter_1=ml_training_dag.ml_dag.parameter_1,
            parameter_2=ml_training_dag.parameter_2)