Github user chenghao-intel commented on a diff in the pull request:
https://github.com/apache/spark/pull/2252#discussion_r17640727
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
---
@@ -129,3 +130,40 @@ case class MaxOf(left: Expression, right: Expression)
extends Expression {
override def toString = s"MaxOf($left, $right)"
}
+
+/**
+ * A function that get the power value of two parameters.
+ * First one is taken as base while second one taken as exponent
+ */
+case class Power(base: Expression, exponent: Expression) extends
Expression {
+ type EvaluatedType = Any
+
+ def dataType: DataType = {
+ if (!resolved) {
+ throw new UnresolvedException(this, s"Cannot resolve since $children
are not resolved")
+ }
+ DoubleType
+ }
+ override def foldable = base.foldable && exponent.foldable
+ def nullable: Boolean = base.nullable || exponent.nullable
+ override def toString = s"Power($base, $exponent)"
+
+ override def children = base :: exponent :: Nil
+
+ override def eval(input: Row): Any = {
+ def convertToDouble(num: EvaluatedType): Double = {
+ num match {
+ case d:Double => d
+ case i:Integer => i.doubleValue()
+ case f:Float => f.toDouble
+ }
+ }
+
+ val base_v = base.eval(input)
--- End diff --
Nit: Let's check if `base_v` is null first and then compute `exponent_v`,
probably performance gains in some cases.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]