spark-csv 1.1.0と Spark 1.5を使用しています。次のようにスキーマを作成します。
private def makeSchema(tableColumns: List[SparkSQLFieldConfig]): StructType = {
new StructType(
tableColumns.map(p => p.ColumnDataType match {
case FieldDataType.Integer => StructField(p.ColumnName, IntegerType, nullable = true)
case FieldDataType.Decimal => StructField(p.ColumnName, FloatType, nullable = true)
case FieldDataType.String => StructField(p.ColumnName, StringType, nullable = true)
case FieldDataType.DateTime => StructField(p.ColumnName, TimestampType, nullable = true)
case FieldDataType.Date => StructField(p.ColumnName, DateType, nullable = true)
case FieldDataType.Boolean => StructField(p.ColumnName, BooleanType, nullable = false)
case _ => StructField(p.ColumnName, StringType, nullable = true)
}).toArray
)
}
しかし、DateType
列がある場合、データフレームを使用したクエリは非常に遅くなります。(クエリは単純なものgroupby(), sum()
などです)
DateType
同じデータセットを使用して、Date をと DateTime にマップするTimestampType
(つまり、それらを にマップする)ように 2 行をコメントした後StringType
、クエリははるかに高速になります。
これにはどのような理由が考えられますか? どうもありがとうございました!