是否有任何方法在Hive上使用Python创建数据库?



我想自动化整个过程来测试一个场景,我想创建一个数据库,执行一个操作,然后删除数据库。有没有办法用python3来做。我尝试使用PyHive,但它需要数据库名称来连接。

如果不能连接到数据库,需要在终端上运行hive命令,我们可以使用subprocess模块中的Popen函数在终端上使用hive。

if self.is_database_exist():
print("Exists")
self.drop_hive_database()
else:
print("Not Exists")
put = Popen(["hive", "-S", "-e", "create database {0};".format(self.database)], stdin=PIPE, stdout=PIPE, bufsize=-1)
out, exp = put.communicate()
if "failed" in str(out).lower():
self.logger("Failed to create Hive Database %s!" % self.database)
raise Exception("Failed to create database")

自我。database包含数据库的名称,并且它的database exist函数检查数据库是否已经存在,然后我们删除数据库并重新创建它。

最新更新