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 EA4F4200C23 for ; Wed, 22 Feb 2017 13:22:47 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id E8F13160B67; Wed, 22 Feb 2017 12:22:47 +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 3D584160B49 for ; Wed, 22 Feb 2017 13:22:47 +0100 (CET) Received: (qmail 30852 invoked by uid 500); 22 Feb 2017 12:22:46 -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 30843 invoked by uid 99); 22 Feb 2017 12:22:46 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Feb 2017 12:22:46 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id DACE3C05B0 for ; Wed, 22 Feb 2017 12:22:45 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.999 X-Spam-Level: X-Spam-Status: No, score=-1.999 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id a20uUAp4haik for ; Wed, 22 Feb 2017 12:22:45 +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 CB83C5FC3C for ; Wed, 22 Feb 2017 12:22:44 +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 57776E012B for ; Wed, 22 Feb 2017 12:22: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 0F5A824121 for ; Wed, 22 Feb 2017 12:22:44 +0000 (UTC) Date: Wed, 22 Feb 2017 12:22:44 +0000 (UTC) From: "muxin (JIRA)" To: issues@hive.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Work started] (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:22:48 -0000 [ https://issues.apache.org/jira/browse/HIVE-15820?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Work on HIVE-15820 started by muxin. ------------------------------------ > 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 > Labels: 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)