<?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 Re: Is it possible to do an incremental import using Sqoop free form query? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137460#M23402</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/848/informsuresh.html" nodeid="848"&gt;@Suresh Babu Shanmugam&lt;/A&gt; I find using free form query to be more effective, because you can control exact interval/range for which you want to bring data.  &lt;/P&gt;</description>
    <pubDate>Sun, 10 Apr 2016 10:05:08 GMT</pubDate>
    <dc:creator>shishir_saxena4</dc:creator>
    <dc:date>2016-04-10T10:05:08Z</dc:date>
    <item>
      <title>Is it possible to do an incremental import using Sqoop free form query?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137456#M23398</link>
      <description>&lt;P&gt;Please point me to documentation for the same. More helpful if I get examples as well&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 19:11:26 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137456#M23398</guid>
      <dc:creator>informsuresh</dc:creator>
      <dc:date>2016-03-21T19:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to do an incremental import using Sqoop free form query?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137457#M23399</link>
      <description>&lt;P&gt;
 &lt;A href="https://community.hortonworks.com/questions/23896/is-it-possible-to-do-an-incremental-import-using-s-1.html#" rel="nofollow noopener noreferrer" target="_blank"&gt;@Suresh Babu Shanmugam&lt;/A&gt;&lt;/P&gt;&lt;P&gt;
 An Incremental Import in Sqoop is easily replicated in free form query&lt;/P&gt;&lt;P&gt;
 For example let’s assume you have the following table and the last import was on “2013-01-25” (column: createdOn) which corresponds to the “id” 3 (column:id):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2925-screen-shot-2016-03-21-at-52308-pm.png" style="width: 938px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/21966iFD8A41FEE8919CE7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2925-screen-shot-2016-03-21-at-52308-pm.png" alt="2925-screen-shot-2016-03-21-at-52308-pm.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;You can import the changes/increment since that time using any of the following two “Incremental Update Import” commands&lt;/STRONG&gt; (the first by id and the second by last modification date):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2926-screen-shot-2016-03-21-at-52800-pm.png" style="width: 1352px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/21967iF63B71DAD814E767/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2926-screen-shot-2016-03-21-at-52800-pm.png" alt="2926-screen-shot-2016-03-21-at-52800-pm.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The equivalent “Free Form Query Import” commands would be:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2927-screen-shot-2016-03-21-at-52958-pm.png" style="width: 1354px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/21968iCADB637F2EEB0D8F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2927-screen-shot-2016-03-21-at-52958-pm.png" alt="2927-screen-shot-2016-03-21-at-52958-pm.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So, if you require flexibility with your incremental import then expand/modify on the free form query above.  Just keep in mind that the flag ’--m 1’ signifies that only 1 mapper will be used and jobs will run in serial form.  This can be changed as needed.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;
