Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-7949

BinaryPredicate rewrite results in double cast

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • Impala 3.1.0
    • None
    • Frontend
    • None
    • ghx-label-4

    Description

      Consider the existing unit test: ExprRewriteRulesTest.TestNormalizeBinaryPredicatesRule, with this SELECT expression:

      cast(0 as double) = id
      

      The existing test case simply does a "toSql" on the rewritten expression, suppressing implicit casts, expecting:

      id = CAST(0 AS DOUBLE)
      

      However, if we examine the AST itself, or render the rewritten expression showing implicit casts, we see we get:

      CAST(id AS DOUBLE) = CAST(CAST(0 AS DOUBLE) AS DOUBLE)
      

      In this particular case, the double-case it benign as the constant-folding rule, if enabled, will remove the two casts. But, if the value were a column, the double casts would exist in the plan sent to the, resulting in an unnecessary extra step.

      The expected behavior is the function argument type propagation would not insert a cast if it is not needed.

      Researching a bit more, it seems this is an artifact of recent changes in toSql(). In the NumericLiteral, we always display the type as a cast. The query specified a cast also, so the outer cast comes from the original SQL, the inner from pushing the cast type into the numeric literal.

      This is not so much a bug as it is a muddling of the semantics. There is no reason to push the type into the numeric literal if an explicit cast exists.

      Attachments

        Activity

          People

            Unassigned Unassigned
            Paul.Rogers Paul Rogers
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: