title: Incorrect query encoding when executing Hive from file
body: <p>I have a Hive query with CJK characters in a file like below:</p>
  
  <pre><code>SELECT * FROM tbl WHERE name LIKE '日本語%';
  </code></pre>
  
  <p>And the file is encoded in UTF-8:</p>
  
  <pre><code>&gt; file -bi query.hql
  text/plain; charset=utf-8
  </code></pre>
  
  <p>If I execute it with Hive CLI, I can get expected result:</p>
  
  <pre><code>&gt; /path/to/hive -f query.hql
  some results here
  </code></pre>
  
  <p>Now I want to execute this query from Java. So I wrote some code like:</p>
  
  <pre><code>String[] cmd = new String[]{"/bin/bash", "/my/script", "/path/to/query.hql", "/path/to/output.txt"};
  ProcessBuilder pb = new ProcessBuilder(cmd);
  ...
  pb.start();
  ...
  </code></pre>
  
  <p>And <code>/my/script</code> looks like:</p>
  
  <pre><code>HQL_FILE=$1
  OUTPUT_FILE=$2
  /path/to/hive -f "${HQL_FILE}" &gt; "${OUTPUT_FILE}"
  </code></pre>
  
  <p>I ran my Java program but got no output. I checked Hive log file and it looks like an encoding issue.</p>
  
  <p>If I run <code>hive -f query.hql</code> via shell, the CJK text logged correctly in hive log: </p>
  
  <pre><code>&gt; cat /tmp/myuser/hive.log
  2016-02-29 11:27:40,303 INFO  [main]: parse.ParseDriver (ParseDriver.java:parse(185)) - Parsing command: ... name LIKE '日本語%' ...
  </code></pre>
  
  <p>But if I run via above Java program, the log looks strange</p>
  
  <pre><code>&gt; cat /tmp/myuser/hive.log
  2016-02-29 11:29:41,104 INFO  [main]: parse.ParseDriver (ParseDriver.java:parse(185)) - Parsing command: ... name LIKE '???????%' ...
  </code></pre>
  
  <p>I've been investigating this problem for half day but could not find any useful information.</p>
  
  <p>I appreciate if anyone can give me some advice.</p>
  
  <p>PS:</p>
  
  <ol>
  <li>Hive Server is not an option. I have to invoke hive client via shell.</li>
  <li>I'm using Hive 0.14.0.</li>
  </ol>