0
我使用spark-csv 1.1.0和Spark 1.5。我做的模式如下:爲什麼指定模式爲DateType/TimestampType會使查詢速度非常慢?
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
列,我與Dataframes查詢會很慢。 (該查詢只是簡單的groupby(), sum()
等)
用同樣的數據集,之後我評論了兩行日期映射到DateType
和日期,以TimestampType
(即把它們映射到StringType
),查詢變得更更快。
這是什麼原因?非常感謝你!