From issues-return-230543-apmail-spark-issues-archive=spark.apache.org@spark.apache.org Tue Jul 2 01:03:01 2019 Return-Path: X-Original-To: apmail-spark-issues-archive@minotaur.apache.org Delivered-To: apmail-spark-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id A027C1907D for ; Tue, 2 Jul 2019 01:03:01 +0000 (UTC) Received: (qmail 90562 invoked by uid 500); 2 Jul 2019 01:03:01 -0000 Delivered-To: apmail-spark-issues-archive@spark.apache.org Received: (qmail 90534 invoked by uid 500); 2 Jul 2019 01:03:01 -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 90523 invoked by uid 99); 2 Jul 2019 01:03:01 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jul 2019 01:03:01 +0000 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 42699E062E for ; Tue, 2 Jul 2019 01:03: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 0837125FEF for ; Tue, 2 Jul 2019 01:03:00 +0000 (UTC) Date: Tue, 2 Jul 2019 01:03:00 +0000 (UTC) From: "Andrew Leverentz (JIRA)" To: issues@spark.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (SPARK-28225) Unexpected behavior for Window functions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 Andrew Leverentz created SPARK-28225: ---------------------------------------- Summary: Unexpected behavior for Window functions Key: SPARK-28225 URL: https://issues.apache.org/jira/browse/SPARK-28225 Project: Spark Issue Type: Bug Components: SQL Affects Versions: 2.4.0 Reporter: Andrew Leverentz I've noticed some odd behavior when combining the "first" aggregate functio= n with an ordered Window. In particular, I'm=C2=A0working with columns created using the syntax {code} first($"y", ignoreNulls =3D true).over(Window.orderBy($"x")) {code} Below, I'm including some=C2=A0code=C2=A0which reproduces this issue in a D= atabricks notebook. *Code:* {code:java} import org.apache.spark.sql.functions.first import org.apache.spark.sql.expressions.Window import org.apache.spark.sql.Row import org.apache.spark.sql.types.{StructType,StructField,IntegerType} val schema =3D StructType(Seq( StructField("x", IntegerType, false), StructField("y", IntegerType, true), StructField("z", IntegerType, true) )) val input =3D spark.createDataFrame(sc.parallelize(Seq( Row(101, null, 11), Row(102, null, 12), Row(103, null, 13), Row(203, 24, null), Row(201, 26, null), Row(202, 25, null) )), schema =3D schema) input.show val output =3D input .withColumn("u1", first($"y", ignoreNulls =3D true).over(Window.orderBy($= "x".asc_nulls_last))) .withColumn("u2", first($"y", ignoreNulls =3D true).over(Window.orderBy($= "x".asc))) .withColumn("u3", first($"y", ignoreNulls =3D true).over(Window.orderBy($= "x".desc_nulls_last))) .withColumn("u4", first($"y", ignoreNulls =3D true).over(Window.orderBy($= "x".desc))) .withColumn("u5", first($"z", ignoreNulls =3D true).over(Window.orderBy($= "x".asc_nulls_last))) .withColumn("u6", first($"z", ignoreNulls =3D true).over(Window.orderBy($= "x".asc))) .withColumn("u7", first($"z", ignoreNulls =3D true).over(Window.orderBy($= "x".desc_nulls_last))) .withColumn("u8", first($"z", ignoreNulls =3D true).over(Window.orderBy($= "x".desc))) output.show {code} *Expectation:* Based on my understanding of how ordered-Window and aggregate functions wor= k, the results I expected to see were: * u1 =3D u2 =3D constant value of 26 * u3 =3D u4 =3D constant value of 24 * u5 =3D u6 =3D constant value of 11 * u7 =3D u8 =3D constant value of 13 However,=C2=A0columns u1, u2, u7, and u8 contain some unexpected nulls.=C2= =A0 *Results:* {code:java} +---+----+----+----+----+---+---+---+---+----+----+ | x| y| z| u1| u2| u3| u4| u5| u6| u7| u8| +---+----+----+----+----+---+---+---+---+----+----+ |203| 24|null| 26| 26| 24| 24| 11| 11|null|null| |202| 25|null| 26| 26| 24| 24| 11| 11|null|null| |201| 26|null| 26| 26| 24| 24| 11| 11|null|null| |103|null| 13|null|null| 24| 24| 11| 11| 13| 13| |102|null| 12|null|null| 24| 24| 11| 11| 13| 13| |101|null| 11|null|null| 24| 24| 11| 11| 13| 13| +---+----+----+----+----+---+---+---+---+----+----+ {code} -- 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