Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3DA6C200BAC for ; Tue, 11 Oct 2016 22:37:32 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3C32B160AC3; Tue, 11 Oct 2016 20:37:32 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 61A93160AE6 for ; Tue, 11 Oct 2016 22:37:31 +0200 (CEST) Received: (qmail 51200 invoked by uid 500); 11 Oct 2016 20:37:20 -0000 Mailing-List: contact issues-help@spark.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@spark.apache.org Received: (qmail 51069 invoked by uid 99); 11 Oct 2016 20:37:20 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Oct 2016 20:37:20 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 72B852C4C72 for ; Tue, 11 Oct 2016 20:37:20 +0000 (UTC) Date: Tue, 11 Oct 2016 20:37:20 +0000 (UTC) From: "Yin Huai (JIRA)" To: issues@spark.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (SPARK-17863) SELECT distinct does not work if there is a order by clause MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 11 Oct 2016 20:37:32 -0000 [ https://issues.apache.org/jira/browse/SPARK-17863?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Yin Huai updated SPARK-17863: ----------------------------- Description: {code} select distinct struct.a, struct.b from ( select named_struct('a', 1, 'b', 2, 'c', 3) as struct union all select named_struct('a', 1, 'b', 2, 'c', 4) as struct) tmp order by struct.a, struct.b {code} This query generates {code} +---+---+ | a| b| +---+---+ | 1| 2| | 1| 2| +---+---+ {code} The plan is wrong because the analyze somehow added {{struct#21805}} to the project list, which changes the semantic of the distinct (basically, the query is changed to {{select distinct struct.a, struct.b, struct}} from {{select distinct struct.a, struct.b}}). {code} == Parsed Logical Plan == 'Sort ['struct.a ASC, 'struct.b ASC], true +- 'Distinct +- 'Project ['struct.a, 'struct.b] +- 'SubqueryAlias tmp +- 'Union :- 'Project ['named_struct(a, 1, b, 2, c, 3) AS struct#21805] : +- OneRowRelation$ +- 'Project ['named_struct(a, 1, b, 2, c, 4) AS struct#21806] +- OneRowRelation$ == Analyzed Logical Plan == a: int, b: int Project [a#21819, b#21820] +- Sort [struct#21805.a ASC, struct#21805.b ASC], true +- Distinct +- Project [struct#21805.a AS a#21819, struct#21805.b AS b#21820, struct#21805] +- SubqueryAlias tmp +- Union :- Project [named_struct(a, 1, b, 2, c, 3) AS struct#21805] : +- OneRowRelation$ +- Project [named_struct(a, 1, b, 2, c, 4) AS struct#21806] +- OneRowRelation$ == Optimized Logical Plan == Project [a#21819, b#21820] +- Sort [struct#21805.a ASC, struct#21805.b ASC], true +- Aggregate [a#21819, b#21820, struct#21805], [a#21819, b#21820, struct#21805] +- Union :- Project [1 AS a#21819, 2 AS b#21820, [1,2,3] AS struct#21805] : +- OneRowRelation$ +- Project [1 AS a#21819, 2 AS b#21820, [1,2,4] AS struct#21806] +- OneRowRelation$ == Physical Plan == *Project [a#21819, b#21820] +- *Sort [struct#21805.a ASC, struct#21805.b ASC], true, 0 +- Exchange rangepartitioning(struct#21805.a ASC, struct#21805.b ASC, 200) +- *HashAggregate(keys=[a#21819, b#21820, struct#21805], functions=[], output=[a#21819, b#21820, struct#21805]) +- Exchange hashpartitioning(a#21819, b#21820, struct#21805, 200) +- *HashAggregate(keys=[a#21819, b#21820, struct#21805], functions=[], output=[a#21819, b#21820, struct#21805]) +- Union :- *Project [1 AS a#21819, 2 AS b#21820, [1,2,3] AS struct#21805] : +- Scan OneRowRelation[] +- *Project [1 AS a#21819, 2 AS b#21820, [1,2,4] AS struct#21806] +- Scan OneRowRelation[] {code} was: {code} select distinct struct.a, struct.b from ( select named_struct('a', 1, 'b', 2, 'c', 3) as struct union all select named_struct('a', 1, 'b', 2, 'c', 4) as struct) tmp order by struct.a, struct.b {code} This query generates {code} +---+---+ | a| b| +---+---+ | 1| 2| | 1| 2| +---+---+ {code} The plan is wrong {code} == Parsed Logical Plan == 'Sort ['struct.a ASC, 'struct.b ASC], true +- 'Distinct +- 'Project ['struct.a, 'struct.b] +- 'SubqueryAlias tmp +- 'Union :- 'Project ['named_struct(a, 1, b, 2, c, 3) AS struct#21805] : +- OneRowRelation$ +- 'Project ['named_struct(a, 1, b, 2, c, 4) AS struct#21806] +- OneRowRelation$ == Analyzed Logical Plan == a: int, b: int Project [a#21819, b#21820] +- Sort [struct#21805.a ASC, struct#21805.b ASC], true +- Distinct +- Project [struct#21805.a AS a#21819, struct#21805.b AS b#21820, struct#21805] +- SubqueryAlias tmp +- Union :- Project [named_struct(a, 1, b, 2, c, 3) AS struct#21805] : +- OneRowRelation$ +- Project [named_struct(a, 1, b, 2, c, 4) AS struct#21806] +- OneRowRelation$ == Optimized Logical Plan == Project [a#21819, b#21820] +- Sort [struct#21805.a ASC, struct#21805.b ASC], true +- Aggregate [a#21819, b#21820, struct#21805], [a#21819, b#21820, struct#21805] +- Union :- Project [1 AS a#21819, 2 AS b#21820, [1,2,3] AS struct#21805] : +- OneRowRelation$ +- Project [1 AS a#21819, 2 AS b#21820, [1,2,4] AS struct#21806] +- OneRowRelation$ == Physical Plan == *Project [a#21819, b#21820] +- *Sort [struct#21805.a ASC, struct#21805.b ASC], true, 0 +- Exchange rangepartitioning(struct#21805.a ASC, struct#21805.b ASC, 200) +- *HashAggregate(keys=[a#21819, b#21820, struct#21805], functions=[], output=[a#21819, b#21820, struct#21805]) +- Exchange hashpartitioning(a#21819, b#21820, struct#21805, 200) +- *HashAggregate(keys=[a#21819, b#21820, struct#21805], functions=[], output=[a#21819, b#21820, struct#21805]) +- Union :- *Project [1 AS a#21819, 2 AS b#21820, [1,2,3] AS struct#21805] : +- Scan OneRowRelation[] +- *Project [1 AS a#21819, 2 AS b#21820, [1,2,4] AS struct#21806] +- Scan OneRowRelation[] {code} > SELECT distinct does not work if there is a order by clause > ----------------------------------------------------------- > > Key: SPARK-17863 > URL: https://issues.apache.org/jira/browse/SPARK-17863 > Project: Spark > Issue Type: Bug > Components: SQL > Reporter: Yin Huai > Priority: Critical > Labels: correctness > > {code} > select distinct struct.a, struct.b > from ( > select named_struct('a', 1, 'b', 2, 'c', 3) as struct > union all > select named_struct('a', 1, 'b', 2, 'c', 4) as struct) tmp > order by struct.a, struct.b > {code} > This query generates > {code} > +---+---+ > | a| b| > +---+---+ > | 1| 2| > | 1| 2| > +---+---+ > {code} > The plan is wrong because the analyze somehow added {{struct#21805}} to the project list, which changes the semantic of the distinct (basically, the query is changed to {{select distinct struct.a, struct.b, struct}} from {{select distinct struct.a, struct.b}}). > {code} > == Parsed Logical Plan == > 'Sort ['struct.a ASC, 'struct.b ASC], true > +- 'Distinct > +- 'Project ['struct.a, 'struct.b] > +- 'SubqueryAlias tmp > +- 'Union > :- 'Project ['named_struct(a, 1, b, 2, c, 3) AS struct#21805] > : +- OneRowRelation$ > +- 'Project ['named_struct(a, 1, b, 2, c, 4) AS struct#21806] > +- OneRowRelation$ > == Analyzed Logical Plan == > a: int, b: int > Project [a#21819, b#21820] > +- Sort [struct#21805.a ASC, struct#21805.b ASC], true > +- Distinct > +- Project [struct#21805.a AS a#21819, struct#21805.b AS b#21820, struct#21805] > +- SubqueryAlias tmp > +- Union > :- Project [named_struct(a, 1, b, 2, c, 3) AS struct#21805] > : +- OneRowRelation$ > +- Project [named_struct(a, 1, b, 2, c, 4) AS struct#21806] > +- OneRowRelation$ > == Optimized Logical Plan == > Project [a#21819, b#21820] > +- Sort [struct#21805.a ASC, struct#21805.b ASC], true > +- Aggregate [a#21819, b#21820, struct#21805], [a#21819, b#21820, struct#21805] > +- Union > :- Project [1 AS a#21819, 2 AS b#21820, [1,2,3] AS struct#21805] > : +- OneRowRelation$ > +- Project [1 AS a#21819, 2 AS b#21820, [1,2,4] AS struct#21806] > +- OneRowRelation$ > == Physical Plan == > *Project [a#21819, b#21820] > +- *Sort [struct#21805.a ASC, struct#21805.b ASC], true, 0 > +- Exchange rangepartitioning(struct#21805.a ASC, struct#21805.b ASC, 200) > +- *HashAggregate(keys=[a#21819, b#21820, struct#21805], functions=[], output=[a#21819, b#21820, struct#21805]) > +- Exchange hashpartitioning(a#21819, b#21820, struct#21805, 200) > +- *HashAggregate(keys=[a#21819, b#21820, struct#21805], functions=[], output=[a#21819, b#21820, struct#21805]) > +- Union > :- *Project [1 AS a#21819, 2 AS b#21820, [1,2,3] AS struct#21805] > : +- Scan OneRowRelation[] > +- *Project [1 AS a#21819, 2 AS b#21820, [1,2,4] AS struct#21806] > +- Scan OneRowRelation[] > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org For additional commands, e-mail: issues-help@spark.apache.org