Skip to content

Commit aa96735

Browse files
committed
not cast for same type compare
1 parent 30bf48b commit aa96735

File tree

4 files changed

+5
-13
lines changed

4 files changed

+5
-13
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ 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.
223+
// we should cast all timestamp/date/string compare into string compare
225224
case p: BinaryPredicate if p.left.dataType == StringType
226225
&& p.right.dataType == DateType =>
227226
p.makeCopy(Array(p.left, Cast(p.right, StringType)))
@@ -240,13 +239,6 @@ trait HiveTypeCoercion {
240239
case p: BinaryPredicate if p.left.dataType == DateType
241240
&& p.right.dataType == TimestampType =>
242241
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)))
250242

251243
case p: BinaryPredicate if p.left.dataType == StringType && p.right.dataType != StringType =>
252244
p.makeCopy(Array(Cast(p.left, DoubleType), p.right))

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression w
174174
// Date cannot be cast to double, according to hive
175175
private[this] def dateToDouble(d: Date) = null
176176

177-
// Converts Timestamp to string according to Hive TimestampWritable convention
177+
// Converts Date to string according to Hive DateWritable convention
178178
private[this] def dateToString(d: Date): String = {
179179
Cast.threadLocalDateFormat.get.format(d)
180180
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/dataTypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ case object DateType extends NativeType {
256256
@transient private[sql] lazy val tag = ScalaReflectionLock.synchronized { typeTag[JvmType] }
257257

258258
private[sql] val ordering = new Ordering[JvmType] {
259-
def compare(x: Date, y: Date) = x.compareTo(y)
259+
def compare(x: Date, y: Date) = x.toString.compareTo(y.toString)
260260
}
261261

262262
def simpleString: String = "date"

sql/core/src/main/scala/org/apache/spark/sql/columnar/ColumnStats.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ private[sql] class DateColumnStats extends ColumnStats {
198198
override def gatherStats(row: Row, ordinal: Int) {
199199
if (!row.isNullAt(ordinal)) {
200200
val value = row(ordinal).asInstanceOf[Date]
201-
if (upper == null || value.compareTo(upper) > 0) upper = value
202-
if (lower == null || value.compareTo(lower) < 0) lower = value
201+
if (upper == null || value.toString.compareTo(upper.toString) > 0) upper = value
202+
if (lower == null || value.toString.compareTo(lower.toString) < 0) lower = value
203203
} else {
204204
nullCount += 1
205205
}

0 commit comments

Comments
 (0)