java 未找到 Spark SQL 包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36302922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spark SQL package not found
提问by Belphegor
I am quite new to Spark, and have the following trouble: when I try to import SQLContext with:
我对 Spark 很陌生,遇到以下问题:当我尝试使用以下命令导入 SQLContext 时:
import org.apache.spark.sql.SQLContext;
or try to initialize SQLContext variable explicitly:
或尝试显式初始化 SQLContext 变量:
SQLContext sqlContext = new org.apache.spark.sql.SQLContext(sc);
I get an error from Eclipse:
我从 Eclipse 收到一个错误:
The import org.apache.spark.sql.SQLContext cannot be resolved
导入 org.apache.spark.sql.SQLContext 无法解析
I have put Spark into the dependency file, and everything else is fine except for the SQLContext. The whole code:
我已经将 Spark 放入依赖文件中,除了 SQLContext 之外,其他一切都很好。整个代码:
package main.java;
import java.io.Serializable;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.sql.SQLContext;
public class SparkTests {
public static void main(String[] args){
SparkConf conf = new SparkConf().setAppName("SparkMain");
JavaSparkContext sc = new JavaSparkContext(conf);
SQLContext sqlContext = new org.apache.spark.sql.SQLContext(sc);
//DataFrame df = sqlContext
System.out.println("\n\n\nHello world!\n\n\n");
}
}
When I try to compile it with mvn package
, I get the compilation error:
当我尝试使用 编译它时mvn package
,出现编译错误:
package org.apache.spark.sql does not exist
包 org.apache.spark.sql 不存在
Any ideas why the SQL package cannot be found?
为什么找不到 SQL 包的任何想法?
EDIT:
编辑:
The dependency file pom.xml:
依赖文件 pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>edu.berkeley</groupId>
<artifactId>simple-project</artifactId>
<modelVersion>4.0.0</modelVersion>
<name>Simple Project</name>
<packaging>jar</packaging>
<version>1.0</version>
<dependencies>
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
</project>
回答by zero323
If you want to use Spark SQL or DataFrames
in your project you'll have to add spark-sql
artifact as a dependency. In this particular case:
如果您想使用 Spark SQL 或DataFrames
在您的项目中,您必须添加spark-sql
工件作为依赖项。在这种特殊情况下:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.10</artifactId> <!-- matching Scala version -->
<version>1.6.1</version> <!-- matching Spark Core version -->
</dependency>
should do the trick.
应该做的伎俩。