Skip to content

Commit b738986

Browse files
committed
Renames l/r to left/right or lhs/rhs
1 parent 14900ae commit b738986

File tree

1 file changed

+81
-77
lines changed

1 file changed

+81
-77
lines changed

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

Lines changed: 81 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,20 @@ trait HiveTypeCoercion {
138138
case e if !e.childrenResolved => e
139139

140140
/* Double Conversions */
141-
case b @ BinaryExpression(StringNaN, r @ DoubleType()) =>
142-
b.makeCopy(Array(r, Literal(Double.NaN)))
143-
case b @ BinaryExpression(l @ DoubleType(), StringNaN) =>
144-
b.makeCopy(Array(Literal(Double.NaN), l))
141+
case b @ BinaryExpression(StringNaN, right @ DoubleType()) =>
142+
b.makeCopy(Array(Literal(Double.NaN), right))
143+
case b @ BinaryExpression(left @ DoubleType(), StringNaN) =>
144+
b.makeCopy(Array(left, Literal(Double.NaN)))
145145

146146
/* Float Conversions */
147-
case b @ BinaryExpression(StringNaN, r @ FloatType()) =>
148-
b.makeCopy(Array(b.right, Literal(Float.NaN)))
149-
case b @ BinaryExpression(l @ FloatType(), StringNaN) =>
150-
b.makeCopy(Array(Literal(Float.NaN), l))
147+
case b @ BinaryExpression(StringNaN, right @ FloatType()) =>
148+
b.makeCopy(Array(Literal(Float.NaN), right))
149+
case b @ BinaryExpression(left @ FloatType(), StringNaN) =>
150+
b.makeCopy(Array(left, Literal(Float.NaN)))
151151

152152
/* Use float NaN by default to avoid unnecessary type widening */
153-
case b @ BinaryExpression(l @ StringNaN, StringNaN) =>
154-
b.makeCopy(Array(Literal(Float.NaN), l))
153+
case b @ BinaryExpression(left @ StringNaN, StringNaN) =>
154+
b.makeCopy(Array(left, Literal(Float.NaN)))
155155
}
156156
}
157157
}
@@ -193,12 +193,16 @@ trait HiveTypeCoercion {
193193
logDebug(s"Resolving mismatched union input ${l.dataType}, ${r.dataType}")
194194
findTightestCommonTypeOfTwo(l.dataType, r.dataType).map { widestType =>
195195
val newLeft =
196-
if (l.dataType == widestType) l else Alias(Cast(l, widestType), l.name)()
196+
if (lhs.dataType == widestType) lhs else Alias(Cast(lhs, widestType), lhs.name)()
197197
val newRight =
198-
if (r.dataType == widestType) r else Alias(Cast(r, widestType), r.name)()
198+
if (rhs.dataType == widestType) rhs else Alias(Cast(rhs, widestType), rhs.name)()
199199

200200
(newLeft, newRight)
201-
}.getOrElse((l, r)) // If there is no applicable conversion, leave expression unchanged.
201+
}.getOrElse {
202+
// If there is no applicable conversion, leave expression unchanged.
203+
(lhs, rhs)
204+
}
205+
202206
case other => other
203207
}
204208

