Spark, add new Column with the same value in Scala
<p>I have some problem with the <code>withColumn</code> function in Spark-Scala environment.
I would like to add a new Column in my DataFrame like that:</p>

<pre><code>+---+----+---+
|  A|   B|  C|
+---+----+---+
|  4|blah|  2|
|  2|    |  3|
| 56| foo|  3|
|100|null|  5|
+---+----+---+
</code></pre>

<p>became:</p>

<pre><code>+---+----+---+-----+
|  A|   B|  C|  D  |
+---+----+---+-----+
|  4|blah|  2|  750|
|  2|    |  3|  750|
| 56| foo|  3|  750|
|100|null|  5|  750|
+---+----+---+-----+
</code></pre>

<p>the column D in one value repeated N-time for each row in my DataFrame.</p>

<p>The code are this:</p>

<pre><code>var totVehicles : Double = df_totVehicles(0).getDouble(0); //return 750
</code></pre>

<p>The variable totVehicles returns the correct value, it's works!</p>

<p>The second DataFrame has to calculate 2 fields (id_zipcode, n_vehicles), and add the third column (with the same value -750):</p>

<pre><code>var df_nVehicles =
df_carPark.filter(
      substring($"id_time",1,4) &lt; 2013
    ).groupBy(
      $"id_zipcode"
    ).agg(
      sum($"n_vehicles") as 'n_vehicles
    ).select(
      $"id_zipcode" as 'id_zipcode,
      'n_vehicles
    ).orderBy(
      'id_zipcode,
      'n_vehicles
    );
</code></pre>

<p>Finally, I add the new column with <code>withColumn</code> function:</p>

<pre><code>var df_nVehicles2 = df_nVehicles.withColumn(totVehicles, df_nVehicles("n_vehicles") + df_nVehicles("id_zipcode"))
</code></pre>

<p>But Spark returns me this error:</p>

<pre><code> error: value withColumn is not a member of Unit
         var df_nVehicles2 = df_nVehicles.withColumn(totVehicles, df_nVehicles("n_vehicles") + df_nVehicles("id_zipcode"))
</code></pre>

<p>Can you help me?
Thank you very much!</p>