&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;For information on Incremental Imports see:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://sqoop.apache.org/docs/1.4.2/SqoopUserGuide.html#_incremental_imports" rel="nofollow noopener noreferrer" target="_blank"&gt;https://sqoop.apache.org/docs/1.4.2/SqoopUserGuide.html#_incremental_imports&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;For information on Free Form Query see:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://sqoop.apache.org/docs/1.4.2/SqoopUserGuide.html#_free_form_query_imports" rel="nofollow noopener noreferrer" target="_blank"&gt;https://sqoop.apache.org/docs/1.4.2/SqoopUserGuide.html#_free_form_query_imports&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;For advanced examples of Free Form Query Imports I strongly recommend looking at:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.safaribooksonline.com/library/view/apache-sqoop-cookbook/9781449364618/ch04.html" rel="nofollow noopener noreferrer" target="_blank"&gt;https://www.safaribooksonline.com/library/view/apache-sqoop-cookbook/9781449364618/ch04.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 08:44:09 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137457#M23399</guid>
      <dc:creator>egarelnabi</dc:creator>
      <dc:date>2019-08-19T08:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to do an incremental import using Sqoop free form query?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137458#M23400</link>
      <description>&lt;P&gt;Hi &lt;A href="https://community.hortonworks.com/users/445/egarelnabi.html"&gt;Eyad Garelnabi&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;I apologize for the delay. Your solution works. Thank you.&lt;/P&gt;&lt;P&gt;Actually we are trying Join queries. Till now we are not successful with incremental import.&lt;/P&gt;&lt;P&gt;I will definitely post the solution once we crack join queries incremental import.&lt;/P&gt;&lt;P&gt;Thanks once again,&lt;/P&gt;&lt;P&gt;Suresh&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 11:41:59 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137458#M23400</guid>
      <dc:creator>informsuresh</dc:creator>
      <dc:date>2016-04-01T11:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to do an incremental import using Sqoop free form query?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137459#M23401</link>
      <description>&lt;P&gt;Great!  Looking forward to seeing your final solution &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 12:21:11 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137459#M23401</guid>
      <dc:creator>egarelnabi</dc:creator>
      <dc:date>2016-04-01T12:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to do an incremental import using Sqoop free form query?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137460#M23402</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/848/informsuresh.html" nodeid="848"&gt;@Suresh Babu Shanmugam&lt;/A&gt; I find using free form query to be more effective, because you can control exact interval/range for which you want to bring data.  &lt;/P&gt;</description>
      <pubDate>Sun, 10 Apr 2016 10:05:08 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137460#M23402</guid>
      <dc:creator>shishir_saxena4</dc:creator>
      <dc:date>2016-04-10T10:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to do an incremental import using Sqoop free form query?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137461#M23403</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/445/egarelnabi.html" nodeid="445"&gt;@Eyad Garelnabi&lt;/A&gt;    Found a solution for the join queries.&lt;/P&gt;&lt;P&gt;I am using MySQL DB as source. I tried incremental with Sakila DB which comes with the MySQL installatoin. &lt;/P&gt;&lt;P&gt;I thought I will share my experience that why lengthy response. I apologize for the lengthy answer. &lt;/P&gt;&lt;P&gt;My first sqoop job was:&lt;/P&gt;&lt;PRE&gt;sqoop job --create myssb1 -- import --connect jdbc:mysql://&amp;lt;hostname&amp;gt;:&amp;lt;port&amp;gt;/sakila --username admin --password admin --driver=com.mysql.jdbc.Driver --query "&lt;STRONG&gt;select * from sakila.address a inner join sakila.city c on a.city_id=c.city_id WHERE $CONDITIONS&lt;/STRONG&gt;" --incremental lastmodified --check-column &lt;STRONG&gt;last_update&lt;/STRONG&gt; --last-value 1900-01-01 --target-dir /user/cloudera/ssb7 --hive-import --hive-table test.sakila -m 1 --hive-drop-import-delims --map-column-java address=String&lt;/PRE&gt;&lt;P&gt;It was a straight forward join query. &lt;/P&gt;&lt;PRE&gt;select * from sakila.address a inner join sakila.city c on a.city_id=c.city_id WHERE $CONDITIONS&lt;/PRE&gt;&lt;P&gt;But it gave exception: Imported Failed: Duplicate Column identifier specified: '&lt;STRONG&gt;city_id&lt;/STRONG&gt;'&lt;/P&gt;&lt;P&gt;city_id is available in both city as well as address tables.&lt;/P&gt;&lt;P&gt;I modified the job to:&lt;/P&gt;&lt;PRE&gt;sqoop job --create myssb1 -- import --connect jdbc:mysql://&amp;lt;hostname&amp;gt;:&amp;lt;port&amp;gt;/sakila --username admin --password admin --driver=com.mysql.jdbc.Driver --query "select a.address_id as address_id, a.address as address, a.district as district, a.city_id as city_id, a.postal_code as postal_code, a.last_update as alast_update, c.city_id as cityid, c.city as city, c.country_id as country_id, c.last_update as clast_update from sakila.address a inner join sakila.city c on a.city_id=c.city_id WHERE $CONDITIONS" --incremental lastmodified --check-column alast_update --last-value 1900-01-01 --target-dir /user/cloudera/ssb7 --hive-import --hive-table test.sakila -m 1 --hive-drop-import-delims --map-column-java address=String&lt;/PRE&gt;&lt;P&gt;I gave unique alias to individual column in select clause as mentioned in sqoop cook book Chapter 4. "use SQL projection to rename columns in the query so that each column in the output result set has a unique name."  The SQL is&lt;/P&gt;&lt;PRE&gt;select a.address_id as address_id, a.address as address, a.district as district, a.city_id as city_id, a.postal_code as postal_code, a.last_update as alast_update, c.city_id as cityid, c.city as city, c.country_id as country_id, c.last_update as clast_update from sakila.address a inner join sakila.city c on a.city_id=c.city_id WHERE $CONDITIONS&lt;/PRE&gt;&lt;P&gt;I am referring alias name for check-column (alast_update) attribute as well in sqoop job.&lt;/P&gt;&lt;P&gt;But it gave exception again: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column '&lt;STRONG&gt;alast_update&lt;/STRONG&gt;' in 'where clause'&lt;/P&gt;&lt;P&gt;I was going through lot of online material to resolve this issue. Then I saw this answer in stackoverflow (&lt;A target="_blank" href="http://stackoverflow.com/questions/13248669/sqoop-free-form-query-split-by-alias"&gt;Click here&lt;/A&gt;). Though the answer talks about MS SQL, the solution provided there worked for MySQL and PostreSQL as well.&lt;/P&gt;&lt;P&gt;my new job is:&lt;/P&gt;&lt;PRE&gt;sqoop job --create myssb1 -- import --connect jdbc:mysql://&amp;lt;hostname&amp;gt;:&amp;lt;port&amp;gt;/sakila --username admin --password admin --driver=com.mysql.jdbc.Driver --query "SELECT address_id, address, district, city_id, postal_code, alast_update, cityid, city, country_id, clast_update FROM(SELECT a.address_id as address_id, a.address as address, a.district as district, a.city_id as city_id, a.postal_code as postal_code, a.last_update as alast_update, c.city_id as cityid, c.city as city, c.country_id as country_id, c.last_update as clast_update FROM sakila.address a INNER JOIN sakila.city c ON a.city_id=c.city_id) as sub WHERE $CONDITIONS" --incremental lastmodified --check-column alast_update --last-value 1900-01-01 --target-dir /user/cloudera/ssb7 --hive-import --hive-table test.sakila -m 1 --hive-drop-import-delims --map-column-java address=String&lt;/PRE&gt;&lt;P&gt;The SQL is&lt;/P&gt;&lt;PRE&gt;SELECT address_id, address, district, city_id, postal_code, alast_update, cityid, city, country_id, clast_update 
