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 D58DF200C53 for ; Tue, 7 Mar 2017 01:53:39 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D45ED160B76; Tue, 7 Mar 2017 00:53:39 +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 2854D160B81 for ; Tue, 7 Mar 2017 01:53:39 +0100 (CET) Received: (qmail 85599 invoked by uid 500); 7 Mar 2017 00:53:38 -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 85399 invoked by uid 99); 7 Mar 2017 00:53:37 -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, 07 Mar 2017 00:53:37 +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 5C759C18A3 for ; Tue, 7 Mar 2017 00:53:37 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.651 X-Spam-Level: X-Spam-Status: No, score=0.651 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_NEUTRAL=0.652] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 1f6t2tKW3jr0 for ; Tue, 7 Mar 2017 00:53:36 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 5B92160DC0 for ; Tue, 7 Mar 2017 00:53:36 +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 A440DE08C3 for ; Tue, 7 Mar 2017 00:53:33 +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 15AD524176 for ; Tue, 7 Mar 2017 00:53:33 +0000 (UTC) Date: Tue, 7 Mar 2017 00:53:33 +0000 (UTC) From: "Franklyn Dsouza (JIRA)" To: issues@spark.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (SPARK-19844) UDF in when control function is executed before the when clause is evaluated. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 07 Mar 2017 00:53:40 -0000 Franklyn Dsouza created SPARK-19844: --------------------------------------- Summary: UDF in when control function is executed before the when clause is evaluated. Key: SPARK-19844 URL: https://issues.apache.org/jira/browse/SPARK-19844 Project: Spark Issue Type: Bug Components: PySpark, SQL Affects Versions: 2.1.0, 2.0.1 Reporter: Franklyn Dsouza Sometimes we try to filter out the argument to a udf using {code}when(clause, udf).otherwise(default){code} but we've noticed that sometimes the udf is being run on data that shouldn't have matched the clause. heres some code to reproduce the issue. {code} from pyspark.sql import functions as F from pyspark.sql import types df = sc.sql.createDataFrame([{'r': None}], schema=types.StructType([types.StructField('r', types.StringType())])) simple_udf = F.udf(lambda ref: ref.strip("/"), types.StringType()) df.withColumn('test', F.when(F.col("r").isNotNull(), simple_udf(F.col("r"))) .otherwise(F.lit(None)) ).collect() {code} This causes an exception because the udf is running on null data. i get AttributeError: 'NoneType' object has no attribute 'strip'. so it looks like the udf is being evaluated before the clause in the when is evaulated. Oddly enough when i change {code}F.col("r").isNotNull(){code} to {code}df["r"] != None{code} then it works. might be related to https://issues.apache.org/jira/browse/SPARK-13773 and https://issues.apache.org/jira/browse/SPARK-15282 -- This message was sent by Atlassian JIRA (v6.3.15#6346) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org For additional commands, e-mail: issues-help@spark.apache.org