title: Spark - How to take logarithm of every value minus smallest element in a column
body: <p>I want to take logarithm of every value subtracted by the smallest element in a column. For example, if a have a column like:</p>
  
  <blockquote>
    <p>score: 1000, 500, 1200, 300</p>
  </blockquote>
  
  <p>Then I want:</p>
  
  <blockquote>
    <p>logged_score: log(700), log(200), log(900), log(0)</p>
  </blockquote>
  
  <p>I tried with this in Spark data frame:</p>
  
  <pre><code>.select(log($"score" - min($"score")).alias("logged_score"))
  </code></pre>
  
  <p>But I got this error:</p>
  
  <blockquote>
    <p>Exception in thread "main" org.apache.spark.sql.AnalysisException:
    grouping expressions sequence is empty, and '<code>score</code>' is not an
    aggregate function. Wrap '(LOG((<code>score</code> - min(<code>score</code>))) AS
    <code>logged_score</code>)' in windowing function(s) or wrap '<code>score</code>' in
    first() (or first_value) if you don't care which value you get.;;</p>
  </blockquote>
  
  <p>The easiest way to overcome this is by getting the <code>min($"score")</code> by collecting it before taking the log value. However, I am trying to avoid doing collect here if there is any better solution.</p>