当前位置: 首页>>代码示例>>Python>>正文


Python meta.current_session函数代码示例

本文整理汇总了Python中tasks.meta.current_session函数的典型用法代码示例。如果您正苦于以下问题:Python current_session函数的具体用法?Python current_session怎么用?Python current_session使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了current_session函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_acs_columns_run

def test_acs_columns_run():
    task = Columns()
    assert_equals(False, task.complete())
    assert_equals(0, len(current_session().dirty))
    worker = runtask(task)
    assert_equals(True, task.complete())
    assert_equals(True, worker.run_succeeded)
    assert_equals(0, len(current_session().dirty))
开发者ID:CartoDB,项目名称:bigmetadata,代码行数:8,代码来源:test_acs.py

示例2: test_table_task_increment_version_runs_again

def test_table_task_increment_version_runs_again():
    task = TestTableTask()
    runtask(task)
    output = task.output()
    assert_true(output.exists())

    task = TestTableTask()
    task.version = lambda: 10
    output = task.output()
    assert_false(output.exists())

    current_session().rollback()
    runtask(task)
    assert_true(output.exists())
开发者ID:CartoDB,项目名称:bigmetadata,代码行数:14,代码来源:test_util.py

示例3: populate

    def populate(self):
        session = current_session()

        insert = True
        for hometype, _, measure, _, _ in hometype_measures():
            col_id = hometype + '_' + measure
            input_table = self.input()[col_id].table
            if insert:
                stmt = 'INSERT INTO {output} (region_name, {col_id}) ' \
                        'SELECT "RegionName", "{year}-{month}"::NUMERIC ' \
                        'FROM {input_table} '
            else:
                stmt = 'UPDATE {output} ' \
                        'SET {col_id} = "{year}-{month}"::NUMERIC ' \
                        'FROM {input_table} WHERE ' \
                        '{input_table}."RegionName" = {output}.region_name '
            session.execute(stmt.format(
                output=self.output().table,
                year=str(self.year).zfill(2),
                month=str(self.month).zfill(2),
                col_id=col_id,
                input_table=input_table))
            if insert:
                session.execute('ALTER TABLE {output} ADD PRIMARY KEY (region_name)'.format(
                    output=self.output().table))
            insert = False
开发者ID:stvno,项目名称:bigmetadata,代码行数:26,代码来源:zillow.py

示例4: populate

 def populate(self):
     session = current_session()
     session.execute('INSERT INTO {output} (the_geom, cvegeo) '
                     'SELECT wkb_geometry, cvegeo '
                     'FROM {input} '.format(
                         output=self.output().table,
                         input=self.input()['data'].table))
开发者ID:CartoDB,项目名称:bigmetadata,代码行数:7,代码来源:inegi.py

示例5: run

 def run(self):
     session = current_session()
     try:
         session.execute('DROP TABLE IF EXISTS observatory.obs_meta')
         session.execute(self.FIRST_AGGREGATE)
         session.execute('CREATE TABLE observatory.obs_meta AS {select}'.format(
             select=self.QUERY.replace('the_geom_webmercator', 'the_geom')
         ))
         # confirm that there won't be ambiguity with selection of geom
         session.execute('CREATE UNIQUE INDEX ON observatory.obs_meta '
                         '(numer_id, denom_id, numer_timespan, geom_weight)')
         session.execute('CREATE INDEX ON observatory.obs_meta USING gist '
                         '(the_geom)')
         for dimension, query in self.DIMENSIONS.iteritems():
             session.execute('DROP TABLE IF EXISTS observatory.obs_meta_{dimension}'.format(
                 dimension=dimension))
             session.execute('CREATE TABLE observatory.obs_meta_{dimension} '
                             'AS {select}'.format(
                                 dimension=dimension,
                                 select=query.replace('the_geom_webmercator', 'the_geom') \
                                             .replace('3857', '4326')
                             ))
             session.execute('CREATE INDEX ON observatory.obs_meta_{dimension} USING gist '
                             '(the_geom)'.format(dimension=dimension))
         session.commit()
         self._complete = True
     except:
         session.rollback()
         raise
开发者ID:CartoDB,项目名称:bigmetadata,代码行数:29,代码来源:carto.py

示例6: populate

    def populate(self):
        session = current_session()

        session.execute('INSERT INTO {output} '
                        'SELECT "wof:id", '
                        'CASE WHEN ST_Npoints(wkb_geometry) > 1000000 '
                        '     THEN ST_Simplify(wkb_geometry, 0.0001) '
                        '     ELSE wkb_geometry '
                        'END, '
                        '"wof:name" '
                        'FROM {input} '.format(
                            output=self.output().table,
                            input=self.input()['data'].table
                        ))

        # replace default WOF US states with our clipped versions
        if self.resolution == 'region':
            for geoid, statename in session.execute('SELECT geoid, name FROM tiger2014.state'):
                session.execute('UPDATE {output} out '
                                'SET the_geom = shoreline.the_geom '
                                'FROM {shoreline} shoreline '
                                'WHERE shoreline.geoid = \'{geoid}\' '
                                '  AND out.name ILIKE \'{statename}\' '.format(
                                    shoreline=self.input()['shoreline'].table,
                                    output=self.output().table,
                                    geoid=geoid,
                                    statename=statename))
开发者ID:CartoDB,项目名称:bigmetadata,代码行数:27,代码来源:whosonfirst.py

