首页 > 解决方案 > Spark 数据集的 Avro Schema 与 Scala 案例类

问题描述

我很好奇使用 Scala 案例类中定义的模式与使用 Apache Avro 为 Spark 数据集定义模式之间是否存在显着的性能差异。目前我有一个看起来像这样的模式:

root
 |-- uniqueID: string (nullable = true)
 |-- fieldCount: integer (nullable = false)
 |-- fieldImportance: integer (nullable = false)
 |-- fieldPrimaryName: string (nullable = true)
 |-- fieldSecondaryName: string (nullable = true)
 |-- samples: map (nullable = true)
 |    |-- key: string
 |    |-- value: struct (valueContainsNull = true)
 |    |    |-- value1: byte (nullable = false)
 |    |    |-- value2: byte (nullable = false)
 |    |    |-- value3: byte (nullable = false)

对应的案例类看起来像

case class FieldSample(uniqueID: String, 
                       fieldCount: Int, 
                       fieldImportance: Int,
                       fieldPrimaryName: Int,
                       fieldSecondaryName: Int, 
                       samples: Map[String, ValueStruct])

case class ValueStruct(value1: Byte,
                       value2: Byte,
                       value3: Byte)

我已经使用 scala 案例类实现了这个,但我看到从磁盘读取的瓶颈非常大。数据以 parquet 格式保存在磁盘上。我想知道的是,在这种情况下,使用 Avro 模式而不是 scala 案例类是否有任何性能优势。我的猜测是嵌套模式导致 parquet 读取缓慢,所以我想知道 Avro 序列化是否以这种方式提供任何性能升级。谢谢!

标签: apache-sparkavro

解决方案


推荐阅读