16

I have seen other posts saying that double hyphen -- should be a hive comment. But at least within the hive CLI that is not working properly;

hive> -- some comment;
FAILED: Parse Error: line 0:-1 cannot recognize input near '<EOF>' '<EOF>' '<EOF>'

Even in Eduardo Capriolo's book he says the same:

As of Hive v0.8.0, you can embed lines of comments that start with the string --,
for example:
-- Copyright (c) 2012 Megacorp, LLC.
-- This is the best Hive script evar!

The version is apparently 0.8.1 (I am using latest Amazon EMR)

hadoop@ip-10-114-113-44:~$ hive
bin is /home/hadoop/.versions/hive-0.8.1/bin
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560

2 Answers2

10

Case is simple Hive accepts comments but not as a single line. If you try:

--comment
show tables;

or

show tables
--comment;

everything will be fine. GL with Hive struggle!

www
  • 4,365
  • 1
  • 23
  • 24
  • 1
    Generally this is true, but I've found you can't do `--comment[linebreak]SET hivevar:foo=bar;` in the CLI (I guess because `SET` needs to be the start of a statement). In that case I had to either remove the comment or live with the error from including the semi-colon `--comment;[linebreak]SET hivevar:foo=bar;` (which as javadba points out, is actually a harmless -- if annoying -- error) – Tim Goodman May 16 '14 at 13:08
5

I found a middling workaround:

place semicolon after each comment line like thus:

-- some comment  ;

Then What happens - the CLI does issue an error (still!) but at least does not mangle the succeeding lines of code.

I am using this technique in a few hive scripts now, it allows me to cut and paste snippets into the CLI (with the mentioned caveat ).

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560