title: Scala Spark - empty map on DataFrame column for map(String, Int)
body: <p>I am joining two DataFrames, where there are columns of a type <code>Map[String, Int]</code></p>
  
  <p>I want the merged DF to have an empty map <code>[]</code> and not <code>null</code> on the <code>Map</code> type columns.</p>
  
  <pre><code>val df = dfmerged.
    .select("id"),
            coalesce(col("map_1"), lit(null).cast(MapType(StringType, IntType))).alias("map_1"),
            coalesce(col("map_2"), lit(Map.empty[String, Int])).alias("map_2")
  </code></pre>
  
  <p>for a <code>map_1</code> column, a <code>null</code> will be inserted, but I'd like to have an <strong>empty map</strong>
  map_2 is giving me an error:</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: Unsupported literal type class
    scala.collection.immutable.Map$EmptyMap$ Map()</p>
  </blockquote>
  
  <p>I've also tried with an <code>udf</code> function like:</p>
  
  <pre><code>case class myStructMap(x:Map[String, Int])
  val emptyMap = udf(() =&gt; myStructMap(Map.empty[String, Int]))
  </code></pre>
  
  <p>also did not work.</p>
  
  <p>when I try something like:</p>
  
  <p><code>.select( coalesce(col("myMapCol"), lit(map())).alias("brand_viewed_count")...</code></p>
  
  <p>or</p>
  
  <p><code>.select(coalesce(col("myMapCol"), lit(map().cast(MapType(LongType, LongType)))).alias("brand_viewed_count")...</code></p>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>cannot resolve 'map()' due to data type mismatch: cannot cast
    MapType(NullType,NullType,false) to MapType(LongType,IntType,true);</p>
  </blockquote>