FROM (
               SELECT a.address_id AS address_id, a.address AS address, a.district AS district, a.city_id AS city_id, a.postal_code AS postal_code, a.last_update AS alast_update, c.city_id AS cityid, c.city AS city, c.country_id AS country_id, c.last_update AS clast_update 
               FROM sakila.address a 
               INNER JOIN sakila.city c 
               ON a.city_id=c.city_id) AS sub 
WHERE $CONDITIONS
&lt;/PRE&gt;&lt;P&gt;The solution worked for us. &lt;A rel="user" href="https://community.cloudera.com/users/445/egarelnabi.html" nodeid="445"&gt;@Eyad Garelnabi&lt;/A&gt; Please let me know your thoughts on this.&lt;/P&gt;&lt;P&gt;Thanks again to &lt;A rel="user" href="https://community.cloudera.com/users/445/egarelnabi.html" nodeid="445"&gt;@Eyad Garelnabi&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Suresh Babu&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 14:21:30 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137461#M23403</guid>
      <dc:creator>informsuresh</dc:creator>
      <dc:date>2016-04-11T14:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to do an incremental import using Sqoop free form query?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137462#M23404</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/848/informsuresh.html" nodeid="848"&gt;@Suresh Babu Shanmugam&lt;/A&gt; I had the same problem and your solution worked for me. Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 14:25:21 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-it-possible-to-do-an-incremental-import-using-Sqoop-free/m-p/137462#M23404</guid>
      <dc:creator>saswat123</dc:creator>
      <dc:date>2017-07-06T14:25:21Z</dc:date>
    </item>
  </channel>
</rss>

