From issues-return-210510-archive-asf-public=cust-asf.ponee.io@spark.apache.org Tue Dec 11 04:47:05 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 330C1180648 for ; Tue, 11 Dec 2018 04:47:05 +0100 (CET) Received: (qmail 85597 invoked by uid 500); 11 Dec 2018 03:47:04 -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 85584 invoked by uid 99); 11 Dec 2018 03:47:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Dec 2018 03:47:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id BA0AFC0359 for ; Tue, 11 Dec 2018 03:47:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.501 X-Spam-Level: X-Spam-Status: No, score=-109.501 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id gEjqIvtMh776 for ; Tue, 11 Dec 2018 03:47:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 4C1D660D12 for ; Tue, 11 Dec 2018 03:47:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 8895EE0E3E for ; Tue, 11 Dec 2018 03:47:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 42580252F2 for ; Tue, 11 Dec 2018 03:47:00 +0000 (UTC) Date: Tue, 11 Dec 2018 03:47:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@spark.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (SPARK-26078) WHERE .. IN fails to filter rows when used in combination with UNION MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/SPARK-26078?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D167= 16106#comment-16716106 ]=20 ASF GitHub Bot commented on SPARK-26078: ---------------------------------------- cloud-fan commented on a change in pull request #23057: [SPARK-26078][SQL] = Dedup self-join attributes on IN subqueries URL: https://github.com/apache/spark/pull/23057#discussion_r240465174 =20 =20 ########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optim= izer/subquery.scala ########## @@ -92,18 +114,20 @@ object RewritePredicateSubquery extends Rule[LogicalP= lan] with PredicateHelper { // Deduplicate conflicting attributes if any. dedupJoin(Join(outerPlan, sub, LeftAnti, joinCond)) =20 Review comment: Looks like we don't need `dedupJoin`, but always dedup the subquery befo= re putting it in a join. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. =20 For queries about this service, please contact Infrastructure at: users@infra.apache.org > WHERE .. IN fails to filter rows when used in combination with UNION > -------------------------------------------------------------------- > > Key: SPARK-26078 > URL: https://issues.apache.org/jira/browse/SPARK-26078 > Project: Spark > Issue Type: Bug > Components: SQL > Affects Versions: 2.3.1, 2.4.0 > Reporter: Arttu Voutilainen > Priority: Blocker > Labels: correctness > > Hey, > We encountered a case where Spark SQL does not seem to handle WHERE .. IN= correctly, when used in combination with UNION, but instead returns also r= ows that do not fulfill the condition. Swapping the order of the datasets i= n the UNION makes the problem go away. Repro below: > =C2=A0 > {code} > sql =3D SQLContext(sc) > a =3D spark.createDataFrame([{'id': 'a', 'num': 2}, {'id':'b', 'num':1}]) > b =3D spark.createDataFrame([{'id': 'a', 'num': 2}, {'id':'b', 'num':1}]) > a.registerTempTable('a') > b.registerTempTable('b') > bug =3D sql.sql(""" > SELECT id,num,source FROM > ( > SELECT id, num, 'a' as source FROM a > UNION ALL > SELECT id, num, 'b' as source FROM b > ) AS c > WHERE c.id IN (SELECT id FROM b WHERE num =3D 2) > """) > no_bug =3D sql.sql(""" > SELECT id,num,source FROM > ( > SELECT id, num, 'b' as source FROM b > UNION ALL > SELECT id, num, 'a' as source FROM a > ) AS c > WHERE c.id IN (SELECT id FROM b WHERE num =3D 2) > """) > bug.show() > no_bug.show() > bug.explain(True) > no_bug.explain(True) > {code} > This results in one extra row in the "bug" DF coming from DF "b", that sh= ould not be there as it=C2=A0=C2=A0 > {code:java} > >>> bug.show() > +---+---+------+ > | id|num|source| > +---+---+------+ > | a| 2| a| > | a| 2| b| > | b| 1| b| > +---+---+------+ > >>> no_bug.show() > +---+---+------+ > | id|num|source| > +---+---+------+ > | a| 2| b| > | a| 2| a| > +---+---+------+ > {code} > =C2=A0The reason can be seen in the query plans: > {code:java} > >>> bug.explain(True) > ... > =3D=3D Optimized Logical Plan =3D=3D > Union > :- Project [id#0, num#1L, a AS source#136] > : +- Join LeftSemi, (id#0 =3D id#4) > : :- LogicalRDD [id#0, num#1L], false > : +- Project [id#4] > : +- Filter (isnotnull(num#5L) && (num#5L =3D 2)) > : +- LogicalRDD [id#4, num#5L], false > +- Join LeftSemi, (id#4#172 =3D id#4#172) > :- Project [id#4, num#5L, b AS source#137] > : +- LogicalRDD [id#4, num#5L], false > +- Project [id#4 AS id#4#172] > +- Filter (isnotnull(num#5L) && (num#5L =3D 2)) > +- LogicalRDD [id#4, num#5L], false > {code} > Note the line *+- Join LeftSemi, (id#4#172 =3D id#4#172)* - this conditio= n seems wrong, and I believe it causes the LeftSemi to return true for all = rows in the left-hand-side table, thus failing to filter as the WHERE .. IN= should. Compare with the non-buggy version, where both LeftSemi joins have= =C2=A0distinct #-things on both sides: > {code:java} > >>> no_bug.explain() > ... > =3D=3D Optimized Logical Plan =3D=3D > Union > :- Project [id#4, num#5L, b AS source#142] > : +- Join LeftSemi, (id#4 =3D id#4#173) > : :- LogicalRDD [id#4, num#5L], false > : +- Project [id#4 AS id#4#173] > : +- Filter (isnotnull(num#5L) && (num#5L =3D 2)) > : +- LogicalRDD [id#4, num#5L], false > +- Project [id#0, num#1L, a AS source#143] > +- Join LeftSemi, (id#0 =3D id#4#173) > :- LogicalRDD [id#0, num#1L], false > +- Project [id#4 AS id#4#173] > +- Filter (isnotnull(num#5L) && (num#5L =3D 2)) > +- LogicalRDD [id#4, num#5L], false > {code} > =C2=A0 > Best, > -Arttu=C2=A0 > =C2=A0 -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org For additional commands, e-mail: issues-help@spark.apache.org