sparksql 读取、连接 hive 报The root scratch dir: /tmp/hive on HDFS should be writable. Current permissions
首先检查权限问题,这里有两种解决方式:
1.用有写权限的用户去操作:在代码中添加环境变量:System.setProperty("HADOOP_USER_NAME","hadoop")
2.其次检查 hdfs /tmp/hive 其他用户是否对其有写的权限,如果没有就用该目录拥有者账户执行hadoop fs -chmod -R 777 /tmp/
在确保拥有写权限的前提下,如果还报这个异常,则考虑是缺少某 个配置。解决方式就是在spark 程序中添加配置项: "hive.exec.scratchdir", "hdfs://192.168.19.59:9000/user/hive/tmp”在 idea 等开发工具采用 local 方式运行,程序其实是去本地文件系统找 /tmp/hive 这个目录,所以,应该告诉程序该目录是 hdfs 上的,在程序sparkSession 中添加 "hive.exec.scratchdir", "hdfs://192.168.19.59:9000/user/hive/tmp"即可:
val ss: SparkSession = SparkSession
.builder()
.appName("test on hive ")
.master("local")
.config("hive.metastore.uris", "thrift://192.168.19.59:9083")
.config("hive.exec.scratchdir", "hdfs://192.168.19.59:9000/user/hive/tmp")
.enableHiveSupport()
.getOrCreate()