pyspark 判断 Hive 表是否存在

python 复制代码
Catalog.tableExists(tableName: str, dbName: Optional[str] = None) → bool
'''
tableName:表名
dbName:库名(可选)
return:bool 值
'''
python 复制代码
from pyspark.sql import SparkSession
spark = SparkSession \
        .builder \
        .appName('tableExists') \
        .config('spark.num.executors', '6') \
        .config('spark.executor.memory', '12g') \
        .config('spark.driver.memory', '2g') \
        .config('spark.executor.cores', '4') \
        .config('spark.default.parallelism', '50') \
        .config('spark.executor.memoryOverhead', '2g') \
        .config('spark.task.maxFailures', '10') \
        .config("spark.dynamicAllocation.enabled", 'false') \
        .config("spark.sql.broadcastTimeout", "3600") \
        .enableHiveSupport() \
        .getOrCreate()
# 例1
spark.catalog.tableExists("unexisting_table") # False
_ = spark.sql("DROP TABLE IF EXISTS tbl1")
_ = spark.sql("CREATE TABLE tbl1 (name STRING, age INT) USING parquet")
spark.catalog.tableExists("tbl1") # True

# 例2 不同方式
spark.catalog.tableExists("default.tbl1")
spark.catalog.tableExists("spark_catalog.default.tbl1")
spark.catalog.tableExists("tbl1", "default")
_ = spark.sql("DROP TABLE tbl1")

pyspark.sql.Catalog.tableExists

相关推荐
hINs IONN1 天前
深入解析HDFS:定义、架构、原理、应用场景及常用命令
hadoop·hdfs·架构
隐于花海,等待花开1 天前
Hive 常用函数详细总结
数据仓库·hive·hadoop
孟意昶1 天前
Doris专题28-聚合多维分析
大数据·数据库·数据仓库·sql·doris
docsz2 天前
据数据基座搭建
大数据·hadoop
RestCloud2 天前
流式优先数据架构:从批量ETL到事件驱动架构的演进之路
数据仓库·etl·cdc·数据处理·数据集成·数据传输·数据同步
coderlin_2 天前
LangGraph项目二 同步数据仓库信息到元数据库并且建立向量索引
数据库·数据仓库
隐于花海,等待花开3 天前
COLLECT_LIST函数详解
hive
隐于花海,等待花开3 天前
数据开发常问的技术性问题及解答
大数据·hive
曹宇飞丶3 天前
ambari server及元数据库(postgreSQL)迁移
hadoop·ambari
隐于花海,等待花开3 天前
窗口函数之排序函数详细解读及示例
大数据·数据库·hive