title: How to reuse expression in withColumn
body: <p>I want to filter long and lat coordinates by distance. I have the following expression.</p>
  <pre><code>.withColumn(&quot;a&quot;,
          // Haversine distance
          pow(sin(toRadians($&quot;b_dropoff_latitude&quot; - $&quot;a_pickup_latitude&quot;) / 2), 2) +
            cos(toRadians($&quot;a_pickup_latitude&quot;)) * cos(toRadians($&quot;b_dropoff_latitude&quot;)) *
              pow(sin(toRadians($&quot;b_dropoff_latitude&quot; - $&quot;a_pickup_latitude&quot;) / 2), 2))
        .withColumn(&quot;diff_b_dropoff_a_pickup&quot;, atan2(sqrt($&quot;a&quot;), sqrt(-$&quot;a&quot; + 1)) * 2 * 6371)
        .drop(&quot;a&quot;)
        .filter($&quot;diff_b_pickup_a_dropoff&quot; &lt; lit(max_dist))
  </code></pre>
  <p>Now, I create a column, to further use that column for the next <code>withColumn</code> expression just to drop the first one and filter the second one. In other words, I touch things 4 times and I'm sure I could do this more simply. How can I rewrite this? The main issue I am having right now is that I can't (well I could, but then I compute <code>&quot;a&quot;</code> twice) compute the second <code>withColumn</code> as I need the first one twice..</p>
  <p>Is it possible to reuse / or declare a variable such that I can use the second <code>withColumn</code> as my filter condition?</p>
  <p>Thanks!</p>