Github user yucai commented on the pull request: https://github.com/apache/spark/pull/11212#issuecomment-186077126 @rxin I tried your suggestion like creating PowDecimal for Decimal specially like below: ``` case class PowDecimal(left: Expression, right: Expression) extends BinaryMathExpression(math.pow, "POWER") { override def inputTypes: Seq[AbstractDataType] = Seq(DecimalType, IntegerType) ... } case class Pow(left: Expression, right: Expression) extends BinaryMathExpression(math.pow, "POWER") { ... } ``` But one concern is when "select pow(cast(2 as decimal(5,2)), 3)", how to make the "PowDecimal" node created? The current path will create "Pow" node anyway. So we think of maybe we can still put Decimal processing in "Pow", but byte/short/etc. to integer in type coercion, like below: ``` case class Pow(left: Expression, right: Expression) extends BinaryMathExpression(math.pow, "POWER") { override def inputTypes: Seq[AbstractDataType] = Seq(NumericType, NumericType) override def dataType: DataType = (left.dataType, right.dataType) match { case (dt: DecimalType, ByteType | ShortType | IntegerType) => dt case _ => DoubleType } protected override def nullSafeEval(input1: Any, input2: Any): Any = (left.dataType, right.dataType) match { case (dt: DecimalType, _) => input1.asInstanceOf[Decimal].pow(input2.asInstanceOf[Int]) case _ => math.pow(input1.asInstanceOf[Double], input2.asInstanceOf[Double]) } override def genCode(ctx: CodegenContext, ev: ExprCode): String = ... } In HiveTypeCoercion: ``` object PowCoercion extends Rule[LogicalPlan] { def apply(plan: LogicalPlan): LogicalPlan = plan resolveExpressions { case e if !e.childrenResolved => e case e @ Pow(left, right) => (left.dataType, right.dataType) match { case (dt: DecimalType, IntegerType) => e case (DoubleType, DoubleType) => e case (dt: DecimalType, ByteType | ShortType) => Pow(left, Cast(right, IntegerType)) case _ => Pow(Cast(left, DoubleType), Cast(right, DoubleType)) } } } ``` How do you think this way?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org