title: Spark is not able to resolve the columns correctly when joins data frames
body: <p>I'm using pyspark ( python 3.8) over spark3.0 on Databricks. When running this DataFrame join:</p>
  <pre class="lang-py prettyprint-override"><code>next_df = (
      days_currencies_matrix.alias(&quot;a&quot;)
      .join(
          data_to_merge.alias(&quot;b&quot;),
          [
              days_currencies_matrix.dt == data_to_merge.RATE_DATE,
              days_currencies_matrix.CURRENCY_CODE == data_to_merge.CURRENCY_CODE,
          ],
          &quot;LEFT&quot;,
      )
      .select(
          days_currencies_matrix.CURRENCY_CODE,
          days_currencies_matrix.dt.alias(&quot;RATE_DATE&quot;),
          data_to_merge.AVGYTD,
          data_to_merge.ENDMTH,
          data_to_merge.AVGMTH,
          data_to_merge.AVGWEEK,
          data_to_merge.AVGMTD,
      )
  )
  </code></pre>
  <p>And I’m getting this error:</p>
  <blockquote>
  <p>Column AVGYTD#67187, AVGWEEK#67190, ENDMTH#67188, AVGMTH#67189, AVGMTD#67191 are ambiguous. It's probably because you joined several Datasets together, and some of these Datasets are the same. This column points to one of the Datasets but Spark is unable to figure out which one. Please alias the Datasets with different names via <code>Dataset.as</code> before joining them, and specify the column using qualified name, e.g. <code>df.as(&quot;a&quot;).join(df.as(&quot;b&quot;), $&quot;a.id&quot; &gt; $&quot;b.id&quot;)</code>. You can also set spark.sql.analyzer.failAmbiguousSelfJoin to false to disable this check.</p>
  </blockquote>
  <p>Which is telling me that the above columns belong to more than one dataset. Why is that happening? The code is telling to spark exactly the source dataframe;
  also, the days_currencies_matrix has only 2 columns: dt and CURRENCY_CODE.</p>
  <p>The source data frames are defined as follow:</p>
  <pre><code>currencies_in_merging_data = data_to_merge.select('CURRENCY_CODE').distinct()
  
  days_currencies_matrix = dt_days.crossJoin(currencies_in_merging_data)
  </code></pre>
  <p>Is it because days_currencies_matrix DataFrame actually is built over the data_to_merge? Is that something related to Lazy evaluations or it is a bug?</p>
  <p>BTW, this version works with no issues:</p>
  <pre class="lang-py prettyprint-override"><code>next_df = (
      days_currencies_matrix.alias(&quot;a&quot;)
      .join(
          data_to_merge.alias(&quot;b&quot;),
          [
              days_currencies_matrix.dt == data_to_merge.RATE_DATE,
              days_currencies_matrix.CURRENCY_CODE == data_to_merge.CURRENCY_CODE,
          ],
          &quot;LEFT&quot;,
      )
      .select(
          col(&quot;a.dt&quot;).alias(&quot;RATE_DATE&quot;),
          col(&quot;a.CURRENCY_CODE&quot;),
          col(&quot;b.AVGYTD&quot;),
          col(&quot;b.ENDMTH&quot;),
          col(&quot;b.AVGMTH&quot;),
          col(&quot;b.AVGWEEK&quot;),
          col(&quot;b.AVGMTD&quot;),
      )
  )
  </code></pre>