Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 684ED200C23 for ; Wed, 22 Feb 2017 13:32:51 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 67008160B67; Wed, 22 Feb 2017 12:32:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B0E02160B49 for ; Wed, 22 Feb 2017 13:32:50 +0100 (CET) Received: (qmail 46349 invoked by uid 500); 22 Feb 2017 12:32:50 -0000 Mailing-List: contact issues-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hive.apache.org Delivered-To: mailing list issues@hive.apache.org Received: (qmail 46340 invoked by uid 99); 22 Feb 2017 12:32:49 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Feb 2017 12:32:49 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 53E1CC1FCF for ; Wed, 22 Feb 2017 12:32:49 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.999 X-Spam-Level: X-Spam-Status: No, score=0.999 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id BkSOBqlQfucm for ; Wed, 22 Feb 2017 12:32:48 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 7B4E65FC3C for ; Wed, 22 Feb 2017 12:32:48 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id DE40EE0A6C for ; Wed, 22 Feb 2017 12:32:44 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 2A7D32412B for ; Wed, 22 Feb 2017 12:32:44 +0000 (UTC) Date: Wed, 22 Feb 2017 12:32:44 +0000 (UTC) From: "muxin (JIRA)" To: issues@hive.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (HIVE-15820) comment at the head of beeline -e MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 22 Feb 2017 12:32:51 -0000 [ https://issues.apache.org/jira/browse/HIVE-15820?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15878105#comment-15878105 ] muxin commented on HIVE-15820: ------------------------------ sorry Vihang Karajgaonkar, I'm still not familiar with this. I just attached a patch, please review it and inform me if there is anything inappropriate > 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: Vihang Karajgaonkar > 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 (v6.3.15#6346)