示例7: populate

    def populate(self):
        session = current_session()
        columns = self.columns()
        out_colnames = columns.keys()
        in_table = self.input()['data']
        in_colnames = [ct._id.split('.')[-1] for ct in columns.values()]
        in_colnames[0] = 'geo_code'
        for i, in_c in enumerate(in_colnames):
            cmd =   "SELECT 'exists' FROM information_schema.columns " \
                    "WHERE table_schema = '{schema}' " \
                    "  AND table_name = '{tablename}' " \
                    "  AND column_name = '{colname}' " \
                    "  LIMIT 1".format(
                        schema=in_table.schema,
                        tablename=in_table.tablename.lower(),
                        colname=in_c.lower())
            # remove columns that aren't in input table
            if session.execute(cmd).fetchone() is None:
                in_colnames[i] = None
                out_colnames[i] = None
        in_colnames = [
            "CASE {ic}::TEXT WHEN '-6' THEN NULL ELSE {ic} END".format(ic=ic) for ic in in_colnames if ic is not None]
        out_colnames = [oc for oc in out_colnames if oc is not None]

        cmd =   'INSERT INTO {output} ({out_colnames}) ' \
                'SELECT {in_colnames} FROM {input} '.format(
                    output=self.output().table,
                    input=in_table.table,
                    in_colnames=', '.join(in_colnames),
                    out_colnames=', '.join(out_colnames))
        session.execute(cmd)
开发者ID:CartoDB,项目名称:bigmetadata,代码行数:31,代码来源:data.py

示例8: populate

    def populate(self):
        session = current_session()

        insert = True
        input_ = self.input()
        output = self.output()
        session.execute('ALTER TABLE {output} ADD PRIMARY KEY (region_name)'.format(
            output=output.table))
        session.flush()
        for hometype, _, measure, _, _ in hometype_measures():
            col_id = hometype + '_' + measure
            input_table = input_[col_id].table
            stmt = '''INSERT INTO {output} (region_name, {col_id})
                      SELECT "RegionName", "{year}-{month}"::NUMERIC
                      FROM {input_table}
                      ON CONFLICT (region_name)
                         DO UPDATE SET {col_id} = EXCLUDED.{col_id}'''
            session.execute(stmt.format(
                output=output.table,
                year=str(self.year).zfill(2),
                month=str(self.month).zfill(2),
                col_id=col_id,
                input_table=input_table))
            if insert:
                insert = False
开发者ID:CartoDB,项目名称:bigmetadata,代码行数:25,代码来源:zillow.py

示例9: populate

 def populate(self):
     # This select statement transforms the input table, taking advantage of our
     # new column names.
     # The session is automatically committed if there are no errors.
     session = current_session()
     columns = self.columns()
     colnames = columns.keys()
     select_colnames = []
     for naics_code, naics_columns in self.input()['naics'].iteritems():
         for colname in naics_columns.keys():
             select_colnames.append('''MAX(CASE
                 WHEN industry_code = '{naics_code}' THEN {colname} ELSE NULL
             END)::Numeric'''.format(naics_code=naics_code,
                                     colname=colname
                                    ))
     insert = '''INSERT INTO {output} ({colnames})
                 SELECT area_fips, {select_colnames}
                 FROM {input}
                 GROUP BY area_fips '''.format(
                     output=self.output().table,
                     input=self.input()['data'].table,
                     colnames=', '.join(colnames),
                     select_colnames=', '.join(select_colnames),
                 )
     session.execute(insert)
开发者ID:CartoDB,项目名称:bigmetadata,代码行数:25,代码来源:bls.py

示例10: populate

 def populate(self):
     session = current_session()
     session.execute(' INSERT INTO {output} '
                     ' SELECT the_geom, id_2, pop2010, name_2 '
                     ' FROM {input} '.format(
                         output=self.output().table,
                         input=self.input()['data'].table
                     ))
开发者ID:CartoDB,项目名称:bigmetadata,代码行数:8,代码来源:thaipop.py

示例11: session_scope

def session_scope():
    """Provide a transactional scope around a series of operations."""
    try:
        yield current_session()
        session_commit(None)
    except Exception as e:
        session_rollback(None, e)
        raise
开发者ID:CartoDB,项目名称:bigmetadata,代码行数:8,代码来源:util.py

示例12: populate

 def populate(self):
     session = current_session()
     session.execute('INSERT INTO {output} '
                     'SELECT ST_MakeValid(wkb_geometry), oa_sa, sprgrp, grp, subgrp '
                     'FROM {input}'.format(
                         output=self.output().table,
                         input=self.input()['data'].table,
                     ))
开发者ID:stvno,项目名称:bigmetadata,代码行数:8,代码来源:cdrc.py

示例13: run

 def run(self):
     session = current_session()
     session.execute('CREATE TABLE {output} AS '
                     'SELECT geoid, ST_Union(ST_MakeValid(the_geom)) AS the_geom, '
                     '       MAX(aland) aland, MAX(awater) awater '
                     'FROM {input} '
                     'GROUP BY geoid'.format(
                         output=self.output().table,
                         input=self.input().table))
开发者ID:stvno,项目名称:bigmetadata,代码行数:9,代码来源:tiger.py

示例14: populate

 def populate(self):
     session = current_session()
     session.execute('INSERT INTO {output} '
                     'SELECT {code}uid as geom_id, '
                     '       wkb_geometry as geom '
                     'FROM {input} '.format(
                         output=self.output().table,
                         code=self.resolution.replace('_', ''),
                         input=self.input()['data'].table))
开发者ID:CartoDB,项目名称:bigmetadata,代码行数:9,代码来源:geo.py

示例15: requires

    def requires(self):
        tables = {}
        session = current_session()
        for table in session.query(OBSTable):
            if should_upload(table):
                tables[table.id] = table.tablename

        for table_id, tablename in tables.iteritems():
            yield TableToCartoViaImportAPI(table=tablename, force=self.force)
开发者ID:stvno,项目名称:bigmetadata,代码行数:9,代码来源:carto.py


注:本文中的tasks.meta.current_session函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。