# Path: tasks/base_tasks.py
# class TempTableTask(Task):
#     '''
#     A Task that generates a table that will not be referred to in metadata.
# 
#     This is useful for intermediate processing steps that can benefit from the
#     session guarantees of the ETL, as well as automatic table naming.
# 
#     :param force: Optional Boolean, ``False`` by default.  If ``True``, will
#                   overwrite output table even if it exists already.
#     '''
# 
#     force = BoolParameter(default=False, significant=False)
# 
#     def on_failure(self, ex):
#         session_rollback(self, ex)
#         super(TempTableTask, self).on_failure(ex)
# 
#     def on_success(self):
#         session_commit(self)
# 
#     def target_tablename(self):
#         '''
#         Can be overriden to expose a different table name
#         :return:
#         '''
#         return unqualified_task_id(self.task_id)[:MAX_PG_IDENTIFIER_LENGTH]
# 
#     def run(self):
#         '''
#         Must be overriden by subclass.  Should create and populate a table
#         named from ``self.output().table``
# 
#         If this completes without exceptions, the :func:`~.util.current_session
#         will be committed; if there is an exception, it will be rolled back.
#         '''
#         raise Exception('Must override `run`')
# 
#     def output(self):
#         '''
#         By default, returns a :class:`~.targets.TableTarget` whose associated
#         table lives in a special-purpose schema in Postgres derived using
#         :func:`~.util.classpath`.
#         '''
#         return PostgresTarget(classpath(self), self.target_tablename())
# 
# Path: tasks/uk/gov.py
# class LowerLayerSuperOutputAreas(TableTask):
# 
#     def requires(self):
#         return {
#             'columns': LowerLayerSuperOutputAreasColumns(),
#             'lsoa-data': SimplifiedImportLowerLayerSuperOutputAreas(),
#             'dz-data': SimplifiedImportDataZones(),
#             'ni-data': SimplifiedImportNISuperOutputAreas(),
#         }
# 
#     def version(self):
#         return 1
# 
#     def table_timespan(self):
#         return get_timespan('2011')
# 
#     # TODO: https://github.com/CartoDB/bigmetadata/issues/435
#     def targets(self):
#         return {
#             OBSTable(id='.'.join([self.schema(), self.name()])): GEOM_REF,
#         }
# 
#     def columns(self):
#         input_ = self.input()
#         cols = OrderedDict()
#         cols.update(input_['columns'])
#         return cols
# 
#     def populate(self):
#         session = current_session()
# 
#         query = '''
#                 INSERT INTO {output}
#                 SELECT ST_MakeValid(wkb_geometry), lsoa11cd, lsoa11nm
#                 FROM {input_lsoa}
#                 UNION ALL
#                 SELECT ST_MakeValid(wkb_geometry), datazone, name
#                 FROM {input_dz}
#                 UNION ALL
#                 SELECT ST_MakeValid(wkb_geometry), soa_code, soa_label
#                 FROM {input_ni}
#                 '''.format(output=self.output().table,
#                            input_lsoa=self.input()['lsoa-data'].table,
#                            input_dz=self.input()['dz-data'].table,
#                            input_ni=self.input()['ni-data'].table,)
# 
#         session.execute(query)
# 
#     @staticmethod
#     def geoid_column():
#         return LowerLayerSuperOutputAreasColumns.geoid_column()
# 
#     @staticmethod
#     def geoname_column():
#         return LowerLayerSuperOutputAreasColumns.geoname_column()
# 
# Path: tasks/meta.py
# def current_session():
#     '''
#     Returns the session relevant to the currently operating :class:`Task`, if
#     any.  Outside the context of a :class:`Task`, this can still be used for
#     manual session management.
#     '''
#     return _current_session.get()


from tasks.base_tasks import TempTableTask
from tasks.uk.gov import LowerLayerSuperOutputAreas
from tasks.meta import current_session


class Shoreline(TempTableTask):

    def requires(self):
        return LowerLayerSuperOutputAreas()

    def version(self):
        return 1

    def run(self):
        session = current_session()


