You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "Vineet Garg (JIRA)" <ji...@apache.org> on 2018/06/15 22:56:00 UTC
[jira] [Comment Edited] (HIVE-15820) comment at the head of beeline
-e
[ https://issues.apache.org/jira/browse/HIVE-15820?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16514469#comment-16514469 ]
Vineet Garg edited comment on HIVE-15820 at 6/15/18 10:55 PM:
--------------------------------------------------------------
[~muxin] You don't need to write this logic. This logic already exists in {{HiveStringUtils.removeComments()}}. You can updated {{Beeline::dispatch}} to call this method.
was (Author: vgarg):
[~muxin] You don't need to write this logic. This logic already exists in {{HiveStringUtils.removeComments(line)}}. You can updated {{Beeline::dispatch}} to call this method.
> 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
>
>
> $ 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
(v7.6.3#76005)