Spark 3.1.1 在生成的.java 文件中抛出编译错误

问题描述

我们在 java 中使用 spark 3.1.1,因为我在处理空数据集时看到编译错误错误是,

ERROR org.apache.spark.sql.catalyst.expressions.codegen.CodeGenerator: Failed to compile: org.codehaus.commons.compiler.CompileException: File 'generated.java',Line 29,Column 133: IDENTIFIER expected instead of '['
org.codehaus.commons.compiler.CompileException: File 'generated.java',Column 133: IDENTIFIER expected instead of '['
    at org.codehaus.janino.TokenStreamImpl.read(TokenStreamImpl.java:196)
    at org.codehaus.janino.Parser.read(Parser.java:3705)


----
----
----
WARN org.apache.spark.sql.execution.WholeStageCodegenExec: Whole-stage codegen disabled for plan (id=30):

在某些情况下,我们得到如下空数据集,

+------------------+-------------------+------------------+
|col1              |col2               |col3              |
+------------------+-------------------+------------------+
+------------------+-------------------+------------------+

如果我们尝试处理这个数据集或 dataset.show(false);抛出这个编译错误。但应用程序运行良好。为了维护无错误的控制台,我们需要修复这个。 我尝试了两种方法

第一种方法

在创建数据集时尝试添加空/空数组(取决于列数据类型) 像这样,

List<Integer> result = new ArrayList<>();
dataset.withColumn("col1",when(col(col1.subElement).isNotNull(),col("col1")).otherwise(result));

在我们的例子中,col1 是 proto 字段,因为我们有多个元素。这是其中之一。子元素:[10,20,30]

因此,如果没有任何数据,我会尝试传递空数组。因为我得到了错误

[main] WARN org.apache.spark.sql.catalyst.util.package - Truncated the string representation of a plan since it was too large. This behavior can be adjusted by setting 'spark.sql.debug.maxToStringFields'.

如果我们设置 maxToStringFields,会导致性能问题。所以我没有走这条路。

第二种方法

尝试在处理此数据集时添加空检查。像这样,

List<Integer> result = new ArrayList<>();
dataset.withColumn(("col1"),when(col(col1.subElement).isNull(),result).otherwise(explode(col(col1.subElement))));

这里,问题是我们需要将 col1.subElement 分解为多行,因为它具有元素数组。但我不能对此进行空检查。得到如下错误

org.apache.spark.sql.AnalysisException: Generators are not supported when it's nested in expressions,but got: CASE WHEN (col1.subElement AS `subElement` IS NULL) THEN NULL ELSE explode(col1.subElement AS `subElement`) END

有没有办法解决这个问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)