Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6716#discussion_r32074563
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala
 ---
    @@ -21,8 +21,37 @@ import 
org.apache.spark.sql.catalyst.expressions.codegen._
     import org.apache.spark.sql.types.{DataType, DoubleType}
     
     /**
    + * A leaf expression specifically for math constants. Math constants 
expect no input.
    + * @param c The math constant.
    + * @param name The short name of the function
    + */
    +abstract class LeafMathExpression(c: Double, name: String)
    +  extends LeafExpression with Serializable {
    +  self: Product =>
    +
    +  override def dataType: DataType = DoubleType
    +  override def foldable: Boolean = true
    +  override def nullable: Boolean = false
    +  override def toString: String = s"$name()"
    +
    +  override def eval(input: Row): Any = c
    +
    +  // name of constant in java.lang.Math
    +  def constName: String = name
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): 
String = {
    +    s"""
    +      boolean ${ev.isNull} = false;
    +      ${ctx.javaType(dataType)} ${ev.primitive} = 
${ctx.defaultValue(dataType)};
    --- End diff --
    
    why not just ...
    ```
     ${ctx.javaType(dataType)} ${ev.primitive} = ${ev.primitive} = 
java.lang.Math.$constName;
    ```


---
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

Reply via email to