赞
踩
<!-- 指定hiveserver2连接的host --> <property> <name>hive.server2.thrift.bind.host</name> <value>hadoop111</value> </property> <!-- 指定hiveserver2连接的端口号 --> <property> <name>hive.server2.thrift.port</name> <value>10000</value> </property> <!-- 指定存储元数据要连接的地址 --> <property> <name>hive.metastore.uris</name> <value>thrift://hadoop111:9083</value> </property>
hive --service metastore
hive --service hiveserver2
给个demo示例:
- from pyspark.sql import SparkSession
-
- # 创建 SparkSession
- spark = SparkSession \
- .builder \
- .appName("HiveConnectionExample") \
- .config("spark.sql.warehouse.dir", "hdfs://192.168.10.111:8020/user/hive/warehouse") \
- .config("hive.metastore.uris", "thrift://192.168.10.111:9083") \
- .enableHiveSupport() \
- .getOrCreate()
-
- # 读取 Hive 表
- # df = spark.sql("SELECT * FROM a")
- df = spark.sql("show tables")
- df.show()
-
- # 关闭 SparkSession
- spark.stop()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。