java - 如何解决java spark中的“线程“main”java.lang.Error中的异常:未解决的编译问题:SparkSession无法解析为类型”
问题描述
我在 Azure Windows 虚拟机中安装了“VScode、jdk 8、python 3.8 和 databricks-connect==8.1.*” 。之后,我创建了一个 databricks 集群并使用 cmd配置了 Databricks-connect 。设置完所有路径变量后,我按照 Java 代码执行:
'''
import java.util.ArrayList;
import java.util.List;
import java.sql.Date;
import org.apache.spark.sql.SparkSession;
import org.apache.spark.sql.types.*;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.RowFactory;
import org.apache.spark.sql.Dataset;
public class test_{
public static void main(String[] args) throws Exception {
SparkSession spark = SparkSession.builder().appName("Temps Demo").config("spark.master", "local").getOrCreate();
// Create a Spark DataFrame consisting of high and low temperatures
// by airport code and date.
StructType schema = new StructType(new StructField[] {
new StructField("AirportCode", DataTypes.StringType, false, Metadata.empty()),
new StructField("Date", DataTypes.DateType, false, Metadata.empty()),
new StructField("TempHighF", DataTypes.IntegerType, false, Metadata.empty()),
new StructField("TempLowF", DataTypes.IntegerType, false, Metadata.empty()),
});
}}'''
==================================================== ======= 在 VScode 终端内我得到低于输出'''
PS C:\Users\gaurav> & 'c:\Users\gaurav\.vscode\extensions\vscjava.vscode-java-debug-0.35.0\scripts\launcher.bat' 'C:\Program Files\AdoptOpenJDK\jdk-11.0.11.9-hotspot\bin\java.exe' '-Dfile.encoding=UTF-8' '-cp' 'C:\Users\gaurav\AppData\Local\Temp\vscodesws_8933a\jdt_ws\jdt.ls-java-project\bin' 'App'
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
SparkSession cannot be resolved to a type
SparkSession cannot be resolved
StructType cannot be resolved to a type
StructType cannot be resolved to a type
StructField cannot be resolved to a type
StructField cannot be resolved to a type
StructField cannot be resolved to a type
DataTypes cannot be resolved to a variable
Metadata cannot be resolved
StructField cannot be resolved to a type
StructField cannot be resolved to a type
DataTypes cannot be resolved to a variable
Metadata cannot be resolved
PS C:\Users\gaurav> & 'c:\Users\gaurav\.vscode\extensions\vscjava.vscode-java-debug-0.35.0\scripts\launcher.bat' 'C:\Program Files\AdoptOpenJDK\jdk-11.0.11.9-hotspot\bin\java.exe' '-Dfile.encoding=UTF-8' '-cp' 'C:\Users\gaurav\AppData\Local\Temp\vscodesws_8933a\jdt_ws\jdt.ls-java-project\bin' 'test_'
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
SparkSession cannot be resolved to a type
SparkSession cannot be resolved
StructType cannot be resolved to a type
StructType cannot be resolved to a type
StructField cannot be resolved to a type
StructField cannot be resolved to a type
StructField cannot be resolved to a type
DataTypes cannot be resolved to a variable
Metadata cannot be resolved
StructField cannot be resolved to a type
StructField cannot be resolved to a type
DataTypes cannot be resolved to a variable
Metadata cannot be resolved
StructField cannot be resolved to a type
StructField cannot be resolved to a type
DataTypes cannot be resolved to a variable
Metadata cannot be resolved
StructField cannot be resolved to a type
StructField cannot be resolved to a type
DataTypes cannot be resolved to a variable
Metadata cannot be resolved
at test_.main(testjava.java:22)
'''
当我在配置 databricks 连接后在 cmd 中运行“databricks-connect 测试”时。我得到以下输出... [1]:https ://i.stack.imgur.com/p5WG6.png
解决方案
org.apache.spark.sql.types.StructType
在spark-catalyst中可以实现,将两者都添加spark-catalyst.jar
到spark-sql.jar
Referenced Libraries中。
此外,java 扩展需要jdk11 或最新版本来支持。
满足以上条件,StructField cannot be resolved to a type
我的项目中没有显示。
推荐阅读
- javascript - Select2 样式属性未拾取
- facebook - 通过 facebook 营销 api 获取 Facebook 最新的广告类型及其要求
- python - Optimisation of a numerical model with several data sets (scipy.minimize / scipy.optimise, pymoo or ??)
- sql - 用于存储播放列表和相关曲目的 RDS 数据模型设计?
- python - 安装 virtualenvwrapper 时出现 pyenv 错误
- firebase - 错误“包:cloud_firestore/src/query.dart”:断言失败:第 226 行 pos 12:“documentSnapshot != null”:不正确。扑火商店
- json - 使用本机消息通过 Delphi 从 Thunderbird 复制电子邮件时遇到编码问题
- javascript - 如何在 Wordpress 中根据标题和内容搜索产品?
- c++ - 来自协议缓冲区消息的普通结构
- javascript - 使用 yargs api 的动态和类型安全的函数参数