Daniel Becker has uploaded this change for review. ( 
http://gerrit.cloudera.org:8080/19048


Change subject: IMPALA-10356: Analyzed query in explain plan is not right for 
insert with values clause
......................................................................

IMPALA-10356: Analyzed query in explain plan is not right for insert
with values clause

If the query contains a VALUES clause with a single value, the 'analyzed
query' in the level 2 explain plan contains a UNION where both sides are
the value from the VALUES clause. For

INSERT INTO double_tbl VALUES (-0.43149576573887316);

we get

SELECT CAST(-0.43149576573887316 AS DECIMAL(17,17))
UNION
SELECT CAST(-0.43149576573887316 AS DECIMAL(17,17));

This is because of a bug in 'SetOperationStmt::toSql()'; 'ValuesStmt's
are implemented as special 'UnionStmt's, which derive from
'SetOperationStmt'. 'SetOperationStmt::toSql()' implicitly assumes that
there are at least 2 operands and always prints the first one and the
last one separately, even if they are the same.

Note that 'ValuesStmt' is the only 'SetOperationStmt' that may contain a
single operand - it is syntactically impossible in SQL to create other
'SetOperationStmt's with only one operand.

This patch modifies 'SetOperationStmt::toSql()' so that if there is only
one operand, only that operand is printed (so there is no reference to
the set operation in the resulting string). This change does not affect
how such queries are handled, only how the analyzed query is printed.

Testing:
 - Extended AnalyzeStmtsTest.TestValuesStmt so it now also checks what
   VALUES clauses with one and two operands are rewritten to during
   analysis.

Change-Id: I952377ed14eba26e3774e7776eb81a95d1d8e76f
---
M fe/src/main/java/org/apache/impala/analysis/SetOperationStmt.java
M fe/src/test/java/org/apache/impala/analysis/AnalyzeStmtsTest.java
2 files changed, 29 insertions(+), 11 deletions(-)



  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/48/19048/1
--
To view, visit http://gerrit.cloudera.org:8080/19048
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I952377ed14eba26e3774e7776eb81a95d1d8e76f
Gerrit-Change-Number: 19048
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Becker <daniel.bec...@cloudera.com>

Reply via email to