You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@impala.apache.org by "Daniel Becker (Code Review)" <ge...@cloudera.org> on 2022/09/28 10:58:41 UTC

[Impala-ASF-CR] IMPALA-10356: Fix SetOperationStmt::toSql() for VALUES statement with single value

Daniel Becker has uploaded a new patch set (#2). ( http://gerrit.cloudera.org:8080/19048 )

Change subject: IMPALA-10356: Fix SetOperationStmt::toSql() for VALUES statement with single value
......................................................................

IMPALA-10356: Fix SetOperationStmt::toSql() for VALUES statement with
single value

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/2
-- 
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: newpatchset
Gerrit-Change-Id: I952377ed14eba26e3774e7776eb81a95d1d8e76f
Gerrit-Change-Number: 19048
Gerrit-PatchSet: 2
Gerrit-Owner: Daniel Becker <da...@cloudera.com>
Gerrit-Reviewer: Csaba Ringhofer <cs...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Peter Rozsa <pr...@cloudera.com>