我正在尝试检查 hive Metastore 中是否存在表,如果不存在,请创建该表。如果表存在,则追加数据。
我有下面的代码片段:
spark.catalog.setCurrentDatabase("db_name")
db_catalog = spark.catalog.listTables(dbName = 'table_name)
if any(table_name in row for row in db_catalog):
add data
else:
create table
但是,我收到一个错误。>>> ValueError: Some of types cannot be determined after inferring
我无法解决值错误,因为在 hive Metastore 中创建的其他数据库表出现相同的错误。是否有另一种方法来检查 hive Metastore 中是否存在表?
最佳答案
您可以为此使用 JVM 对象。
if spark._jsparkSession.catalog().tableExists('db_name', 'tableName'):
print("exist")
else:
print("Not Exist")
用于 Python 功能的 Py4j 套接字。其他操作使用JVM SparkContext
.在 Spark Scala 中,您可以直接访问。
spark.catalog.tableExists("dbName.tableName")
关于python-3.x - 使用 Pyspark 检查 hive Metastore 中是否存在表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57646341/