Java Spark:命名的_结构至少需要一个参数
我正在将行的数据集映射到自定义类的数据集Java Spark:命名的_结构至少需要一个参数,java,apache-spark,apache-spark-sql,Java,Apache Spark,Apache Spark Sql,我正在将行的数据集映射到自定义类的数据集 Dataset<Row> rows= sparkSession.read().orc(path); Dataset<customClass> dataset = rows.map(I'm parsing row to map it to customClass, Encoders.bean(customClass.class)); 我终于找到了为什么我将这个命名为_struct错误:我使用的一个字段被声明为fina
Dataset<Row> rows= sparkSession.read().orc(path);
Dataset<customClass> dataset =
rows.map(I'm parsing row to map it to customClass,
Encoders.bean(customClass.class));
我终于找到了为什么我将这个
命名为_struct
错误:我使用的一个字段被声明为final
,这意味着它没有setter。这违反了JavaBean
契约。如何“解析行以将其映射到customClass”。我仍然希望发现类似于命名的_struct
的东西。您的customClass
有哪些字段?customClass有以下字段:字符串、整数、双精度、布尔值和枚举。除此之外,它还有其他类作为字段。设A,B,C,D,E为这些类:A有一个映射。B只有一个字符串。C有字符串、整数、双精度、枚举和映射。D有字符串、双精度和整数。E有一个地图。你能编辑你的问题并包括逻辑查询计划吗,例如q.explain(true)
?你能不能也添加System.out.println(Encoders.bean(customClass.class))
的输出?您是否可以删除customClass
中Map
的所有用法并重新开始(只是为了测试它是否可以在没有部分支持的映射的情况下提供更好的结果)?我无法获得逻辑查询计划,因为在创建数据集时程序正在崩溃。我认为问题与Maps
有关:在customClass
模式上,Maps
的键是struct
,没有与之链接的值。也许这就是我遇到这个问题的原因。我终于找到了为什么我将这个命名为_struct
错误:我使用的一个字段被声明为final
,这意味着它没有setter。这违反了JavaBean
合同。是的,遗憾的是,在java的spark中,我们不得不使用可变bean:(
root
|-- field1: struct (nullable = true)
| |-- value: string (nullable = true)
|-- field2: string (nullable = true)
|-- field3: integer (nullable = true)
|-- field4: double (nullable = true)
|-- field5: struct (nullable = true)
| |-- value: double (nullable = true)
|-- field6: struct (nullable = true)
| |-- field61: double (nullable = true)
| |-- field62: string (nullable = true)
| |-- field63: integer (nullable = true)
| |-- field64: struct (nullable = true)
| | |-- value: string (nullable = true)
|-- field7: struct (nullable = true)
| |-- value: double (nullable = true)
|-- field8: struct (nullable = true)
| |-- value: double (nullable = true)
|-- field9: struct (nullable = true)
| |-- field91: map (nullable = true)
| | |-- key: struct
| | |-- value: struct (valueContainsNull = true)
| | | |-- value: string (nullable = true)
| | | |-- field911: struct (nullable = true)
| | | | |-- value: double (nullable = true)
| | | |-- field912: struct (nullable = true)
| | | | |-- value: double (nullable = true)
| | | |-- field913: map (nullable = true)
| | | | |-- key: struct
| | | | |-- value: struct (valueContainsNull = true)
| | | | | |-- value: integer (nullable = false)
| | | | | |-- field9131: struct (nullable = true)
| | | | | | |-- value: double (nullable = true)
| | | | | |-- field9131: struct (nullable = true)
| | | | | | |-- value: double (nullable = true)
| | | |-- field914: struct (nullable = true)
| | | | |-- value: double (nullable = true)
| | | |-- field915: string (nullable = true)
|-- field10: string (nullable = true)
|-- field11: struct (nullable = true)
| |-- field111: map (nullable = true)
| | |-- key: struct
| | |-- value: struct (valueContainsNull = true)
| | | |-- value: integer (nullable = false)
| | | |-- field1111: struct (nullable = true)
| | | | |-- value: double (nullable = true)
| | | |-- field1112: struct (nullable = true)
| | | | |-- value: double (nullable = true)
|-- field12: boolean (nullable = true)
|-- field13: struct (nullable = true)
| |-- field131: integer (nullable = false)
| |-- field132: integer (nullable = false)
|-- field14: struct (nullable = true)
| |-- field141: string (nullable = true)