<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Is there a better method to join two dataframes and not have a duplicated column? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30570#M22185</link>
    <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;noticed similar behavior. Even when specify right_dataframe.col("columnname") in filter condition or drop function it uses leftdatframe.col("columnname") during execution.&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Sep 2019 13:54:13 GMT</pubDate>
    <dc:creator>Harshil</dc:creator>
    <dc:date>2019-09-19T13:54:13Z</dc:date>
    <item>
      <title>Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30559#M22174</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I would like to keep only one of the columns used to join the dataframes. Using select() after the join does not seem straight forward because the real data may have many columns or the column names may not be known. A simple example below&lt;/P&gt;llist = [('bob', '2015-01-13', 4), ('alice', '2015-04-23',10)] ddf = sqlContext.createDataFrame(llist,['name','date','duration']) print ddf.collect() up_ddf = sqlContext.createDataFrame([('alice', 100),('bob', 23)],['name','upload'])
&lt;P&gt;&lt;/P&gt; 
&lt;B&gt;this keeps both 'name' columns when we only want a one!&lt;/B&gt; 
&lt;P&gt;df = ddf.join(up_ddf, ddf.name == up_ddf.name) print ddf.collect() display( ddf.select(ddf.name, (ddf.duration/ddf.upload).alias('duration_per_upload')) )&lt;/P&gt;
&lt;P&gt;Executing display above causes an ambiguous name error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;org.apache.spark.sql.AnalysisException: Reference 'name' is ambiguous, could be: name#8484, name#8487.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The error can be avoided by using up_ddf.name from the right-hand dataframe in the join&lt;/P&gt;
&lt;P&gt;ddf.select(up_ddf.name, ...&lt;/P&gt;
&lt;P&gt;but seems awkward. Is there a better method to join two dataframes and get only one 'name' column?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2015 10:29:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30559#M22174</guid>
      <dc:creator>kruhly</dc:creator>
      <dc:date>2015-05-12T10:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30560#M22175</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;As of Spark 1.4, you should be able to just:&lt;/P&gt;
&lt;P&gt;val new_ddf = ddf.join(up_ddf, "name")&lt;/P&gt;
&lt;P&gt;Similar email thread here&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jun 2015 13:54:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30560#M22175</guid>
      <dc:creator>bplaster</dc:creator>
      <dc:date>2015-06-22T13:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30561#M22176</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Looks like in spark 1.5, we don't have df.join functions. There is a top level join functions.&lt;/P&gt;
&lt;P&gt;How do I remove the join column once (which appears twice in the joined table, and any aggregate on that column fails)?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 09:35:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30561#M22176</guid>
      <dc:creator>krdeepak</dc:creator>
      <dc:date>2015-09-30T09:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30562#M22177</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;This is not efficient especially in case of joining with bunch of columns. It should be removed automatically after join. can't understand why are doing so.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2016 22:05:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30562#M22177</guid>
      <dc:creator>JingtaoYun</dc:creator>
      <dc:date>2016-02-11T22:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30563#M22178</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;OL&gt;&lt;LI&gt;ddf = ddf.join(up_ddf, ddf.name == up_ddf.name).drop(up_ddf.name)&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2016 19:47:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30563#M22178</guid>
      <dc:creator>jsharrett</dc:creator>
      <dc:date>2016-02-25T19:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30564#M22179</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;This is covered in the Databricks Spark FAQ:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://docs.databricks.com/spark/latest/faq/join-two-dataframes-duplicated-column.html" target="test_blank"&gt;http://docs.databricks.com/spark/latest/faq/join-two-dataframes-duplicated-column.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;We'll keep that up to date!&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2016 22:19:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30564#M22179</guid>
      <dc:creator>Bill_Chambers</dc:creator>
      <dc:date>2016-02-26T22:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30565#M22180</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;the drop() only removes the specific data frame instance of the column. So if you have:&lt;/P&gt;
&lt;P&gt;val new_ddf = ddf.join(up_ddf, "name")&lt;/P&gt;
&lt;P&gt;then in new_ddf you have two columns ddf.name and up_ddf.name.&lt;/P&gt;
&lt;P&gt;val new_ddf = ddf.join(up_ddf, "name").drop(up_ddf.col("name") will remove that column and only leave ddf.name in new_ddf.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Mar 2016 03:25:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30565#M22180</guid>
      <dc:creator>jsharrett</dc:creator>
      <dc:date>2016-03-13T03:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30566#M22181</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;How do I drop duplicate during &lt;/P&gt;How do I drop duplicate column after left_outer/left join . What I noticed drop works for inner join but the same is not working for left join , like here in this case I want drop duplicate join column from right .
&lt;P&gt;&lt;/P&gt; 
&lt;P&gt;val column = right(joinColumn)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;val test = left.join(broadcast(right),left(joinColumn) === right(joinColumn),"left_outer)&lt;P&gt;&lt;/P&gt;val newDF = test.drop(column)</description>
      <pubDate>Wed, 10 Aug 2016 22:27:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30566#M22181</guid>
      <dc:creator>bdas77</dc:creator>
      <dc:date>2016-08-10T22:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30567#M22182</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;In python, we can solve it like:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0693f000007OrmxAAC"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2545i57AE7248E054A293/image-size/large?v=v2&amp;amp;px=999" role="button" title="0693f000007OrmxAAC" alt="0693f000007OrmxAAC" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;And in java, we can use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;public Dataset&amp;lt;Row&amp;gt; join(Dataset&amp;lt;?&amp;gt; right,
                scala.collection.Seq&amp;lt;String&amp;gt; usingColumns,
                String joinType)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;more in &lt;A href="http://spark.apache.org/docs/2.1.0/api/java/index.html" target="test_blank"&gt;http://spark.apache.org/docs/2.1.0/api/java/index.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;According to question：&lt;/P&gt;
&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/35988315/convert-java-list-to-scala-seq" target="test_blank"&gt;http://stackoverflow.com/questions/35988315/convert-java-list-to-scala-seq&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;the &lt;B&gt;usingColumns&lt;/B&gt; parameter can be defined as ArrayList.&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 10:15:23 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30567#M22182</guid>
      <dc:creator>Carrod</dc:creator>
      <dc:date>2017-01-19T10:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30568#M22183</link>
      <description>&lt;P&gt;This is an expected behavior. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DataFrame.join&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; method is equivalent to SQL join like this&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT*FROM a JOIN b ON joinExprs&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If you want to ignore duplicate columns just drop them or select columns of interest afterwards. If you want to disambiguate you can use access these using parent &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DataFrames&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;val a:DataFrame=???val b:DataFrame=???val joinExprs:Column=???&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;a.join(b, joinExprs).select(a("id"), b("foo"))// drop equivalent a.alias("a").join(b.alias("b"), joinExprs).drop(b("id")).drop(a("foo"))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or use aliases:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;// As for now aliases don't work with drop
a.alias("a").join(b.alias("b"), joinExprs).select($"a.id", $"b.foo")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 09:55:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30568#M22183</guid>
      <dc:creator>TejuNC</dc:creator>
      <dc:date>2017-01-23T09:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30569#M22184</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I followed the same way what it is in the above article. But did not work for me.&lt;/P&gt;
&lt;P&gt;Both df1 &amp;amp; df2 have the same column set of 1006 count. The result created with 2012 columns.&lt;/P&gt;
&lt;P&gt;scala&amp;gt; df1.join(df2, Seq("file_name","post_evar30") ) &lt;/P&gt;
&lt;P&gt;res24: org.apache.spark.sql.DataFrame = [file_name: string, post_evar30: string ... 2012 more fields]&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 18:33:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30569#M22184</guid>
      <dc:creator>bharathk12</dc:creator>
      <dc:date>2019-02-14T18:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30570#M22185</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;noticed similar behavior. Even when specify right_dataframe.col("columnname") in filter condition or drop function it uses leftdatframe.col("columnname") during execution.&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 13:54:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30570#M22185</guid>
      <dc:creator>Harshil</dc:creator>
      <dc:date>2019-09-19T13:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better method to join two dataframes and not have a duplicated column?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30571#M22186</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;404 -&amp;gt; didnt keep this article upto date. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 17:59:06 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-there-a-better-method-to-join-two-dataframes-and-not-have-a/m-p/30571#M22186</guid>
      <dc:creator>Ericewittry</dc:creator>
      <dc:date>2019-11-20T17:59:06Z</dc:date>
    </item>
  </channel>
</rss>