# Path: tasks/base_tasks.py
# class TempTableTask(Task):
#     '''
#     A Task that generates a table that will not be referred to in metadata.
# 
#     This is useful for intermediate processing steps that can benefit from the
#     session guarantees of the ETL, as well as automatic table naming.
# 
#     :param force: Optional Boolean, ``False`` by default.  If ``True``, will
#                   overwrite output table even if it exists already.
#     '''
# 
#     force = BoolParameter(default=False, significant=False)
# 
#     def on_failure(self, ex):
#         session_rollback(self, ex)
#         super(TempTableTask, self).on_failure(ex)
# 
#     def on_success(self):
#         session_commit(self)
# 
#     def target_tablename(self):
#         '''
#         Can be overriden to expose a different table name
#         :return:
#         '''
#         return unqualified_task_id(self.task_id)[:MAX_PG_IDENTIFIER_LENGTH]
# 
#     def run(self):
#         '''
#         Must be overriden by subclass.  Should create and populate a table
#         named from ``self.output().table``
# 
#         If this completes without exceptions, the :func:`~.util.current_session
#         will be committed; if there is an exception, it will be rolled back.
#         '''
#         raise Exception('Must override `run`')
# 
#     def output(self):
#         '''
#         By default, returns a :class:`~.targets.TableTarget` whose associated
#         table lives in a special-purpose schema in Postgres derived using
#         :func:`~.util.classpath`.
#         '''
#         return PostgresTarget(classpath(self), self.target_tablename())
# 
# Path: tasks/uk/gov.py
# class LowerLayerSuperOutputAreas(TableTask):
# 
#     def requires(self):
#         return {
#             'columns': LowerLayerSuperOutputAreasColumns(),
#             'lsoa-data': SimplifiedImportLowerLayerSuperOutputAreas(),
#             'dz-data': SimplifiedImportDataZones(),
#             'ni-data': SimplifiedImportNISuperOutputAreas(),
#         }
# 
#     def version(self):
#         return 1
# 
#     def table_timespan(self):
#         return get_timespan('2011')
# 
#     # TODO: https://github.com/CartoDB/bigmetadata/issues/435
#     def targets(self):
#         return {
#             OBSTable(id='.'.join([self.schema(), self.name()])): GEOM_REF,
#         }
# 
#     def columns(self):
#         input_ = self.input()
#         cols = OrderedDict()
#         cols.update(input_['columns'])
#         return cols
# 
#     def populate(self):
#         session = current_session()
# 
#         query = '''
#                 INSERT INTO {output}
#                 SELECT ST_MakeValid(wkb_geometry), lsoa11cd, lsoa11nm
#                 FROM {input_lsoa}
#                 UNION ALL
#                 SELECT ST_MakeValid(wkb_geometry), datazone, name
#                 FROM {input_dz}
#                 UNION ALL
#                 SELECT ST_MakeValid(wkb_geometry), soa_code, soa_label
#                 FROM {input_ni}
#                 '''.format(output=self.output().table,
#                            input_lsoa=self.input()['lsoa-data'].table,
#                            input_dz=self.input()['dz-data'].table,
#                            input_ni=self.input()['ni-data'].table,)
# 
#         session.execute(query)
# 
#     @staticmethod
#     def geoid_column():
#         return LowerLayerSuperOutputAreasColumns.geoid_column()
# 
#     @staticmethod
#     def geoname_column():
#         return LowerLayerSuperOutputAreasColumns.geoname_column()
# 
# Path: tasks/meta.py
# def current_session():
#     '''
#     Returns the session relevant to the currently operating :class:`Task`, if
#     any.  Outside the context of a :class:`Task`, this can still be used for
#     manual session management.
#     '''
#     return _current_session.get()


# Path: tasks/uk/shoreline.py
from tasks.base_tasks import TempTableTask
from tasks.uk.gov import LowerLayerSuperOutputAreas
from tasks.meta import current_session



class Shoreline(TempTableTask):

    def requires(self):
        return LowerLayerSuperOutputAreas()

    def version(self):
        return 1

    def run(self):
        session = current_session()


        stmt = '''