本文整理汇总了Python中dumptruck.DumpTruck.create_table方法的典型用法代码示例。如果您正苦于以下问题:Python DumpTruck.create_table方法的具体用法?Python DumpTruck.create_table怎么用?Python DumpTruck.create_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dumptruck.DumpTruck
的用法示例。
在下文中一共展示了DumpTruck.create_table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_rows_second_insert
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def test_no_rows_second_insert(self):
"Nothing happens if no rows are inserted to a table that is there."
dt = DumpTruck(dbname="/tmp/test.db")
dt.create_table({"foo": "uhtnh", "bar": "aoue"}, "ninety")
dt.insert([], "ninety")
c = dt.execute("select count(*) as c from ninety")[0]["c"]
dt.close()
self.assertEqual(c, 0)
示例2: test_empty_row_second_insert
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def test_empty_row_second_insert(self):
"An empty row acts like any other row."
dt = DumpTruck(dbname="/tmp/test.db")
dt.create_table({"foo": "uhtnh", "bar": "aoue"}, "nine")
dt.insert({}, "nine")
c = dt.execute("select count(*) as c from nine")[0]["c"]
dt.close()
self.assertEqual(c, 1)
示例3: test_second_insert
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def test_second_insert(self):
"Inserting a second row that is all null adds an empty row."
dt = DumpTruck(dbname = '/tmp/test.db')
dt.create_table({'foo': 'uhtnh', 'bar': 'aoue'}, 'three')
dt.insert({'foo': None, 'bar': None}, 'three')
c = dt.execute('select count(*) as c from three')[0]['c']
dt.close()
self.assertEqual(c, 1)
示例4: test_empty_row_second_insert
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def test_empty_row_second_insert(self):
"An empty row acts like any other row."
dt = DumpTruck(dbname = '/tmp/test.db')
dt.create_table({'foo': 'uhtnh', 'bar': 'aoue'}, 'nine')
dt.insert({}, 'nine')
c = dt.execute('select count(*) as c from nine')[0]['c']
dt.close()
self.assertEqual(c, 1)
示例5: test_second_insert
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def test_second_insert(self):
"Inserting a second row that is all null adds an empty row."
dt = DumpTruck(dbname="/tmp/test.db")
dt.create_table({"foo": "uhtnh", "bar": "aoue"}, "three")
dt.insert({"foo": None, "bar": None}, "three")
c = dt.execute("select count(*) as c from three")[0]["c"]
dt.close()
self.assertEqual(c, 1)
示例6: test_no_rows_second_insert
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def test_no_rows_second_insert(self):
"Nothing happens if no rows are inserted to a table that is there."
dt = DumpTruck(dbname = '/tmp/test.db')
dt.create_table({'foo': 'uhtnh', 'bar': 'aoue'}, 'ninety')
dt.insert([], 'ninety')
c = dt.execute('select count(*) as c from ninety')[0]['c']
dt.close()
self.assertEqual(c, 0)
示例7: apis
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def apis():
dt = DumpTruck('/tmp/open-data.sqlite', auto_commit = False)
dt.create_table({'catalog':'abc.def'}, 'socrata_apis')
dt.create_index(['catalog'], 'socrata_apis', unique = True, if_not_exists = True)
socrata_catalogs = filter(lambda x: x[0] == 'socrata', catalogs())
for _, catalog in socrata_catalogs:
dt.upsert({
'catalog': catalog.split('://')[-1],
'apis': count_apis(catalog),
}, 'socrata_apis')
示例8: main
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def main():
edges = build_network()['edges']
dt = DumpTruck(dbname = '/tmp/open-data.sqlite', adapt_and_convert = True)
datasets_in = dt.execute('SELECT * FROM socrata')
dt.create_table({'id': 'blah-blah'}, 'socrata_deduplicated')
dt.create_index(['id'], 'socrata_deduplicated', if_not_exists = True, unique = True)
for dataset in dedupe(datasets_in, edges):
dt.upsert(dataset, 'socrata_deduplicated')
示例9: test_create_table
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def test_create_table(self):
h = DumpTruck(dbname = '/tmp/test.db')
h.create_table({'foo': 0, 'bar': 1, 'baz': 2}, 'zombies')
h.close()
connection=sqlite3.connect('/tmp/test.db')
cursor=connection.cursor()
cursor.execute('SELECT foo, bar, baz FROM zombies')
observed = cursor.fetchall()
connection.close()
expected = []
self.assertListEqual(observed, expected)
示例10: test_create_table
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def test_create_table(self):
h = DumpTruck(dbname="/tmp/test.db")
h.create_table({"foo": 0, "bar": 1, "baz": 2}, "zombies")
h.close()
connection = sqlite3.connect("/tmp/test.db")
cursor = connection.cursor()
cursor.execute("SELECT foo, bar, baz FROM zombies")
observed = cursor.fetchall()
connection.close()
expected = []
self.assertListEqual(observed, expected)
示例11: extract_dataset_table_info
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def extract_dataset_table_info():
dt = DumpTruck(dbname = '/tmp/table_info.db')
dt.create_table({'portal': 'abc', 'id': 'abcd-efgh'}, 'table_info')
dt.create_index(['portal', 'id'], 'table_info', unique = True)
dt.create_index(['tableId'], 'table_info', unique = False)
done = set([tuple(row.keys()) for row in dt.execute('SELECT portal, id FROM table_info')])
for portal in os.listdir('data'):
for viewid in os.listdir(os.path.join('data', portal, 'views')):
if (portal, viewid) in done:
continue
d = _dataset_table_info(portal, viewid)
if d == None:
continue
dt.upsert(d, 'table_info')
示例12: users
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def users():
dt = DumpTruck(dbname = '/tmp/socrata.db')
dt.create_table({'id': 'abcd-efgh'}, 'user')
dt.create_index(['id'], 'user', unique = True)
_users = {}
for portal in os.listdir('data'):
for viewid in os.listdir(os.path.join('data', portal, 'views')):
handle = open(os.path.join('data', portal, 'views', viewid), 'r')
try:
view = json.load(handle)
except:
# *cringe*
continue
handle.close()
if view['owner']['id'] in _users:
_users[view['owner']['id']]['views'].add(view['id'])
try:
_users[view['owner']['id']]['publicationDates'].add((view['id'], view['publicationDate']))
except:
return view
else:
_users[view['owner']['id']] = view['owner']
_users[view['owner']['id']]['views'] = {view['id']}
_users[view['owner']['id']]['tables'] = set()
_users[view['owner']['id']]['publicationDates'] = set()
if view['tableAuthor']['id'] in _users:
_users[view['tableAuthor']['id']]['tables'].add(view['tableId'])
else:
_users[view['tableAuthor']['id']] = view['tableAuthor']
_users[view['tableAuthor']['id']]['views'] = set()
_users[view['tableAuthor']['id']]['tables'] = {view['tableId']}
_users[view['tableAuthor']['id']]['publicationDates'] = set()
for uid in _users.keys():
for key in ['views', 'rights', 'tables']:
if key in _users[uid]:
_users[uid]['n_' + key] = len(_users[uid][key])
del _users[uid][key]
dt.insert(_users.values(), 'user')
for uid, user in _users.items():
for viewid, publicationDate in user['publicationDates']:
dt.insert({'userid': user['id'], 'viewid': viewid, 'publicationDate': publicationDate}, 'publications', commit = False)
dt.commit()
return _users
示例13: get_links
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def get_links(softwares = ['ckan','socrata']):
dt = DumpTruck('/tmp/open-data.sqlite')
dummyrow = dict(zip(['software','catalog','identifier', 'status_code', 'headers', 'error'], (['blah'] * 3) + ([234] * 1) + ([{'a':'b'}] * 2)))
dt.create_table(dummyrow, 'links', if_not_exists = True)
dt.create_index(['software','catalog','identifier'], 'links', if_not_exists = True, unique = True)
for software in softwares:
for catalog in read.catalogs(software):
if SOCRATA_FIX.get(catalog, 'this is a string, not None') == None:
continue
try:
for row in _check_catalog(software, catalog):
dt.upsert(row, 'links')
except:
print(os.path.join('downloads',software,catalog))
raise
示例14: to_sqlite3
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def to_sqlite3():
dt = DumpTruck('/tmp/open-data.sqlite', auto_commit = False)
dummyrow = dict(zip(['software','catalog','identifier'], ['blah']*3))
dt.create_table(dummyrow, 'datasets', if_not_exists = True)
dt.create_index(['software','catalog','identifier'], 'datasets', if_not_exists = True, unique = True)
for table in ['ckan','socrata']:
dt.create_table({'catalog':'blah','identifier':'blah'}, table, if_not_exists = True)
dt.create_index(['catalog','identifier'], table, if_not_exists = True, unique = True)
dt.create_table({'view_id':'abc','table_id':123}, 'socrata_tables')
dt.create_index(['view_id'], 'socrata_tables', if_not_exists = True, unique = True)
dt.create_index(['table_id'], 'socrata_tables', if_not_exists = True)
for dataset in datasets():
row = {
'software': dataset['software'],
'catalog': dataset['catalog'],
'identifier': dataset[SOFTWARE_MAP['identifier'][dataset['software']]],
}
sql = 'SELECT * FROM datasets WHERE software = ? AND catalog = ? AND identifier = ?'
if dt.execute(sql, [row['software'],row['catalog'],row['identifier']]) != []:
continue
dt.upsert(row, 'datasets')
if dataset['software'] == 'socrata':
socrata_table = {
'view_id': row['identifier'],
'table_id': dataset['tableId'],
}
dt.upsert(socrata_table, 'socrata_tables')
dt.upsert(dataset,dataset['software'])
dt.commit()
示例15: test_empty_row_create_table
# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import create_table [as 别名]
def test_empty_row_create_table(self):
"The schema row must have a non-null value."
dt = DumpTruck(dbname = '/tmp/test.db')
with self.assertRaises(ValueError):
dt.create_table({}, 'two')
dt.close()