JSqlParser icon indicating copy to clipboard operation
JSqlParser copied to clipboard

impala/hive grammar

Open xiearthur opened this issue 6 years ago • 9 comments

I want to implement impala/hive grammar, for example:

insert overwrite a(b,c) partitions(tx_date=20190626) select b,c from b

I would like to ask which class I should pay attention to

xiearthur avatar Jul 29 '19 06:07 xiearthur

I would start a new class IMHO. The ordinary insert into statement. Is to complicated to be modified.

Look at the SingleStatement() rule in the grammar file. There all main statements like select, insert, .. start.

wumpz avatar Jul 29 '19 06:07 wumpz

Any progress here?

wumpz avatar Aug 11 '19 08:08 wumpz

Looking at the hive manual it looks like insert overwrite is something like:

INSERT OVERWRITE TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...) [IF NOT EXISTS]] select_statement1 FROM from_statement;

Further down in the manual it has another FROM x INSERT OVERWRITE flavour:

FROM page_view_stg pvs
INSERT OVERWRITE TABLE page_view PARTITION(dt='2008-06-08', country)
       SELECT pvs.viewTime, pvs.userid, pvs.page_url, pvs.referrer_url, null, null, pvs.ip, pvs.cnt

What I think is the suggested it to mofify the SimpleStatement grammar here.

The easy one to start with would seem to be the FROM x INSERT OVERWRITE TABLE y SELECT z. I am guessing that a new | from() can be added into the SimpleStatement and that could be fairly standalone and not interfer with other stuff.

The bit that I am not sure about is how to get a match on INSERT OVERWRITE without having a load of problems merging that into the existing Insert().Should I try to put a more specific | InsertOverwrite() into the list? I am thinking that that is a question about how to use jjtree but if anyone with experience could make a suggestion that would be a great help.

simbo1905 avatar Mar 15 '20 10:03 simbo1905

@simbo1905 i recently implemented a new feature here #977

I found that referencing the grammar for javacc: https://javacc.github.io/javacc/documentation/grammar.html and the oracle SQL grammar (ebnf) sort of made it Straight forward. I think I would create an insert overwrite and put it above the insert match, so then the parser first explores if it is an insert overwrite and if not it goes Through the regular insert rules/productions

AnEmortalKid avatar Apr 29 '20 04:04 AnEmortalKid

what can I do if add code to current version JsqlParser?

  • add the insert overwrite logic to the file src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt?
  • how much work is there?

wat1r avatar May 25 '21 06:05 wat1r

As @wumpz mentioned:

  1. take the class Insert as a template (and maybe rename it to 'InsertInto')
  2. create a new class 'InsertOverwrite`
  3. provide tokens for it in the Grammar (e.g the OVERWRITE)
  4. provide productions for it in the Grammar
  5. amend the Productions for Blocks(), Statements(), Statement(), SingleStatements()
  6. ensure, that all existing Test run throough (and you did not break anything)

Personally I do not see any value in this kind of syntax. There is a SQL Standard for a reason and it is bad enough that Oracle does not follow it, but hey that is Oracle.

manticore-projects avatar May 25 '21 06:05 manticore-projects

@manticore-projects ok , thanks

wat1r avatar May 25 '21 06:05 wat1r

@wat1r So can we close this?

wumpz avatar May 25 '21 21:05 wumpz

@wumpz It's ok for me, the issue is opened by this guy @xiearthur

wat1r avatar May 27 '21 02:05 wat1r