[ 
https://issues.apache.org/jira/browse/HIVE-15820?focusedWorklogId=531888&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-531888
 ]

ASF GitHub Bot logged work on HIVE-15820:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 06/Jan/21 14:05
            Start Date: 06/Jan/21 14:05
    Worklog Time Spent: 10m 
      Work Description: nrg4878 commented on a change in pull request #1814:
URL: https://github.com/apache/hive/pull/1814#discussion_r552640050



##########
File path: beeline/src/test/org/apache/hive/beeline/TestCommands.java
##########
@@ -30,21 +30,35 @@
 
   @Test
   public void testLinesEndingWithComments() {
-    int[] escape = {-1};
-    assertEquals("show tables;", removeComments("show tables;",escape));
-    assertEquals("show tables;", removeComments("show tables; 
--comments",escape));
-    assertEquals("show tables;", removeComments("show tables; 
-------comments",escape));
-    assertEquals("show tables;", removeComments("show tables; 
-------comments;one;two;three;;;;",escape));
-    assertEquals("show", removeComments("show-- tables; 
-------comments",escape));
-    assertEquals("show", removeComments("show --tables; 
-------comments",escape));
-    assertEquals("s", removeComments("s--how --tables; 
-------comments",escape));
-    assertEquals("", removeComments("-- show tables; -------comments",escape));
+    assertEquals("show tables;", removeComments("show tables;"));
+    assertEquals("show tables;", removeComments("show tables; --comments"));
+    assertEquals("show tables;", removeComments("show tables; 
-------comments"));
+    assertEquals("show tables;", removeComments("show tables; 
-------comments;one;two;three;;;;"));
+    assertEquals("show", removeComments("show-- tables; -------comments"));
+    assertEquals("show", removeComments("show --tables; -------comments"));
+    assertEquals("s", removeComments("s--how --tables; -------comments"));
+    assertEquals("", removeComments("-- show tables; -------comments"));
 
-    assertEquals("\"show tables\"", removeComments("\"show tables\" 
--comments",escape));
-    assertEquals("\"show --comments tables\"", removeComments("\"show 
--comments tables\" --comments",escape));
-    assertEquals("\"'show --comments' tables\"", removeComments("\"'show 
--comments' tables\" --comments",escape));
-    assertEquals("'show --comments tables'", removeComments("'show --comments 
tables' --comments",escape));
-    assertEquals("'\"show --comments tables\"'", removeComments("'\"show 
--comments tables\"' --comments",escape));
+    assertEquals("\"show tables\"", removeComments("\"show tables\" 
--comments"));
+    assertEquals("\"show --comments tables\"", removeComments("\"show 
--comments tables\" --comments"));
+    assertEquals("\"'show --comments' tables\"", removeComments("\"'show 
--comments' tables\" --comments"));
+    assertEquals("'show --comments tables'", removeComments("'show --comments 
tables' --comments"));
+    assertEquals("'\"show --comments tables\"'", removeComments("'\"show 
--comments tables\"' --comments"));
+
+    assertEquals("show tables;", removeComments("--comments\nshow tables;"));
+    assertEquals("show tables;", removeComments("--comments\nshow tables; 
--comments"));
+    assertEquals("show tables;", removeComments("--comments\nshow tables; 
-------comments"));
+    assertEquals("show tables;", removeComments("--comments\nshow tables; 
-------comments;one;two;three;;;;"));
+    assertEquals("show", removeComments("--comments\nshow-- tables; 
-------comments"));
+    assertEquals("show", removeComments("--comments\nshow --tables; 
-------comments"));
+    assertEquals("s", removeComments("--comments\ns--how --tables; 
-------comments"));
+    assertEquals("", removeComments("--comments\n-- show tables; 
-------comments"));
+
+    assertEquals("\"show tables\"", removeComments("--comments\n\"show 
tables\" --comments"));
+    assertEquals("\"show --comments tables\"", 
removeComments("--comments\n\"show --comments tables\" --comments"));
+    assertEquals("\"'show --comments' tables\"", 
removeComments("--comments\n\"'show --comments' tables\" --comments"));
+    assertEquals("'show --comments tables'", removeComments("--comments\n'show 
--comments tables' --comments"));
+    assertEquals("'\"show --comments tables\"'", 
removeComments("--comments\n'\"show --comments tables\"' --comments"));

Review comment:
       Could you please add a test scenario where a multiline query strings has 
comments in between fragments of query? just as an example
   "select col1,
   --partitioned year column
   year,
   --partitioned month column
   month,
   --partitioned date column
   date
   from test_table
   where
   --for a particular user
   username = 'foo';"
   
   should return something equivalent to
   "select col1, year, month, date from test_table where username = 'foo';"




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 531888)
    Time Spent: 40m  (was: 0.5h)

> comment at the head of beeline -e
> ---------------------------------
>
>                 Key: HIVE-15820
>                 URL: https://issues.apache.org/jira/browse/HIVE-15820
>             Project: Hive
>          Issue Type: Bug
>          Components: Beeline
>    Affects Versions: 1.2.1, 2.1.1
>            Reporter: muxin
>            Assignee: Robbie Zhang
>            Priority: Major
>              Labels: patch, pull-request-available
>         Attachments: HIVE-15820.patch
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> $ beeline -u jdbc:hive2://localhost:10000 -n test -e "
> > --asdfasdfasdfasdf
> > select * from test_table;
> > "
> expected result of the above command should be all rows of test_table(same as 
> run in beeline interactive mode),but it does not output anything.
> the cause is that -e option will read commands as one string, and in method 
> dispatch(String line) it calls function isComment(String line) in the first, 
> which using
>  'lineTrimmed.startsWith("#") || lineTrimmed.startsWith("--")' 
> to regard commands as a comment.
> two ways can be considered to fix this problem:
> 1. in method initArgs(String[] args), split command by '\n' into command list 
> before dispatch when cl.getOptionValues('e') != null
> 2. in method dispatch(String line), remove comments using this:
> static String removeComments(String line) {
>     if (line == null || line.isEmpty()) {
>         return line;
>     }
>     StringBuilder builder = new StringBuilder();
>     int escape = -1;
>     for (int index = 0; index < line.length(); index++) {
>         if (index < line.length() - 1 && line.charAt(index) == 
> line.charAt(index + 1)) {
>             if (escape == -1 && line.charAt(index) == '-') {
>                 //find \n as the end of comment
>                 index = line.indexOf('\n',index+1);
>                 //there is no sql after this comment,so just break out
>                 if (-1==index){
>                     break;
>                 }
>             }
>         }
>         char letter = line.charAt(index);
>         if (letter == escape) {
>             escape = -1; // Turn escape off.
>         } else if (escape == -1 && (letter == '\'' || letter == '"')) {
>             escape = letter; // Turn escape on.
>         }
>         builder.append(letter);
>     }
>     return builder.toString();
>   }
> the second way can be a general solution to remove all comments start with 
> '--'  in a sql



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to