[ 
https://issues.apache.org/jira/browse/HIVE-19700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16489825#comment-16489825
 ] 

Naveen Gangam commented on HIVE-19700:
--------------------------------------

For example,
{code}
$ cat /tmp/multi.sql 
select * from testa
where
col2 > 100;
$ beeline -u "jdbc:hive2://localhost:10000" -n hive -p hive --silent=true -f 
/tmp/multi.sql > /tmp/b_multi.out &
$ cat /tmp/b_multi.out 
null+-------------+-------------+-------------+-------------+-------------+--------------+--------------+--------------+--+
| testa.col1  | testa.col2  | testa.col3  | testa.col4  | testa.col5  | 
testa.part1  | testa.part2  | testa.part3  |
+-------------+-------------+-------------+-------------+-------------+--------------+--------------+--------------+--+
| 12.341      | 1001        | 2001        | 3001        | abcd        | CA      
     | ABC          | 300          |
| 12.341      | 1001        | 2001        | 3001        | abcd        | UK      
     | DEF          | 123          |
| 12.341      | 1001        | 2001        | 3001        | abcd        | US      
     | ABC          | 123          |
| 12.341      | 1001        | 2001        | 3001        | abcd        | US      
     | DEF          | 200          |
+-------------+-------------+-------------+-------------+-------------+--------------+--------------+--------------+--+

With the proposed fix,
$ beeline -u "jdbc:hive2://localhost:10000" -n hive -p hive --silent=true -f 
/tmp/multi.sql > /tmp/g_multi.out
$ cat /tmp/g_multi.out 
+-------------+-------------+-------------+-------------+-------------+--------------+--------------+--------------+--+
| testa.col1  | testa.col2  | testa.col3  | testa.col4  | testa.col5  | 
testa.part1  | testa.part2  | testa.part3  |
+-------------+-------------+-------------+-------------+-------------+--------------+--------------+--------------+--+
| 12.341      | 1001        | 2001        | 3001        | abcd        | CA      
     | ABC          | 300          |
| 12.341      | 1001        | 2001        | 3001        | abcd        | UK      
     | DEF          | 123          |
| 12.341      | 1001        | 2001        | 3001        | abcd        | US      
     | ABC          | 123          |
| 12.341      | 1001        | 2001        | 3001        | abcd        | US      
     | DEF          | 200          |
+-------------+-------------+-------------+-------------+-------------+--------------+--------------+--------------+--+
{code}


> Workaround for JLine issue with UnsupportedTerminal
> ---------------------------------------------------
>
>                 Key: HIVE-19700
>                 URL: https://issues.apache.org/jira/browse/HIVE-19700
>             Project: Hive
>          Issue Type: Bug
>            Reporter: Naveen Gangam
>            Assignee: Naveen Gangam
>            Priority: Major
>             Fix For: 2.2.1
>
>
> From the JLine's ConsoleReader, readLine(prompt, mask) calls the following 
> beforeReadLine() method.
> {code}
>         try {
>             // System.out.println("is terminal supported " + 
> terminal.isSupported());
>             if (!terminal.isSupported()) {
>                 beforeReadLine(prompt, mask);
>             }
> {code}
> So specifically when using UnsupportedTerminal {{-Djline.terminal}} and 
> {{prompt=null}} and {{mask!=null}}, a "null" string gets printed to the 
> console before and after the query result. {{UnsupportedTerminal}} is 
> required to be used when running beeline as a background process, hangs 
> otherwise.
> {code}
>     private void beforeReadLine(final String prompt, final Character mask) {
>         if (mask != null && maskThread == null) {
>             final String fullPrompt = "\r" + prompt
>                 + "                 "
>                 + "                 "
>                 + "                 "
>                 + "\r" + prompt;
>             maskThread = new Thread()
>             {
>                 public void run() {
>                     while (!interrupted()) {
>                         try {
>                             Writer out = getOutput();
>                             out.write(fullPrompt);
> {code}
> So the {{prompt}} is null and {{mask}} is NOT in atleast 2 scenarios in 
> beeline. 
> when beeline's silent=true, prompt is null
> * 
> https://github.com/apache/hive/blob/master/beeline/src/java/org/apache/hive/beeline/BeeLine.java#L1264
> when running multiline queries
> * 
> https://github.com/apache/hive/blob/master/beeline/src/java/org/apache/hive/beeline/Commands.java#L1093
> When executing beeline in script mode (commands in a file), there should not 
> be any masking while reading lines from the script file. aka, entire line 
> should be a beeline command or part of a multiline hive query.
> So it should be safe to use a null mask instead of 
> {{ConsoleReader.NULL_MASK}} when using UnsupportedTerminal as jline terminal.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to