我一直在尝试使用 python 从 KDB+ 数据库中获取元数据,基本上,我安装了一个名为的库qpython
,并使用该库连接和查询 KDB+ 数据库。
我想使用 python 将表/视图的所有适当列的元数据存储在 KDB+ 数据库中。尽管尝试了无数不同的方法,但我无法分离元数据部分。
即一些将输出类型转换为列表/元组,使用迭代for
等。
from qpython import qconnection
def fetch_metadata_from_kdb(params):
try:
kdb_connection_obj = qconnection.QConnection(host=params['host'], port=params['port'], username=params['username'], password=params['password'])
kdb_connection_obj.open()
PREDICATE = "meta[{}]".format(params['table'])
metadata = kdb_connection_obj(PREDICATE)
kdb_connection_obj.close()
return metadata
except Exception as error_msg:
return error_msg
def fetch_tables_from_kdb(params):
try:
kdb_connection_obj = qconnection.QConnection(host=params['host'], port=params['port'], username=params['username'], password=params['password'])
kdb_connection_obj.open()
tables = kdb_connection_obj("tables[]")
views = kdb_connection_obj("views[]")
kdb_connection_obj.close()
return [table.decode() for table in list(tables)], [view.decode() for view in list(views)]
except Exception as error_msg:
return error_msg
parms_q = {'host':'localhost', 'port':5010,
'username':'kdb', 'password':'kdb', 'table':'testing'}
print("fetch_tables_from_kdb:", fetch_tables_from_kdb(parms_q), "\n")
print("fetch_metadata_from_kdb:", fetch_metadata_from_kdb(parms_q), "\n")
我目前得到的输出如下;
fetch_tables_from_kdb: (['testing'], ['viewname'])
fetch_metadata_from_kdb: [(b'time',) (b'sym',) (b'price',) (b'qty',)]![(b'p', b'', b'') (b's', b'', b'') (b'f', b'', b'') (b'j', b'', b'')]
我无法将列部分和元数据部分分开。如何使用python仅存储KDB中表/视图的适当列的元数据?