Paul Rogers created IMPALA-8000: ----------------------------------- Summary: Implied cast of NULL done for expressions, not literals Key: IMPALA-8000 URL: https://issues.apache.org/jira/browse/IMPALA-8000 Project: IMPALA Issue Type: Bug Components: Frontend Affects Versions: Impala 3.1.0 Reporter: Paul Rogers Assignee: Paul Rogers
Impala can combine a cast with a null to create a typed null: {noformat} CAST(NULL AS SMALLINT) --> NULL:SMALLINT {code} Where the notation on the right indicates a NULL of type SMALLINT. However, the analyzer appears to apply this optimization inconsistently. It is done with constant folding: {code:java} String query = "SELECT 1 + NULL AS c" + " from functional.alltypestiny"; AnalysisContext ctx = createAnalysisCtx(); ctx.getQueryOptions().setEnable_expr_rewrites(true); SelectStmt select = (SelectStmt) AnalyzesOk(query, ctx); Expr expr = select.getSelectList().getItems().get(0).getExpr(); assertEquals(ScalarType.SMALLINT, expr.getType()); assertTrue(expr instanceof NullLiteral); {code} But not for the near-identical result with an explicit cast: {code:java} String query = "SELECT CAST(NULL AS SMALLINT) AS c" + " from functional.alltypestiny"; … // Same as above assertEquals(ScalarType.SMALLINT, expr.getType()); // Fails, is actually CastExpr //assertTrue(expr instanceof NullLiteral); {code} Interestingly, the NULL inside the CAST does have its type set to SMALLINT, so the CAST is unnecessary. Expected the analyzer to apply the rule consistently so that other rules don’t have to handle both cases. -- This message was sent by Atlassian JIRA (v7.6.3#76005)