<?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: Including WITH UR in Sqoop Free-form query Import (SOLVED) in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Including-WITH-UR-in-Sqoop-Free-form-query-Import-SOLVED/m-p/170026#M41826</link>
    <description>&lt;A rel="user" href="https://community.cloudera.com/users/936/landontrobinson.html" nodeid="936"&gt;@Landon Robinson&lt;/A&gt;&lt;P&gt;Is your query wrapped in quotes? If not, can you try that (single quotes is fine)? If you wrap it in double quotes then you will need to use "\$CONDITIONS" instead of just "$CONDITIONS" so that your shell doesn't use it as a shell variable.&lt;/P&gt;</description>
    <pubDate>Mon, 26 Sep 2016 23:19:18 GMT</pubDate>
    <dc:creator>mqureshi</dc:creator>
    <dc:date>2016-09-26T23:19:18Z</dc:date>
    <item>
      <title>Including WITH UR in Sqoop Free-form query Import (SOLVED)</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Including-WITH-UR-in-Sqoop-Free-form-query-Import-SOLVED/m-p/170025#M41825</link>
      <description>&lt;P&gt;&lt;STRONG&gt;EDIT (SOLUTION):&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem&lt;/STRONG&gt;: Can't include the "with ur" statement DB2 requires to keep a table from locking. i.e. a "dirty read."&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Solution&lt;/STRONG&gt;: Make use of the &lt;EM&gt;--boundary-query&lt;/EM&gt; option in Sqoop.&lt;/P&gt;&lt;P&gt;I modified my Sqoop import statement to leverage the &lt;EM&gt;--boundary-query&lt;/EM&gt; option in Sqoop, which allows me to build the boundary query for determining the splits for the mappers. Typically, since I'm using the &lt;EM&gt;--split-by&lt;/EM&gt; and &lt;EM&gt;--query&lt;/EM&gt; options, this is generated automatically. By adding the new option at the end of my Sqoop statement, and adjusting both it and my standard query to include the desired "with ur", I can achieve a Sqoop job whose multiple mappers fire off non-locking select queries, with ranges of data, with the "with ur" statement.&lt;/P&gt;&lt;P&gt;Working code:&lt;/P&gt;&lt;PRE&gt;sqoop import -Ddb2.jcc.charsetDecoderEncoder=3 -Dmapred.job.queue.name=default 
