spark on hive local模式使用元数据连接的方式查询hive 在idea中需要引入的包文件如下: <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-sql_2.11</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-hive_2.11</artifactId> <version>2.3.0</version> </dependency> 将hive的hive-site.xml文件和hadoop的core-site.xml和hdfs-site.xml文件放在idea 的resource目录下https://hub.fastgit.org/steveloughran/winutils/tags 目录下下载hadoop winutil工具在idea中配置HADOOP_HOME的环境变量,如下最后就可以编写sql查询语句了,如下 SparkConf sparkConf = new SparkConf(); sparkConf.setMaster("local[*]"); SparkSession spark = SparkSession .builder() .appName("Java Spark SQL basic example") .config(sparkConf) .enableHiveSupport() .getOrCreate(); spark.sql("select count(1) from test").show();