@@ -20,13 +20,13 @@ package org.apache.spark.sql.execution.datasources
2020import org .apache .spark .{Logging , TaskContext }
2121import org .apache .spark .deploy .SparkHadoopUtil
2222import org .apache .spark .rdd .{MapPartitionsRDD , RDD , UnionRDD }
23- import org .apache .spark .sql .catalyst .{InternalRow , expressions }
23+ import org .apache .spark .sql .catalyst .{CatalystTypeConverters , InternalRow , expressions }
2424import org .apache .spark .sql .catalyst .expressions ._
2525import org .apache .spark .sql .catalyst .planning .PhysicalOperation
2626import org .apache .spark .sql .catalyst .plans .logical
2727import org .apache .spark .sql .catalyst .plans .logical .LogicalPlan
2828import org .apache .spark .sql .sources ._
29- import org .apache .spark .sql .types .{StringType , StructType }
29+ import org .apache .spark .sql .types .{TimestampType , DateType , StringType , StructType }
3030import org .apache .spark .sql .{SaveMode , Strategy , execution , sources , _ }
3131import org .apache .spark .unsafe .types .UTF8String
3232import org .apache .spark .util .{SerializableConfiguration , Utils }
@@ -343,11 +343,17 @@ private[sql] object DataSourceStrategy extends Strategy with Logging {
343343 * and convert them.
344344 */
345345 protected [sql] def selectFilters (filters : Seq [Expression ]) = {
346+ import CatalystTypeConverters ._
347+
346348 def translate (predicate : Expression ): Option [Filter ] = predicate match {
347349 case expressions.EqualTo (a : Attribute , Literal (v, _)) =>
348350 Some (sources.EqualTo (a.name, v))
349351 case expressions.EqualTo (Literal (v, _), a : Attribute ) =>
350352 Some (sources.EqualTo (a.name, v))
353+ case expressions.EqualTo (Cast (a : Attribute , _), l : Literal ) =>
354+ Some (sources.EqualTo (a.name, convertToScala(Cast (l, a.dataType).eval(), a.dataType)))
355+ case expressions.EqualTo (l : Literal , Cast (a : Attribute , _)) =>
356+ Some (sources.EqualTo (a.name, convertToScala(Cast (l, a.dataType).eval(), a.dataType)))
351357
352358 case expressions.EqualNullSafe (a : Attribute , Literal (v, _)) =>
353359 Some (sources.EqualNullSafe (a.name, v))
@@ -358,21 +364,41 @@ private[sql] object DataSourceStrategy extends Strategy with Logging {
358364 Some (sources.GreaterThan (a.name, v))
359365 case expressions.GreaterThan (Literal (v, _), a : Attribute ) =>
360366 Some (sources.LessThan (a.name, v))
367+ case expressions.GreaterThan (Cast (a : Attribute , _), l : Literal ) =>
368+ Some (sources.GreaterThan (a.name, convertToScala(Cast (l, a.dataType).eval(), a.dataType)))
369+ case expressions.GreaterThan (l : Literal , Cast (a : Attribute , _)) =>
370+ Some (sources.LessThan (a.name, convertToScala(Cast (l, a.dataType).eval(), a.dataType)))
361371
362372 case expressions.LessThan (a : Attribute , Literal (v, _)) =>
363373 Some (sources.LessThan (a.name, v))
364374 case expressions.LessThan (Literal (v, _), a : Attribute ) =>
365375 Some (sources.GreaterThan (a.name, v))
376+ case expressions.LessThan (Cast (a : Attribute , _), l : Literal ) =>
377+ Some (sources.LessThan (a.name, convertToScala(Cast (l, a.dataType).eval(), a.dataType)))
378+ case expressions.LessThan (l : Literal , Cast (a : Attribute , _)) =>
379+ Some (sources.GreaterThan (a.name, convertToScala(Cast (l, a.dataType).eval(), a.dataType)))
366380
367381 case expressions.GreaterThanOrEqual (a : Attribute , Literal (v, _)) =>
368382 Some (sources.GreaterThanOrEqual (a.name, v))
369383 case expressions.GreaterThanOrEqual (Literal (v, _), a : Attribute ) =>
370384 Some (sources.LessThanOrEqual (a.name, v))
385+ case expressions.GreaterThanOrEqual (Cast (a : Attribute , _), l : Literal ) =>
386+ Some (sources.GreaterThanOrEqual (a.name,
387+ convertToScala(Cast (l, a.dataType).eval(), a.dataType)))
388+ case expressions.GreaterThanOrEqual (l : Literal , Cast (a : Attribute , _)) =>
389+ Some (sources.LessThanOrEqual (a.name,
390+ convertToScala(Cast (l, a.dataType).eval(), a.dataType)))
371391
372392 case expressions.LessThanOrEqual (a : Attribute , Literal (v, _)) =>
373393 Some (sources.LessThanOrEqual (a.name, v))
374394 case expressions.LessThanOrEqual (Literal (v, _), a : Attribute ) =>
375395 Some (sources.GreaterThanOrEqual (a.name, v))
396+ case expressions.LessThanOrEqual (Cast (a : Attribute , _), l : Literal ) =>
397+ Some (sources.LessThanOrEqual (a.name,
398+ convertToScala(Cast (l, a.dataType).eval(), a.dataType)))
399+ case expressions.LessThanOrEqual (l : Literal , Cast (a : Attribute , _)) =>
400+ Some (sources.GreaterThanOrEqual (a.name,
401+ convertToScala(Cast (l, a.dataType).eval(), a.dataType)))
376402
377403 case expressions.InSet (a : Attribute , set) =>
378404 Some (sources.In (a.name, set.toArray))
0 commit comments