gpt4 book ai didi

apache-spark - apache spark 2.2 没有可用的 toString 方法

转载 作者:行者123 更新时间:2023-12-05 07:32:14 27 4
gpt4 key购买 nike

在获取数据集的头部时,我收到一条错误消息:

java.util.concurrent.ExecutionException: org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 60, Column 32: failed to compile: org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 60, Column 32: A method named "toString" is not declared in any enclosing class nor any supertype, nor through a static import

我在代码中做一个简单的连接,然后尝试获取头部:

Dataset<Transaction> ds = getSparkSession().read().text(file).map(Row::mkString, Encoders.STRING())                            
.map(row -> {
return Transaction.builder()
.account(row.substring(7, 19).trim())
.referenceNumber(row.substring(58, 69).trim())
.dateAndTime(row.substring(71, 79).trim())
.amount(row.substring(87, 100).trim())
.merchantCity(row.substring(160, 173).trim())
.merchantCountry(row.substring(173, 175).trim())
.build();
}, Encoders.bean(CreditCardTransaction.class)));

Dataset<User> userDs = getUserDs();

Dataset<FilteredTransaction> fds = ds.filter(functions.length(ds.col("account")).geq("16"))
.join(userDs, ds.col("referenceNumber").startsWith(userDs.col("referenceNumber")))
.select(userDs.col("userId"),
ds.col("amount"),
ds.col("dateAndTime").cast(DataTypes.TimestampType),
ds.col("account"),
ds.col("merchantCity"),
ds.col("merchantCountry"))
.as(Encoders.bean(FilteredTransaction.class))
);

fds.head(1);

当我查看生成的代码时,我看到它在下面第 60 行的长基元上执行 toString,这是一个 Bug 吗?

/* 050 */     boolean isNull21 = i.isNullAt(2);
/* 051 */ long value21 = isNull21 ? -1L : (i.getLong(2));
/* 052 */ boolean isNull20 = true;
/* 053 */ java.lang.String value20 = null;
/* 054 */ if (!isNull21) {
/* 055 */
/* 056 */ isNull20 = false;
/* 057 */ if (!isNull20) {
/* 058 */
/* 059 */ Object funcResult9 = null;
/* 060 */ funcResult9 = value21.toString();

最佳答案

原因可能是 Dataset 列数据类型与 Encoder bean 类中的相应字段数据类型不匹配。

例如,FilteredTransaction 的字段account 的类型为String。在源文本文件中它是一个数字(将被处理为 long )。在这种情况下,它无法将 long 转换为 String,因为 long 没有 toString 方法。因此,为编码器 bean 中的字段创建相同的数据类型(如在推断的数据集模式中)。

class FilteredTransaction {
...
private long account;
....
}

关于apache-spark - apache spark 2.2 没有可用的 toString 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51363297/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com