--connect jdbc:db2://mybox.mycompany.com:1234/mydb2db 
--username myuser 
--password mypassword 
--query "select * from ( SELECT column1, column2, column3, current timestamp as load_time, CHAR(current date, iso) as load_dt FROM my_database.my_table where column1 &amp;lt;= 1000 )a WHERE $CONDITIONS with UR" 
--hcatalog-database myHiveDB 
--hcatalog-table myHiveTable 
--split-by column1 
--fields-terminated-by \001 
-m 5 
--relaxed-isolation 
--fetch-size=100000 
--boundary-query "SELECT MIN(column1), MAX(column1) FROM my_database.my_table where column1 &amp;lt;= 1000 with UR"&lt;/PRE&gt;&lt;P&gt;* This Sqoop command is being dynamically generated from a bash script. If you experience problems adopting the above code, try the following:&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;- put the whole sqoop command on one line&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;- use \$CONDITIONS not $CONDITIONS (if this is coming from a text file, not hardcoded, you don't need the escape. If you're typing it directly in the sqoop command, you do&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;- ensure the information following both --query and --boundary-query are in double quotes as above&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;---&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ORIGINAL QUESTION:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I have this Sqoop command that nearly works... up until I get a syntax exception from DB2:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sqoop Command:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;sqoop import -Ddb2.jcc.charsetDecoderEncoder=3 -Dmapred.job.queue.name=default --connect jdbc:db2://mybox.mycompany.com:1234/mydb2db --username myuser --password mypassword --query SELECT column1, column2, column3, current timestamp as load_time, CHAR(current date, iso) as load_dt FROM my_database.my_table where column1 &amp;lt;= 1000 AND $CONDITIONS with UR --hcatalog-database myHiveDB --hcatalog-table myHiveTable --split-by column1 --fields-terminated-by \001 -m 5 --relaxed-isolation --fetch-size=100000&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;It works great up to this point. Compares the target data with the hcat/hive table, all checks out. Then it tries to do the splits with the bounding values, and flips.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Error (and log):&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;16/09/26 10:32:12 INFO db.DataDrivenDBInputFormat: BoundingValsQuery: SELECT MIN(column1), MAX(column1) FROM (SELECT
column1,
column2,
column3,
current timestamp as load_time,
CHAR(current date, iso) as load_dt
FROM my_database.my_table
where column1 &amp;lt;= 1000 AND  (1 = 1)  with UR) AS t1
&lt;/PRE&gt;
&lt;PRE&gt;Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-199, SQLSTATE=42601, SQLERRMC=WITH;AND OR HAVING GROUP INTERSECT ORDER ) FETCH EXCEPT MINUS UNION, DRIVER=4.16.53&lt;/PRE&gt;&lt;P&gt;I believe it has to do with DB2 needing the "with UR" phrase last, but Sqoop always tacks on the AS t1, causing it to break. Any suggestions to fixing this? We need to do non-locking reads on a DB2 table.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 21:51:13 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Including-WITH-UR-in-Sqoop-Free-form-query-Import-SOLVED/m-p/170025#M41825</guid>
      <dc:creator>landon_t_robins</dc:creator>
      <dc:date>2016-09-26T21:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Including WITH UR in Sqoop Free-form query Import (SOLVED)</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Including-WITH-UR-in-Sqoop-Free-form-query-Import-SOLVED/m-p/170026#M41826</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/936/landontrobinson.html" nodeid="936"&gt;@Landon Robinson&lt;/A&gt;&lt;P&gt;Is your query wrapped in quotes? If not, can you try that (single quotes is fine)? If you wrap it in double quotes then you will need to use "\$CONDITIONS" instead of just "$CONDITIONS" so that your shell doesn't use it as a shell variable.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 23:19:18 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Including-WITH-UR-in-Sqoop-Free-form-query-Import-SOLVED/m-p/170026#M41826</guid>
      <dc:creator>mqureshi</dc:creator>
      <dc:date>2016-09-26T23:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: Including WITH UR in Sqoop Free-form query Import (SOLVED)</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Including-WITH-UR-in-Sqoop-Free-form-query-Import-SOLVED/m-p/170027#M41827</link>
      <description>&lt;P&gt;I've attempted that, but it still feeds out the same error as above. Am trying now to use JDBC level connection parameters as below, but it doesn't seem to be passing it to the splitted sub queries. Initial connection is with UR, but subsequent subqueries are not.&lt;/P&gt;&lt;PRE&gt;--connection-param-file /just/some/path/sqoop.properties
&lt;/PRE&gt;&lt;PRE&gt;jdbc.transaction.isolation=TRANSACTION_READ_UNCOMMITTED&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Sep 2016 00:09:23 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Including-WITH-UR-in-Sqoop-Free-form-query-Import-SOLVED/m-p/170027#M41827</guid>
      <dc:creator>landon_t_robins</dc:creator>
      <dc:date>2016-09-27T00:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Including WITH UR in Sqoop Free-form query Import (SOLVED)</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Including-WITH-UR-in-Sqoop-Free-form-query-Import-SOLVED/m-p/170028#M41828</link>
      <description>&lt;P&gt;&lt;STRONG&gt;I've resolved the issue &lt;/STRONG&gt;by using the --&lt;EM&gt;boundary-query&lt;/EM&gt; option in Sqoop, in tandem with my use of &lt;EM&gt;--query &lt;/EM&gt;and &lt;EM&gt;--split-by&lt;/EM&gt;. Will post answer shortly.&lt;/P&gt;&lt;P&gt;Edit: Posted answer at top of my question. Here's the code again for convenience:&lt;/P&gt;&lt;PRE&gt;sqoop import -Ddb2.jcc.charsetDecoderEncoder=3 -Dmapred.job.queue.name=default --connect jdbc:db2://mybox.mycompany.com:1234/mydb2db --username myuser --password mypassword --query "select * from ( SELECT column1, column2, column3, current timestamp as load_time, CHAR(current date, iso) as load_dt FROM my_database.my_table where column1 &amp;lt;= 1000 )a WHERE $CONDITIONS with UR" --hcatalog-database myHiveDB --hcatalog-table myHiveTable --split-by column1 --fields-terminated-by \001 -m 5 --relaxed-isolation --fetch-size=100000 --boundary-query "SELECT MIN(column1), MAX(column1) FROM my_database.my_table where column1 &amp;lt;= 1000 with UR"&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Sep 2016 01:28:35 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Including-WITH-UR-in-Sqoop-Free-form-query-Import-SOLVED/m-p/170028#M41828</guid>
      <dc:creator>landon_t_robins</dc:creator>
      <dc:date>2016-09-27T01:28:35Z</dc:date>
    </item>
  </channel>
</rss>

