impala/hive grammar
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
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.
Any progress here?
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 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
what can I do if add code to current version JsqlParser?
- add the
insert overwritelogic to the filesrc/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt? - how much work is there?
As @wumpz mentioned:
- take the class
Insertas a template (and maybe rename it to 'InsertInto') - create a new class 'InsertOverwrite`
- provide tokens for it in the Grammar (e.g the
OVERWRITE) - provide productions for it in the Grammar
- amend the Productions for
Blocks(),Statements(),Statement(),SingleStatements() - 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 ok , thanks
@wat1r So can we close this?
@wumpz It's ok for me, the issue is opened by this guy @xiearthur