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 5236E200B5E for ; Wed, 10 Aug 2016 09:19:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 50E60160AB1; Wed, 10 Aug 2016 07:19:22 +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 96860160A90 for ; Wed, 10 Aug 2016 09:19:21 +0200 (CEST) Received: (qmail 12456 invoked by uid 500); 10 Aug 2016 07:19: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 12440 invoked by uid 99); 10 Aug 2016 07:19:20 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Aug 2016 07:19:20 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id ADE072C0003 for ; Wed, 10 Aug 2016 07:19:20 +0000 (UTC) Date: Wed, 10 Aug 2016 07:19:20 +0000 (UTC) From: "Nick Pentreath (JIRA)" To: issues@spark.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (SPARK-16921) RDD/DataFrame persist() and cache() should return Python context managers MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 10 Aug 2016 07:19:22 -0000 [ https://issues.apache.org/jira/browse/SPARK-16921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15414840#comment-15414840 ] Nick Pentreath commented on SPARK-16921: ---------------------------------------- By the way for BC vars, I wonder if {{__exit__}} should call {{unpersist}} or {{destroy}}? Probably {{destroy}} as it's more along the lines of {{close}} type of semantics > RDD/DataFrame persist() and cache() should return Python context managers > ------------------------------------------------------------------------- > > Key: SPARK-16921 > URL: https://issues.apache.org/jira/browse/SPARK-16921 > Project: Spark > Issue Type: New Feature > Components: PySpark, Spark Core, SQL > Reporter: Nicholas Chammas > Priority: Minor > > [Context managers|https://docs.python.org/3/reference/datamodel.html#context-managers] are a natural way to capture closely related setup and teardown code in Python. > For example, they are commonly used when doing file I/O: > {code} > with open('/path/to/file') as f: > contents = f.read() > ... > {code} > Once the program exits the with block, {{f}} is automatically closed. > I think it makes sense to apply this pattern to persisting and unpersisting DataFrames and RDDs. There are many cases when you want to persist a DataFrame for a specific set of operations and then unpersist it immediately afterwards. > For example, take model training. Today, you might do something like this: > {code} > labeled_data.persist() > model = pipeline.fit(labeled_data) > labeled_data.unpersist() > {code} > If {{persist()}} returned a context manager, you could rewrite this as follows: > {code} > with labeled_data.persist(): > model = pipeline.fit(labeled_data) > {code} > Upon exiting the {{with}} block, {{labeled_data}} would automatically be unpersisted. > This can be done in a backwards-compatible way since {{persist()}} would still return the parent DataFrame or RDD as it does today, but add two methods to the object: {{\_\_enter\_\_()}} and {{\_\_exit\_\_()}} -- 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