@@ -227,12 +231,12 @@ trait HiveTypeCoercion {
227231
// Skip nodes who's children have not been resolved yet.
228232
case e if !e.childrenResolved => e
229233

230-
case b @ BinaryExpression(l, r) if l.dataType != r.dataType =>
231-
findTightestCommonType(l.dataType, r.dataType).map { widestType =>
234+
case b @ BinaryExpression(left, right) if left.dataType != right.dataType =>
235+
findTightestCommonType(left.dataType, right.dataType).map { widestType =>
232236
val newLeft =
233-
if (l.dataType == widestType) l else Cast(l, widestType)
237+
if (left.dataType == widestType) left else Cast(left, widestType)
234238
val newRight =
235-
if (r.dataType == widestType) r else Cast(r, widestType)
239+
if (right.dataType == widestType) right else Cast(right, widestType)
236240
b.makeCopy(Array(newLeft, newRight))
237241
}.getOrElse(b) // If there is no applicable conversion, leave expression unchanged.
238242
}
@@ -247,29 +251,29 @@ trait HiveTypeCoercion {
247251
// Skip nodes who's children have not been resolved yet.
248252
case e if !e.childrenResolved => e
249253

250-
case a @ BinaryArithmetic(l @ StringType(), r) =>
251-
a.makeCopy(Array(Cast(l, DoubleType), r))
252-
case a @ BinaryArithmetic(l, r @ StringType()) =>
253-
a.makeCopy(Array(l, Cast(r, DoubleType)))
254+
case a @ BinaryArithmetic(left @ StringType(), r) =>
255+
a.makeCopy(Array(Cast(left, DoubleType), r))
256+
case a @ BinaryArithmetic(left, right @ StringType()) =>
257+
a.makeCopy(Array(left, Cast(right, DoubleType)))
254258

255259
// we should cast all timestamp/date/string compare into string compare
256-
case p @ BinaryComparison(l @ StringType(), r @ DateType()) =>
257-
p.makeCopy(Array(l, Cast(r, StringType)))
258-
case p @ BinaryComparison(l @ DateType(), r @ StringType()) =>
259-
p.makeCopy(Array(Cast(l, StringType), r))
260-
case p @ BinaryComparison(l @ StringType(), r @ TimestampType()) =>
261-
p.makeCopy(Array(Cast(l, TimestampType), r))
262-
case p @ BinaryComparison(l @ TimestampType(), r @ StringType()) =>
263-
p.makeCopy(Array(l, Cast(r, TimestampType)))
264-
case p @ BinaryComparison(l @ TimestampType(), r @ DateType()) =>
265-
p.makeCopy(Array(Cast(l, StringType), Cast(r, StringType)))
266-
case p @ BinaryComparison(l @ DateType(), r @ TimestampType()) =>
267-
p.makeCopy(Array(Cast(l, StringType), Cast(r, StringType)))
268-
269-
case p @ BinaryComparison(l @ StringType(), r) if r.dataType != StringType =>
270-
p.makeCopy(Array(Cast(l, DoubleType), r))
271-
case p @ BinaryComparison(l, r @ StringType()) if l.dataType != StringType =>
272-
p.makeCopy(Array(l, Cast(r, DoubleType)))
260+
case p @ BinaryComparison(left @ StringType(), right @ DateType()) =>
261+
p.makeCopy(Array(left, Cast(right, StringType)))
262+
case p @ BinaryComparison(left @ DateType(), right @ StringType()) =>
263+
p.makeCopy(Array(Cast(left, StringType), right))
264+
case p @ BinaryComparison(left @ StringType(), right @ TimestampType()) =>
265+
p.makeCopy(Array(Cast(left, TimestampType), right))
266+
case p @ BinaryComparison(left @ TimestampType(), right @ StringType()) =>
267+
p.makeCopy(Array(left, Cast(right, TimestampType)))
268+
case p @ BinaryComparison(left @ TimestampType(), right @ DateType()) =>
269+
p.makeCopy(Array(Cast(left, StringType), Cast(right, StringType)))
270+
case p @ BinaryComparison(left @ DateType(), right @ TimestampType()) =>
271+
p.makeCopy(Array(Cast(left, StringType), Cast(right, StringType)))
272+
273+
case p @ BinaryComparison(left @ StringType(), right) if right.dataType != StringType =>
274+
p.makeCopy(Array(Cast(left, DoubleType), right))
275+
case p @ BinaryComparison(left, right @ StringType()) if left.dataType != StringType =>
276+
p.makeCopy(Array(left, Cast(right, DoubleType)))
273277

274278
case i @ In(a @ DateType(), b) if b.forall(_.dataType == StringType) =>
275279
i.makeCopy(Array(Cast(a, StringType), b))
@@ -364,22 +368,22 @@ trait HiveTypeCoercion {
364368
// fix decimal precision for union
365369
case u @ Union(left, right) if u.childrenResolved && !u.resolved =>
366370
val castedInput = left.output.zip(right.output).map {
367-
case (l, r) if l.dataType != r.dataType =>
368-
(l.dataType, r.dataType) match {
371+
case (lhs, rhs) if lhs.dataType != rhs.dataType =>
372+
(lhs.dataType, rhs.dataType) match {
369373
case (DecimalType.Fixed(p1, s1), DecimalType.Fixed(p2, s2)) =>
370374
// Union decimals with precision/scale p1/s2 and p2/s2 will be promoted to
371375
// DecimalType(max(s1, s2) + max(p1-s1, p2-s2), max(s1, s2))
372376
val fixedType = DecimalType(max(s1, s2) + max(p1 - s1, p2 - s2), max(s1, s2))
373-
(Alias(Cast(l, fixedType), l.name)(), Alias(Cast(r, fixedType), r.name)())
377+
(Alias(Cast(lhs, fixedType), lhs.name)(), Alias(Cast(rhs, fixedType), rhs.name)())
374378
case (t, DecimalType.Fixed(p, s)) if intTypeToFixed.contains(t) =>
375-
(Alias(Cast(l, intTypeToFixed(t)), l.name)(), r)
379+
(Alias(Cast(lhs, intTypeToFixed(t)), lhs.name)(), rhs)
376380
case (DecimalType.Fixed(p, s), t) if intTypeToFixed.contains(t) =>
377-
(l, Alias(Cast(r, intTypeToFixed(t)), r.name)())
381+
(lhs, Alias(Cast(rhs, intTypeToFixed(t)), rhs.name)())
378382
case (t, DecimalType.Fixed(p, s)) if floatTypeToFixed.contains(t) =>
379-
(Alias(Cast(l, floatTypeToFixed(t)), l.name)(), r)
383+
(Alias(Cast(lhs, floatTypeToFixed(t)), lhs.name)(), rhs)
380384
case (DecimalType.Fixed(p, s), t) if floatTypeToFixed.contains(t) =>
381-
(l, Alias(Cast(r, floatTypeToFixed(t)), r.name)())
382-
case _ => (l, r)
385+
(lhs, Alias(Cast(rhs, floatTypeToFixed(t)), rhs.name)())
386+
case _ => (lhs, rhs)
383387
}
384388
case other => other
385389
}
@@ -452,16 +456,16 @@ trait HiveTypeCoercion {
452456

453457
// Promote integers inside a binary expression with fixed-precision decimals to decimals,
454458
// and fixed-precision decimals in an expression with floats / doubles to doubles
455-
case b @ BinaryExpression(l, r) if l.dataType != r.dataType =>
456-
(l.dataType, r.dataType) match {
459+
case b @ BinaryExpression(left, right) if left.dataType != right.dataType =>
460+
(left.dataType, right.dataType) match {
457461
case (t, DecimalType.Fixed(p, s)) if intTypeToFixed.contains(t) =>
458-
b.makeCopy(Array(Cast(l, intTypeToFixed(t)), r))
462+
b.makeCopy(Array(Cast(left, intTypeToFixed(t)), right))
459463
case (DecimalType.Fixed(p, s), t) if intTypeToFixed.contains(t) =>
460-
b.makeCopy(Array(l, Cast(r, intTypeToFixed(t))))
464+
b.makeCopy(Array(left, Cast(right, intTypeToFixed(t))))
461465
case (t, DecimalType.Fixed(p, s)) if isFloat(t) =>
462-
b.makeCopy(Array(l, Cast(r, DoubleType)))
466+
b.makeCopy(Array(left, Cast(right, DoubleType)))
463467
case (DecimalType.Fixed(p, s), t) if isFloat(t) =>
464-
b.makeCopy(Array(Cast(l, DoubleType), r))
468+
b.makeCopy(Array(Cast(left, DoubleType), right))
465469
case _ =>
466470
b
467471
}
@@ -510,31 +514,31 @@ trait HiveTypeCoercion {
510514
// all other cases are considered as false.
511515

512516
// We may simplify the expression if one side is literal numeric values
513-
case EqualTo(l @ BooleanType(), Literal(value, _: NumericType))
514-
if trueValues.contains(value) => l
515-
case EqualTo(l @ BooleanType(), Literal(value, _: NumericType))
516-
if falseValues.contains(value) => Not(l)
517-
case EqualTo(Literal(value, _: NumericType), r @ BooleanType())
518-
if trueValues.contains(value) => r
519-
case EqualTo(Literal(value, _: NumericType), r @ BooleanType())
520-
if falseValues.contains(value) => Not(r)
521-
case EqualNullSafe(l @ BooleanType(), Literal(value, _: NumericType))
522-
if trueValues.contains(value) => And(IsNotNull(l), l)
523-
case EqualNullSafe(l @ BooleanType(), Literal(value, _: NumericType))
524-
if falseValues.contains(value) => And(IsNotNull(l), Not(l))
525-
case EqualNullSafe(Literal(value, _: NumericType), r @ BooleanType())
526-
if trueValues.contains(value) => And(IsNotNull(r), r)
527-
case EqualNullSafe(Literal(value, _: NumericType), r @ BooleanType())
528-
if falseValues.contains(value) => And(IsNotNull(r), Not(r))
529-
530-
case EqualTo(l @ BooleanType(), r @ NumericType()) =>
531-
transform(l , r)
532-
case EqualTo(l @ NumericType(), r @ BooleanType()) =>
533-
transform(r, l)
534-
case EqualNullSafe(l @ BooleanType(), r @ NumericType()) =>
535-
transformNullSafe(l, r)
536-
case EqualNullSafe(l @ NumericType(), r @ BooleanType()) =>
537-
transformNullSafe(r, l)
517+
case EqualTo(left @ BooleanType(), Literal(value, _: NumericType))
518+
if trueValues.contains(value) => left
519+
case EqualTo(left @ BooleanType(), Literal(value, _: NumericType))
520+
if falseValues.contains(value) => Not(left)
521+
case EqualTo(Literal(value, _: NumericType), right @ BooleanType())
522+
if trueValues.contains(value) => right
523+
case EqualTo(Literal(value, _: NumericType), right @ BooleanType())
524+
if falseValues.contains(value) => Not(right)
525+
case EqualNullSafe(left @ BooleanType(), Literal(value, _: NumericType))
526+
if trueValues.contains(value) => And(IsNotNull(left), left)
527+
case EqualNullSafe(left @ BooleanType(), Literal(value, _: NumericType))
528+
if falseValues.contains(value) => And(IsNotNull(left), Not(left))
529+
case EqualNullSafe(Literal(value, _: NumericType), right @ BooleanType())
530+
if trueValues.contains(value) => And(IsNotNull(right), right)
531+
case EqualNullSafe(Literal(value, _: NumericType), right @ BooleanType())
532+
if falseValues.contains(value) => And(IsNotNull(right), Not(right))
533+
534+
case EqualTo(left @ BooleanType(), right @ NumericType()) =>
535+
transform(left , right)
536+
case EqualTo(left @ NumericType(), right @ BooleanType()) =>
537+
transform(right, left)
538+
case EqualNullSafe(left @ BooleanType(), right @ NumericType()) =>
539+
transformNullSafe(left, right)
540+
case EqualNullSafe(left @ NumericType(), right @ BooleanType()) =>
541+
transformNullSafe(right, left)
538542
}
539543
}
540544

0 commit comments

Comments
 (0)