[
https://issues.apache.org/jira/browse/HIVE-15820?focusedWorklogId=528297&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-528297
]
ASF GitHub Bot logged work on HIVE-15820:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 25/Dec/20 03:04
Start Date: 25/Dec/20 03:04
Worklog Time Spent: 10m
Work Description: ujc714 opened a new pull request #1814:
URL: https://github.com/apache/hive/pull/1814
### What changes were proposed in this pull request?
1) Don't check if a line is a comment in Beeline.dispatch(). Instead, remove
the comments from the line.
2) Replace removeComments(String, int[]) with removeComments(String) in
Commands.handleMultiLineCmd().
### Why are the changes needed?
1) The queries in '-e' parameter is passed to Beeline.dispatch() as a single
line although there could be multiple lines. If the first line is a comment,
the rest lines are ignored. We should pass the query strings to
Commands.execute().
2) HiveStringUtils.removeComments(String, int[]) is used for a single line.
In this method. If we use it to check a multiple line string and there is one
comment line, the lines after this comment line will be discarded. In fact,
HiveStringUtils.removeComments(String) splits a multiple line string to several
single line strings and calls HiveStringUtils.removeComments(String, int[]) to
process each single line. So HiveStringUtils.removeComments(String) is what we
should use in Commands.handleMultiLineCmd().
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
1) org.apache.hive.beeline.testLinesEndingWithComments is used to test
HiveStringUtils.removeComments(String).
2) org.apache.hive.beeline.cli.testSqlFromCmdWithComments* are used to test
queries passed via '-e' option. And testSqlFromCmdWithComments2 is used to test
the query after a comment line.
----------------------------------------------------------------
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: 528297)
Remaining Estimate: 0h
Time Spent: 10m
> 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: muxin
> Priority: Major
> Labels: patch
> Attachments: HIVE-15820.patch
>
> Time Spent: 10m
> 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)