<?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>question Unable to perform hive exchange partition due to failure of: Partition already exists in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Unable-to-perform-hive-exchange-partition-due-to-failure-of/m-p/92108#M3959</link>
    <description>&lt;P&gt;I am trying to exchange a partition from staging db after merging the incremental data with the existing one as below:&lt;/P&gt;&lt;P&gt;1. Created staging table with partition:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;CREATE TABLE stg.customers_testcontrol_staging(customer_id bigint,customer_name string, customer_number string,status string,attribute_category string,attribute1 string, attribute2 string, attribute3 string, attribute4 string, attribute5 string) PARTITIONED BY (source_name string) ROW FORMAT SERDE'org.apache.hadoop.hive.ql.io.orc.OrcSerde' STORED AS INPUTFORMAT 'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat' Location('/apps/hive/warehouse/stg.db/customers_testcontrol_staging'&lt;/PRE&gt;&lt;P&gt;2. Inserted data into above table after merging with the base table data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;INSERT OVERWRITE TABLE finstg.customers_testcontrol_staging PARTITION (source_name) SELECT t1.* FROM (SELECT * FROM base.customers where source_name='ORACLE' UNION ALL SELECT * FROM external.customers_incremental_data) t1 JOIN (SELECT customer_id,source_name, max(updated_date) max_modified FROM (SELECT * FROM base.customers where source_name='ORACLE' UNION ALL SELECT * FROM external.customers_incremental_data) t2 GROUP BY customer_id,source_name) s ON t1.customer_id=s.customer_id AND t1.source_name=s.source_name;&lt;/PRE&gt;&lt;P&gt;Primary Keys of the table I am performing the join are: customer_id &amp;amp; source_name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Exchange partition step:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ALTER TABLE base.customers EXCHANGE PARTITION (source_name = 'ORACLE') WITH TABLE stg.customers_testcontrol_staging;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the exchange partition step fails with the exception:&lt;/P&gt;&lt;PRE&gt;Error: Error while compiling statement: FAILED: SemanticException [Error 10118]: Partition already exists [customers(source_name=ORACLE)]&lt;/PRE&gt;&lt;P&gt;I took the syntax from &lt;A href="https://cwiki.apache.org/confluence/display/Hive/Exchange+Partition" target="_blank" rel="nofollow noopener noreferrer"&gt;Hive Confluence page&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anything I missed to include in the EXCHANGE partition statement ? Could anyone let me what is the mistake I am doing here &amp;amp; how can I fix it ?&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2022 14:28:48 GMT</pubDate>
    <dc:creator>Sidhartha</dc:creator>
    <dc:date>2022-09-16T14:28:48Z</dc:date>
    <item>
      <title>Unable to perform hive exchange partition due to failure of: Partition already exists</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Unable-to-perform-hive-exchange-partition-due-to-failure-of/m-p/92108#M3959</link>
      <description>&lt;P&gt;I am trying to exchange a partition from staging db after merging the incremental data with the existing one as below:&lt;/P&gt;&lt;P&gt;1. Created staging table with partition:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;CREATE TABLE stg.customers_testcontrol_staging(customer_id bigint,customer_name string, customer_number string,status string,attribute_category string,attribute1 string, attribute2 string, attribute3 string, attribute4 string, attribute5 string) PARTITIONED BY (source_name string) ROW FORMAT SERDE'org.apache.hadoop.hive.ql.io.orc.OrcSerde' STORED AS INPUTFORMAT 'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat' Location('/apps/hive/warehouse/stg.db/customers_testcontrol_staging'&lt;/PRE&gt;&lt;P&gt;2. Inserted data into above table after merging with the base table data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;INSERT OVERWRITE TABLE finstg.customers_testcontrol_staging PARTITION (source_name) SELECT t1.* FROM (SELECT * FROM base.customers where source_name='ORACLE' UNION ALL SELECT * FROM external.customers_incremental_data) t1 JOIN (SELECT customer_id,source_name, max(updated_date) max_modified FROM (SELECT * FROM base.customers where source_name='ORACLE' UNION ALL SELECT * FROM external.customers_incremental_data) t2 GROUP BY customer_id,source_name) s ON t1.customer_id=s.customer_id AND t1.source_name=s.source_name;&lt;/PRE&gt;&lt;P&gt;Primary Keys of the table I am performing the join are: customer_id &amp;amp; source_name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Exchange partition step:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ALTER TABLE base.customers EXCHANGE PARTITION (source_name = 'ORACLE') WITH TABLE stg.customers_testcontrol_staging;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the exchange partition step fails with the exception:&lt;/P&gt;&lt;PRE&gt;Error: Error while compiling statement: FAILED: SemanticException [Error 10118]: Partition already exists [customers(source_name=ORACLE)]&lt;/PRE&gt;&lt;P&gt;I took the syntax from &lt;A href="https://cwiki.apache.org/confluence/display/Hive/Exchange+Partition" target="_blank" rel="nofollow noopener noreferrer"&gt;Hive Confluence page&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anything I missed to include in the EXCHANGE partition statement ? Could anyone let me what is the mistake I am doing here &amp;amp; how can I fix it ?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 14:28:48 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Unable-to-perform-hive-exchange-partition-due-to-failure-of/m-p/92108#M3959</guid>
      <dc:creator>Sidhartha</dc:creator>
      <dc:date>2022-09-16T14:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to perform hive exchange partition due to failure of: Partition already exists</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Unable-to-perform-hive-exchange-partition-due-to-failure-of/m-p/92300#M3960</link>
      <description>Hi &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/21395"&gt;@Sidhartha&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;The error means that the destination table base.customers already has the partition source_name=ORACLE, as the error indicated:&lt;BR /&gt;&lt;BR /&gt;Partition already exists [customers(source_name=ORACLE)]&lt;BR /&gt;&lt;BR /&gt;Can you run :&lt;BR /&gt;&lt;BR /&gt;SHOW PARTITIONS base.customers;&lt;BR /&gt;&lt;BR /&gt;to confirm? If yes, try to drop it and then run EXCHANGE PARTITION again.&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;Eric</description>
      <pubDate>Fri, 05 Jul 2019 04:55:01 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Unable-to-perform-hive-exchange-partition-due-to-failure-of/m-p/92300#M3960</guid>
      <dc:creator>EricL</dc:creator>
      <dc:date>2019-07-05T04:55:01Z</dc:date>
    </item>
  </channel>
</rss>

