spark3.0-python教程-SparkSQL:代码连接 Hive ,指定 metastore 服务

说明

创建 SparkSession 对象时,需要以下操作:

  1. 启用 Hive,如下:

    enableHiveSupport()
    
  2. 指定 Hive 的 metastore 服务,如下:

    config("hive.metastore.uris", "thrift://hadoop1:9083")
    

然后就可以对 Hive 中的表,进行查询、统计

完整代码

import findspark
findspark.init()

from pyspark.sql import SparkSession

spark = SparkSession.builder.\
    appName("test").\
    master("local[*]").\
    enableHiveSupport().\
    config("hive.metastore.uris", "thrift://hadoop1:9083").\
    getOrCreate()

原文出处:/show_1IX3FXqcvITE.html