Skip to content

Commit

Permalink
Remove unnecessary conf checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jovanm-db committed Jan 6, 2025
1 parent b6e4d7c commit f521a23
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package org.apache.spark.sql.catalyst.analysis
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.internal.types.{AbstractArrayType, AbstractStringType}
import org.apache.spark.sql.types._
import org.apache.spark.sql.types.UpCastRule.numericPrecedence
Expand Down Expand Up @@ -104,8 +103,7 @@ object AnsiTypeCoercion extends TypeCoercionBase {
case (NullType, t1) => Some(t1)
case (t1, NullType) => Some(t1)

case(s1: StringType, s2: StringType) if SQLConf.get.preserveCharVarcharTypeInfo =>
StringHelper.tightestCommonString(s1, s2)
case(s1: StringType, s2: StringType) => StringHelper.tightestCommonString(s1, s2)

case (t1: IntegralType, t2: DecimalType) if t2.isWiderThan(t1) =>
Some(t2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ object TypeCoercion extends TypeCoercionBase {
case (NullType, t1) => Some(t1)
case (t1, NullType) => Some(t1)

case(s1: StringType, s2: StringType) if SQLConf.get.preserveCharVarcharTypeInfo =>
StringHelper.tightestCommonString(s1, s2)
case(s1: StringType, s2: StringType) => StringHelper.tightestCommonString(s1, s2)

case (t1: IntegralType, t2: DecimalType) if t2.isWiderThan(t1) =>
Some(t2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ object Cast extends QueryErrorsBase {

case (NullType, _) => true

case (_, CharType(_) | VarcharType(_)) if !SQLConf.get.preserveCharVarcharTypeInfo => false
case (_, _: StringType) => true
case (CharType(_) | VarcharType(_), _) if !SQLConf.get.preserveCharVarcharTypeInfo => false

case (_: StringType, _: BinaryType) => true

Expand Down Expand Up @@ -200,9 +198,7 @@ object Cast extends QueryErrorsBase {

case (NullType, _) => true

case (_, CharType(_) | VarcharType(_)) if !SQLConf.get.preserveCharVarcharTypeInfo => false
case (_, _: StringType) => true
case (CharType(_) | VarcharType(_), _) if !SQLConf.get.preserveCharVarcharTypeInfo => false

case (_: StringType, BinaryType) => true
case (_: IntegralType, BinaryType) => true
Expand Down Expand Up @@ -320,9 +316,8 @@ object Cast extends QueryErrorsBase {
case _ if from == to => true
case (NullType, _) => true
case (_: NumericType, _: NumericType) => true
case (_: StringType, _: StringType) => true
case (_: AtomicType, s: StringType) if StringHelper.isPlainString(s) => true
case (_: CalendarIntervalType, s: StringType) if StringHelper.isPlainString(s) => true
case (_: AtomicType, _: StringType) => true
case (_: CalendarIntervalType, _: StringType) => true
case (_: DatetimeType, _: DatetimeType) => true

case (ArrayType(fromType, fn), ArrayType(toType, tn)) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,10 @@ case class ToPrettyString(child: Expression, timeZoneId: Option[String] = None)

override protected val binaryFormatter: BinaryFormatter = ToStringBase.getBinaryFormatter

private[this] lazy val castFunc: Any => UTF8String = child.dataType match {
case CharType(length) if SQLConf.get.preserveCharVarcharTypeInfo =>
castToChar(child.dataType, length)
case VarcharType(length) if SQLConf.get.preserveCharVarcharTypeInfo =>
castToVarchar(child.dataType, length)
case _ => castToString(child.dataType)
}
private[this] lazy val castFunc: Any => UTF8String = castToString(child.dataType match {
case CharType(_) => StringType
case dt => dt
})

override def eval(input: InternalRow): Any = {
val v = child.eval(input)
Expand Down

0 comments on commit f521a23

Please sign in to comment.