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

    https://github.com/apache/flink/pull/1634#discussion_r52925323
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/codegen/OperatorCodeGen.scala
 ---
    @@ -18,20 +18,56 @@
     package org.apache.flink.api.table.codegen
     
     import org.apache.flink.api.common.typeinfo.BasicTypeInfo.BOOLEAN_TYPE_INFO
    -import org.apache.flink.api.common.typeinfo.TypeInformation
    +import org.apache.flink.api.common.typeinfo.{NumericTypeInfo, 
TypeInformation}
     import org.apache.flink.api.table.codegen.CodeGenUtils._
     
     object OperatorCodeGen {
     
    -   def generateArithmeticOperator(
    +  def generateArithmeticOperator(
           operator: String,
           nullCheck: Boolean,
           resultType: TypeInformation[_],
           left: GeneratedExpression,
           right: GeneratedExpression)
         : GeneratedExpression = {
    -    generateOperatorIfNotNull(nullCheck, resultType, left, right) {
    +    // String arithmetic // TODO rework
    +    if (isString(left)) {
    +      generateOperatorIfNotNull(nullCheck, resultType, left, right) {
           (leftTerm, rightTerm) => s"$leftTerm $operator $rightTerm"
    +      }
    +    }
    +    // Numeric arithmetic
    +    else if (isNumeric(left) && isNumeric(right)) {
    +      val leftType = left.resultType.asInstanceOf[NumericTypeInfo[_]]
    +      val rightType = right.resultType.asInstanceOf[NumericTypeInfo[_]]
    +
    +      generateOperatorIfNotNull(nullCheck, resultType, left, right) {
    +      (leftTerm, rightTerm) =>
    +        // insert auto casting for "narrowing primitive conversions"
    +        if (leftType != rightType) {
    +          // leftType can not be casted to rightType automatically -> 
narrow
    +          if (!leftType.shouldAutocastTo(rightType)) {
    --- End diff --
    
    Just checked, double is actually downcasted.
    The following test fails:
    ```
    val t = env.fromElements((100000.0d: Double, 1: Byte)).toTable.select('_1 + 
'_2)
    val expected = "100001.0"
    ```


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

Reply via email to