Exemple #1
0
    def execute(self, cursor, state):
        partition = self.partition(state)
        datapackage = self.datapackage(state)

        try:
            try:
                store_batch_insert(cursor, partition.table(), datapackage,
                        state["modified"])
            except Exception as exc:
                logging.debug("exception: {}".format(type(exc).__name__))
                raise exc
        except NoSuchTable:
            data_types = compose(DataPackage.deduce_data_types, self.datapackage)
            trend_names = compose(attrgetter("trend_names"), self.datapackage)
            fix = CreatePartition(self.partition, trend_names, data_types)
            return insert_before(fix)
        except NoSuchColumnError:
            data_types = compose(DataPackage.deduce_data_types, self.datapackage)
            trend_names = compose(attrgetter("trend_names"), self.datapackage)
            fix = CheckColumnsExist(self.partition, trend_names, data_types)
            return insert_before(fix)
        except UniqueViolation:
            fix = Update(self.partition, self.datapackage)
            return replace(fix)
        except DataTypeMismatch:
            data_types = compose(DataPackage.deduce_data_types, self.datapackage)
            trend_names = compose(attrgetter("trend_names"), self.datapackage)
            fix = CheckColumnTypes(self.partition, trend_names, data_types)
            return insert_before(fix)
Exemple #2
0
    def execute(self, cursor, state):
        partition = self.partition(state)
        datapackage = self.datapackage(state)

        try:
            store_copy_from(cursor, partition.table(), datapackage,
                    state["modified"])
        except NoCopyInProgress:
            return no_op
        except NoSuchTable:
            data_types = compose(DataPackage.deduce_data_types, self.datapackage)
            trend_names = compose(attrgetter("trend_names"), self.datapackage)
            fix = CreatePartition(self.partition, trend_names, data_types)
            return insert_before(fix)
        except NoSuchColumnError:
            data_types = compose(DataPackage.deduce_data_types, self.datapackage)
            trend_names = compose(attrgetter("trend_names"), self.datapackage)
            fix = CheckColumnsExist(self.partition, trend_names, data_types)
            return insert_before(fix)
        except UniqueViolation:
            fix = Update(self.partition, self.datapackage)
            return replace(fix)
        except DataTypeMismatch:
            data_types = compose(DataPackage.deduce_data_types, self.datapackage)
            trend_names = compose(attrgetter("trend_names"), self.datapackage)
            fix = CheckColumnTypes(self.partition, trend_names, data_types)
            return insert_before(fix)