@@ -220,36 +220,52 @@ trait HiveTypeCoercion {
220220 case a : BinaryArithmetic if a.right.dataType == StringType =>
221221 a.makeCopy(Array (a.left, Cast (a.right, DoubleType )))
222222
223+ // we should cast all timestamp/date/string compare into string compare,
224+ // even if both sides are of same type, as Hive use xxxwritable to compare.
223225 case p : BinaryPredicate if p.left.dataType == StringType
224226 && p.right.dataType == DateType =>
225- p.makeCopy(Array (Cast ( p.left, DateType ), p.right))
227+ p.makeCopy(Array (p.left, Cast ( p.right, StringType ) ))
226228 case p : BinaryPredicate if p.left.dataType == DateType
227229 && p.right.dataType == StringType =>
228- p.makeCopy(Array (p.left, Cast ( p.right, DateType ) ))
230+ p.makeCopy(Array (Cast ( p.left, StringType ), p.right))
229231 case p : BinaryPredicate if p.left.dataType == StringType
230232 && p.right.dataType == TimestampType =>
231- p.makeCopy(Array (Cast ( p.left, TimestampType ), p.right))
233+ p.makeCopy(Array (p.left, Cast ( p.right, StringType ) ))
232234 case p : BinaryPredicate if p.left.dataType == TimestampType
233235 && p.right.dataType == StringType =>
234- p.makeCopy(Array (p.left, Cast ( p.right, TimestampType ) ))
236+ p.makeCopy(Array (Cast ( p.left, StringType ), p.right))
235237 case p : BinaryPredicate if p.left.dataType == TimestampType
236238 && p.right.dataType == DateType =>
237- p.makeCopy(Array (Cast (p.left, DateType ), p.right))
239+ p.makeCopy(Array (Cast (p.left, StringType ), Cast ( p.right, StringType ) ))
238240 case p : BinaryPredicate if p.left.dataType == DateType
239241 && p.right.dataType == TimestampType =>
240- p.makeCopy(Array (p.left, Cast (p.right, DateType )))
242+ p.makeCopy(Array (Cast (p.left, StringType ), Cast (p.right, StringType )))
243+ // same type
244+ case p : BinaryPredicate if p.left.dataType == DateType
245+ && p.right.dataType == DateType =>
246+ p.makeCopy(Array (Cast (p.left, StringType ), Cast (p.right, StringType )))
247+ case p : BinaryPredicate if p.left.dataType == TimestampType
248+ && p.right.dataType == TimestampType =>
249+ p.makeCopy(Array (Cast (p.left, StringType ), Cast (p.right, StringType )))
241250
242251 case p : BinaryPredicate if p.left.dataType == StringType && p.right.dataType != StringType =>
243252 p.makeCopy(Array (Cast (p.left, DoubleType ), p.right))
244253 case p : BinaryPredicate if p.left.dataType != StringType && p.right.dataType == StringType =>
245254 p.makeCopy(Array (p.left, Cast (p.right, DoubleType )))
246255
247256 case i @ In (a, b) if a.dataType == DateType && b.forall(_.dataType == StringType ) =>
248- i.makeCopy(Array (a, b.map( Cast (_, DateType )) ))
257+ i.makeCopy(Array (Cast (a, StringType ), b ))
249258 case i @ In (a, b) if a.dataType == TimestampType && b.forall(_.dataType == StringType ) =>
250- i.makeCopy(Array (a, b.map( Cast (_, TimestampType )) ))
259+ i.makeCopy(Array (Cast (a, StringType ), b ))
251260 case i @ In (a, b) if a.dataType == DateType && b.forall(_.dataType == TimestampType ) =>
252- i.makeCopy(Array (a, b.map(Cast (_, DateType ))))
261+ i.makeCopy(Array (Cast (a, StringType ), b.map(Cast (_, StringType ))))
262+ case i @ In (a, b) if a.dataType == TimestampType && b.forall(_.dataType == DateType ) =>
263+ i.makeCopy(Array (Cast (a, StringType ), b.map(Cast (_, StringType ))))
264+ case i @ In (a, b) if a.dataType == DateType && b.forall(_.dataType == DateType ) =>
265+ i.makeCopy(Array (Cast (a, StringType ), b.map(Cast (_, StringType ))))
266+ case i @ In (a, b) if a.dataType == TimestampType && b.forall(_.dataType == TimestampType ) =>
267+ i.makeCopy(Array (Cast (a, StringType ), b.map(Cast (_, StringType ))))
268+
253269
254270 case Sum (e) if e.dataType == StringType =>
255271 Sum (Cast (e, DoubleType ))
0 commit comments