From a06d04f29180c1ded5dcf6bf25a85bdd4aaa53c9 Mon Sep 17 00:00:00 2001 From: skalashnikov Date: Fri, 20 Oct 2017 16:26:04 +0300 Subject: [PATCH] IGNITE-6276: integrated experimental ANTLR generated parser --- modules/indexing/pom.xml | 23 + .../org/apache/ignite/sql/parser/IgniteSqlLexer.g4 | 66 +++ .../apache/ignite/sql/parser/IgniteSqlParser.g4} | 98 ++-- .../parser/GridExperimentalSqlParserListener.java | 70 +++ .../parser/GridExperimentalSqlParserVisitor.java | 80 +++ .../ignite/internal/parser/IgniteSqlLexer.java | 181 ------ .../ignite/internal/parser/IgniteSqlParser.java | 636 --------------------- .../parser/IgniteSqlParserBaseListener.java | 149 ----- .../parser/IgniteSqlParserBaseVisitor.java | 79 --- .../internal/parser/IgniteSqlParserListener.java | 102 ---- .../internal/parser/IgniteSqlParserVisitor.java | 69 --- .../processors/query/h2/IgniteH2Indexing.java | 47 +- .../query/h2/ddl/DdlStatementsProcessor.java | 7 +- .../query/h2/parser/GridExperimentalSqlParser.java | 146 +++++ .../GridExperimentalSqlParserErrorListener.java | 27 + .../parser/GridExperimentalSqlParserException.java | 41 ++ ...teExperimentalSqlParserIntegrationSelfTest.java | 97 ++++ .../IgniteExperimentalSqlParserSelfTest.java | 183 ++++++ 18 files changed, 842 insertions(+), 1259 deletions(-) create mode 100644 modules/indexing/src/main/antlr4/org/apache/ignite/sql/parser/IgniteSqlLexer.g4 rename modules/indexing/src/main/{java/org/apache/ignite/internal/processors/query/h2/parser/GridCustomSqlParser.java => antlr4/org/apache/ignite/sql/parser/IgniteSqlParser.g4} (56%) create mode 100644 modules/indexing/src/main/java/org/apache/ignite/internal/parser/GridExperimentalSqlParserListener.java create mode 100644 modules/indexing/src/main/java/org/apache/ignite/internal/parser/GridExperimentalSqlParserVisitor.java delete mode 100644 modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlLexer.java delete mode 100644 modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParser.java delete mode 100644 modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserBaseListener.java delete mode 100644 modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserBaseVisitor.java delete mode 100644 modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserListener.java delete mode 100644 modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserVisitor.java create mode 100644 modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridExperimentalSqlParser.java create mode 100644 modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridExperimentalSqlParserErrorListener.java create mode 100644 modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridExperimentalSqlParserException.java create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/parser/IgniteExperimentalSqlParserIntegrationSelfTest.java create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/parser/IgniteExperimentalSqlParserSelfTest.java diff --git a/modules/indexing/pom.xml b/modules/indexing/pom.xml index 82d701a5a4..3cedbc6e3e 100644 --- a/modules/indexing/pom.xml +++ b/modules/indexing/pom.xml @@ -130,6 +130,29 @@ + org.antlr + antlr4-maven-plugin + ${antlr.version} + + ${basedir}/src/main/antlr4/org/apache/ignite/sql/parser + + + IgniteSqlLexer.g4 + IgniteSqlParser.g4 + + true + true + + + + + antlr4 + + + + + + org.apache.maven.plugins maven-jar-plugin diff --git a/modules/indexing/src/main/antlr4/org/apache/ignite/sql/parser/IgniteSqlLexer.g4 b/modules/indexing/src/main/antlr4/org/apache/ignite/sql/parser/IgniteSqlLexer.g4 new file mode 100644 index 0000000000..a132f41bda --- /dev/null +++ b/modules/indexing/src/main/antlr4/org/apache/ignite/sql/parser/IgniteSqlLexer.g4 @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +lexer grammar IgniteSqlLexer; + +@lexer::header { +package org.apache.ignite.internal.parser; +} + +SPACE: [ \t\r\n]+ -> channel(HIDDEN); + +DROP: D R O P; +INDEX: I N D E X; +IF: I F; +EXISTS: E X I S T S; +TABLE: T A B L E; + +SEMI: ';'; +DOT: '.'; + +ID: ( ID_LITERAL | DQUOTE_STRING { setText(getText().substring(1, getText().length() - 1)); }); + +ID_LITERAL: [A-Za-z_][A-Za-z_0-9]*; +DQUOTE_STRING: '"' ( '\\'. | '""' | ~('"'| '\\') )* '"'; + +// solving case-sensitivity for keywords +fragment A: [Aa]; +fragment B: [Bb]; +fragment C: [Cc]; +fragment D: [Dd]; +fragment E: [Ee]; +fragment F: [Ff]; +fragment G: [Gg]; +fragment H: [Hh]; +fragment I: [Ii]; +fragment J: [Jj]; +fragment K: [Kk]; +fragment L: [Ll]; +fragment M: [Mm]; +fragment N: [Nn]; +fragment O: [Oo]; +fragment P: [Pp]; +fragment Q: [Qq]; +fragment R: [Rr]; +fragment S: [Ss]; +fragment T: [Tt]; +fragment U: [Uu]; +fragment V: [Vv]; +fragment W: [Ww]; +fragment X: [Xx]; +fragment Y: [Yy]; +fragment Z: [Zz]; \ No newline at end of file diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridCustomSqlParser.java b/modules/indexing/src/main/antlr4/org/apache/ignite/sql/parser/IgniteSqlParser.g4 similarity index 56% rename from modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridCustomSqlParser.java rename to modules/indexing/src/main/antlr4/org/apache/ignite/sql/parser/IgniteSqlParser.g4 index fed1045ad6..5829891c27 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridCustomSqlParser.java +++ b/modules/indexing/src/main/antlr4/org/apache/ignite/sql/parser/IgniteSqlParser.g4 @@ -1,40 +1,58 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ignite.internal.processors.query.h2.parser; - -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.TokenStream; -import org.apache.ignite.internal.parser.*; - -/** */ -public class GridCustomSqlParser { - IgniteSqlLexer lexer; - IgniteSqlParser parser; - - /** */ - public GridCustomSqlParser(String input) { - lexer = new IgniteSqlLexer(CharStreams.fromString(input)); - - TokenStream tokenStream = new CommonTokenStream(lexer); - - parser = new IgniteSqlParser(tokenStream); - } - - - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +parser grammar IgniteSqlParser; + +@header { +package org.apache.ignite.internal.parser; +} + +options { tokenVocab=IgniteSqlLexer; } + +root + : sqlStatements? EOF + ; + +sqlStatements + : (sqlStatement SEMI | emptyStatement)* + (sqlStatement SEMI? | emptyStatement) + ; + +sqlStatement + : ddlStatement + ; + +ddlStatement + : dropIndex + ; + +dropIndex + : DROP INDEX ifExists? (indexName | indexNameWithSchema) + ; + +ifExists + : IF EXISTS; + +indexName + : ID; + +indexNameWithSchema + : ID DOT ID; + +emptyStatement + : SEMI + ; \ No newline at end of file diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/GridExperimentalSqlParserListener.java b/modules/indexing/src/main/java/org/apache/ignite/internal/parser/GridExperimentalSqlParserListener.java new file mode 100644 index 0000000000..29980dfcd7 --- /dev/null +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/parser/GridExperimentalSqlParserListener.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.parser; + +import org.apache.ignite.internal.processors.query.h2.sql.GridSqlDropIndex; +import org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement; +import org.apache.ignite.internal.parser.IgniteSqlParser.SqlStatementsContext; +import org.apache.ignite.internal.parser.IgniteSqlParser.SqlStatementContext; +import org.apache.ignite.internal.parser.IgniteSqlParser.DropIndexContext; +import org.apache.ignite.internal.parser.IgniteSqlParser.IfExistsContext; + +import java.util.ArrayList; +import java.util.List; + +/** */ +public class GridExperimentalSqlParserListener extends IgniteSqlParserBaseListener { + /** */ + private GridSqlDropIndex dropIndex; + + /** */ + final List stmts = new ArrayList<>(); + + /** */ + public List getStatements() { + return stmts; + } + + /** */ + @Override public void enterDropIndex(DropIndexContext ctx) { + dropIndex = new GridSqlDropIndex(); + } + + /** */ + @Override public void exitDropIndex(DropIndexContext ctx) { + assert dropIndex != null; + + if (ctx.indexNameWithSchema() != null) { + dropIndex.schemaName(ctx.indexNameWithSchema().getChild(0).getText()); + dropIndex.indexName(ctx.indexNameWithSchema().getChild(2).getText()); + } + else { + dropIndex.schemaName("public"); // Current schema of connection + dropIndex.indexName(ctx.indexName().getText()); + } + + stmts.add(dropIndex); + } + + /** */ + @Override public void enterIfExists(IfExistsContext ctx) { + assert dropIndex != null; + + dropIndex.ifExists(true); + } +} \ No newline at end of file diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/GridExperimentalSqlParserVisitor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/parser/GridExperimentalSqlParserVisitor.java new file mode 100644 index 0000000000..da39914dc1 --- /dev/null +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/parser/GridExperimentalSqlParserVisitor.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.parser; + +import org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement; +import org.apache.ignite.internal.processors.query.h2.sql.GridSqlDropIndex; +import org.apache.ignite.internal.parser.IgniteSqlParser.SqlStatementsContext; +import org.apache.ignite.internal.parser.IgniteSqlParser.SqlStatementContext; +import org.apache.ignite.internal.parser.IgniteSqlParser.DropIndexContext; + +import java.util.ArrayList; +import java.util.List; + +/** */ +public class GridExperimentalSqlParserVisitor extends IgniteSqlParserBaseVisitor> { + /** */ + @Override public List visitSqlStatements(SqlStatementsContext ctx) { + List res = new ArrayList<>(); + + DropIndexVisitor v = new DropIndexVisitor(); + + for (SqlStatementContext stmt : ctx.sqlStatement()) + res.add(v.visitSqlStatement(stmt)); + + return res; + } + + /** */ + @Override protected List aggregateResult(List aggregate, + List nextResult) { + if (aggregate == null) + return nextResult; + + if (nextResult == null) + return aggregate; + + aggregate.addAll(nextResult); + + return aggregate; + } + + + /** */ + public static class DropIndexVisitor extends IgniteSqlParserBaseVisitor { + /** */ + @Override public GridSqlDropIndex visitDropIndex(DropIndexContext ctx) { + GridSqlDropIndex dropIndex = new GridSqlDropIndex(); + + dropIndex.schemaName("public"); + + dropIndex.ifExists(ctx.ifExists() != null); + + if (ctx.indexNameWithSchema() != null) { + dropIndex.schemaName(ctx.indexNameWithSchema().getChild(0).getText()); + dropIndex.indexName(ctx.indexNameWithSchema().getChild(2).getText()); + } + else { + dropIndex.schemaName("public"); // Current schema of connection + dropIndex.indexName(ctx.indexName().getText()); + } + + return dropIndex; + } + } +} diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlLexer.java b/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlLexer.java deleted file mode 100644 index f41e92860a..0000000000 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlLexer.java +++ /dev/null @@ -1,181 +0,0 @@ -// Generated from IgniteSqlLexer.g4 by ANTLR 4.7 - -package org.apache.ignite.internal.parser; - -import org.antlr.v4.runtime.Lexer; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.TokenStream; -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.*; -import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.misc.*; - -@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) -public class IgniteSqlLexer extends Lexer { - static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); } - - protected static final DFA[] _decisionToDFA; - protected static final PredictionContextCache _sharedContextCache = - new PredictionContextCache(); - public static final int - SPACE=1, DROP=2, INDEX=3, IF=4, EXISTS=5, SEMI=6, DOT=7, ID=8, ID_LITERAL=9, - DQUOTE_STRING=10; - public static String[] channelNames = { - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - }; - - public static String[] modeNames = { - "DEFAULT_MODE" - }; - - public static final String[] ruleNames = { - "SPACE", "DROP", "INDEX", "IF", "EXISTS", "SEMI", "DOT", "ID", "ID_LITERAL", - "DQUOTE_STRING", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", - "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", - "Z" - }; - - private static final String[] _LITERAL_NAMES = { - null, null, null, null, null, null, "';'", "'.'" - }; - private static final String[] _SYMBOLIC_NAMES = { - null, "SPACE", "DROP", "INDEX", "IF", "EXISTS", "SEMI", "DOT", "ID", "ID_LITERAL", - "DQUOTE_STRING" - }; - public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); - - /** - * @deprecated Use {@link #VOCABULARY} instead. - */ - @Deprecated - public static final String[] tokenNames; - static { - tokenNames = new String[_SYMBOLIC_NAMES.length]; - for (int i = 0; i < tokenNames.length; i++) { - tokenNames[i] = VOCABULARY.getLiteralName(i); - if (tokenNames[i] == null) { - tokenNames[i] = VOCABULARY.getSymbolicName(i); - } - - if (tokenNames[i] == null) { - tokenNames[i] = ""; - } - } - } - - @Override - @Deprecated - public String[] getTokenNames() { - return tokenNames; - } - - @Override - - public Vocabulary getVocabulary() { - return VOCABULARY; - } - - - public IgniteSqlLexer(CharStream input) { - super(input); - _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); - } - - @Override - public String getGrammarFileName() { return "IgniteSqlLexer.g4"; } - - @Override - public String[] getRuleNames() { return ruleNames; } - - @Override - public String getSerializedATN() { return _serializedATN; } - - @Override - public String[] getChannelNames() { return channelNames; } - - @Override - public String[] getModeNames() { return modeNames; } - - @Override - public ATN getATN() { return _ATN; } - - @Override - public void action(RuleContext _localctx, int ruleIndex, int actionIndex) { - switch (ruleIndex) { - case 7: - ID_action((RuleContext)_localctx, actionIndex); - break; - } - } - private void ID_action(RuleContext _localctx, int actionIndex) { - switch (actionIndex) { - case 0: - setText(getText().substring(1, getText().length() - 1)); - break; - } - } - - public static final String _serializedATN = - "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\f\u00b9\b\1\4\2\t"+ - "\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+ - "\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+ - "\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+ - "\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t \4!"+ - "\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\3\2\6\2M\n\2\r\2\16\2N\3\2\3\2\3\3\3\3\3"+ - "\3\3\3\3\3\3\4\3\4\3\4\3\4\3\4\3\4\3\5\3\5\3\5\3\6\3\6\3\6\3\6\3\6\3\6"+ - "\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\t\3\t\5\tp\n\t\3\n\3\n\7\nt\n\n\f\n\16"+ - "\nw\13\n\3\13\3\13\3\13\3\13\3\13\3\13\7\13\177\n\13\f\13\16\13\u0082"+ - "\13\13\3\13\3\13\3\f\3\f\3\r\3\r\3\16\3\16\3\17\3\17\3\20\3\20\3\21\3"+ - "\21\3\22\3\22\3\23\3\23\3\24\3\24\3\25\3\25\3\26\3\26\3\27\3\27\3\30\3"+ - "\30\3\31\3\31\3\32\3\32\3\33\3\33\3\34\3\34\3\35\3\35\3\36\3\36\3\37\3"+ - "\37\3 \3 \3!\3!\3\"\3\"\3#\3#\3$\3$\3%\3%\2\2&\3\3\5\4\7\5\t\6\13\7\r"+ - "\b\17\t\21\n\23\13\25\f\27\2\31\2\33\2\35\2\37\2!\2#\2%\2\'\2)\2+\2-\2"+ - "/\2\61\2\63\2\65\2\67\29\2;\2=\2?\2A\2C\2E\2G\2I\2\3\2 \5\2\13\f\17\17"+ - "\"\"\5\2C\\aac|\6\2\62;C\\aac|\4\2$$^^\4\2CCcc\4\2DDdd\4\2EEee\4\2FFf"+ - "f\4\2GGgg\4\2HHhh\4\2IIii\4\2JJjj\4\2KKkk\4\2LLll\4\2MMmm\4\2NNnn\4\2"+ - "OOoo\4\2PPpp\4\2QQqq\4\2RRrr\4\2SSss\4\2TTtt\4\2UUuu\4\2VVvv\4\2WWww\4"+ - "\2XXxx\4\2YYyy\4\2ZZzz\4\2[[{{\4\2\\\\||\2\u00a4\2\3\3\2\2\2\2\5\3\2\2"+ - "\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21"+ - "\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\3L\3\2\2\2\5R\3\2\2\2\7W\3\2\2\2\t"+ - "]\3\2\2\2\13`\3\2\2\2\rg\3\2\2\2\17i\3\2\2\2\21o\3\2\2\2\23q\3\2\2\2\25"+ - "x\3\2\2\2\27\u0085\3\2\2\2\31\u0087\3\2\2\2\33\u0089\3\2\2\2\35\u008b"+ - "\3\2\2\2\37\u008d\3\2\2\2!\u008f\3\2\2\2#\u0091\3\2\2\2%\u0093\3\2\2\2"+ - "\'\u0095\3\2\2\2)\u0097\3\2\2\2+\u0099\3\2\2\2-\u009b\3\2\2\2/\u009d\3"+ - "\2\2\2\61\u009f\3\2\2\2\63\u00a1\3\2\2\2\65\u00a3\3\2\2\2\67\u00a5\3\2"+ - "\2\29\u00a7\3\2\2\2;\u00a9\3\2\2\2=\u00ab\3\2\2\2?\u00ad\3\2\2\2A\u00af"+ - "\3\2\2\2C\u00b1\3\2\2\2E\u00b3\3\2\2\2G\u00b5\3\2\2\2I\u00b7\3\2\2\2K"+ - "M\t\2\2\2LK\3\2\2\2MN\3\2\2\2NL\3\2\2\2NO\3\2\2\2OP\3\2\2\2PQ\b\2\2\2"+ - "Q\4\3\2\2\2RS\5\35\17\2ST\59\35\2TU\5\63\32\2UV\5\65\33\2V\6\3\2\2\2W"+ - "X\5\'\24\2XY\5\61\31\2YZ\5\35\17\2Z[\5\37\20\2[\\\5E#\2\\\b\3\2\2\2]^"+ - "\5\'\24\2^_\5!\21\2_\n\3\2\2\2`a\5\37\20\2ab\5E#\2bc\5\'\24\2cd\5;\36"+ - "\2de\5=\37\2ef\5;\36\2f\f\3\2\2\2gh\7=\2\2h\16\3\2\2\2ij\7\60\2\2j\20"+ - "\3\2\2\2kp\5\23\n\2lm\5\25\13\2mn\b\t\3\2np\3\2\2\2ok\3\2\2\2ol\3\2\2"+ - "\2p\22\3\2\2\2qu\t\3\2\2rt\t\4\2\2sr\3\2\2\2tw\3\2\2\2us\3\2\2\2uv\3\2"+ - "\2\2v\24\3\2\2\2wu\3\2\2\2x\u0080\7$\2\2yz\7^\2\2z\177\13\2\2\2{|\7$\2"+ - "\2|\177\7$\2\2}\177\n\5\2\2~y\3\2\2\2~{\3\2\2\2~}\3\2\2\2\177\u0082\3"+ - "\2\2\2\u0080~\3\2\2\2\u0080\u0081\3\2\2\2\u0081\u0083\3\2\2\2\u0082\u0080"+ - "\3\2\2\2\u0083\u0084\7$\2\2\u0084\26\3\2\2\2\u0085\u0086\t\6\2\2\u0086"+ - "\30\3\2\2\2\u0087\u0088\t\7\2\2\u0088\32\3\2\2\2\u0089\u008a\t\b\2\2\u008a"+ - "\34\3\2\2\2\u008b\u008c\t\t\2\2\u008c\36\3\2\2\2\u008d\u008e\t\n\2\2\u008e"+ - " \3\2\2\2\u008f\u0090\t\13\2\2\u0090\"\3\2\2\2\u0091\u0092\t\f\2\2\u0092"+ - "$\3\2\2\2\u0093\u0094\t\r\2\2\u0094&\3\2\2\2\u0095\u0096\t\16\2\2\u0096"+ - "(\3\2\2\2\u0097\u0098\t\17\2\2\u0098*\3\2\2\2\u0099\u009a\t\20\2\2\u009a"+ - ",\3\2\2\2\u009b\u009c\t\21\2\2\u009c.\3\2\2\2\u009d\u009e\t\22\2\2\u009e"+ - "\60\3\2\2\2\u009f\u00a0\t\23\2\2\u00a0\62\3\2\2\2\u00a1\u00a2\t\24\2\2"+ - "\u00a2\64\3\2\2\2\u00a3\u00a4\t\25\2\2\u00a4\66\3\2\2\2\u00a5\u00a6\t"+ - "\26\2\2\u00a68\3\2\2\2\u00a7\u00a8\t\27\2\2\u00a8:\3\2\2\2\u00a9\u00aa"+ - "\t\30\2\2\u00aa<\3\2\2\2\u00ab\u00ac\t\31\2\2\u00ac>\3\2\2\2\u00ad\u00ae"+ - "\t\32\2\2\u00ae@\3\2\2\2\u00af\u00b0\t\33\2\2\u00b0B\3\2\2\2\u00b1\u00b2"+ - "\t\34\2\2\u00b2D\3\2\2\2\u00b3\u00b4\t\35\2\2\u00b4F\3\2\2\2\u00b5\u00b6"+ - "\t\36\2\2\u00b6H\3\2\2\2\u00b7\u00b8\t\37\2\2\u00b8J\3\2\2\2\b\2Nou~\u0080"+ - "\4\b\2\2\3\t\2"; - public static final ATN _ATN = - new ATNDeserializer().deserialize(_serializedATN.toCharArray()); - static { - _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; - for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { - _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); - } - } -} \ No newline at end of file diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParser.java b/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParser.java deleted file mode 100644 index ab2a458a6f..0000000000 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParser.java +++ /dev/null @@ -1,636 +0,0 @@ -// Generated from IgniteSqlParser.g4 by ANTLR 4.7 - -package org.apache.ignite.internal.parser; - -import org.antlr.v4.runtime.atn.*; -import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.misc.*; -import org.antlr.v4.runtime.tree.*; -import java.util.List; -import java.util.Iterator; -import java.util.ArrayList; - -@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) -public class IgniteSqlParser extends Parser { - static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); } - - protected static final DFA[] _decisionToDFA; - protected static final PredictionContextCache _sharedContextCache = - new PredictionContextCache(); - public static final int - SPACE=1, DROP=2, INDEX=3, IF=4, EXISTS=5, SEMI=6, DOT=7, ID=8, ID_LITERAL=9, - DQUOTE_STRING=10; - public static final int - RULE_root = 0, RULE_sqlStatements = 1, RULE_sqlStatement = 2, RULE_ddlStatement = 3, - RULE_dropIndex = 4, RULE_ifExists = 5, RULE_indexName = 6, RULE_indexNameWithSchema = 7, - RULE_emptyStatement = 8; - public static final String[] ruleNames = { - "root", "sqlStatements", "sqlStatement", "ddlStatement", "dropIndex", - "ifExists", "indexName", "indexNameWithSchema", "emptyStatement" - }; - - private static final String[] _LITERAL_NAMES = { - null, null, null, null, null, null, "';'", "'.'" - }; - private static final String[] _SYMBOLIC_NAMES = { - null, "SPACE", "DROP", "INDEX", "IF", "EXISTS", "SEMI", "DOT", "ID", "ID_LITERAL", - "DQUOTE_STRING" - }; - public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); - - /** - * @deprecated Use {@link #VOCABULARY} instead. - */ - @Deprecated - public static final String[] tokenNames; - static { - tokenNames = new String[_SYMBOLIC_NAMES.length]; - for (int i = 0; i < tokenNames.length; i++) { - tokenNames[i] = VOCABULARY.getLiteralName(i); - if (tokenNames[i] == null) { - tokenNames[i] = VOCABULARY.getSymbolicName(i); - } - - if (tokenNames[i] == null) { - tokenNames[i] = ""; - } - } - } - - @Override - @Deprecated - public String[] getTokenNames() { - return tokenNames; - } - - @Override - - public Vocabulary getVocabulary() { - return VOCABULARY; - } - - @Override - public String getGrammarFileName() { return "IgniteSqlParser.g4"; } - - @Override - public String[] getRuleNames() { return ruleNames; } - - @Override - public String getSerializedATN() { return _serializedATN; } - - @Override - public ATN getATN() { return _ATN; } - - public IgniteSqlParser(TokenStream input) { - super(input); - _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); - } - public static class RootContext extends ParserRuleContext { - public TerminalNode EOF() { return getToken(IgniteSqlParser.EOF, 0); } - public SqlStatementsContext sqlStatements() { - return getRuleContext(SqlStatementsContext.class,0); - } - public RootContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_root; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).enterRoot(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).exitRoot(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof IgniteSqlParserVisitor ) return ((IgniteSqlParserVisitor)visitor).visitRoot(this); - else return visitor.visitChildren(this); - } - } - - public final RootContext root() throws RecognitionException { - RootContext _localctx = new RootContext(_ctx, getState()); - enterRule(_localctx, 0, RULE_root); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(19); - _errHandler.sync(this); - _la = _input.LA(1); - if (_la==DROP || _la==SEMI) { - { - setState(18); - sqlStatements(); - } - } - - setState(21); - match(EOF); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class SqlStatementsContext extends ParserRuleContext { - public List sqlStatement() { - return getRuleContexts(SqlStatementContext.class); - } - public SqlStatementContext sqlStatement(int i) { - return getRuleContext(SqlStatementContext.class,i); - } - public List emptyStatement() { - return getRuleContexts(EmptyStatementContext.class); - } - public EmptyStatementContext emptyStatement(int i) { - return getRuleContext(EmptyStatementContext.class,i); - } - public List SEMI() { return getTokens(IgniteSqlParser.SEMI); } - public TerminalNode SEMI(int i) { - return getToken(IgniteSqlParser.SEMI, i); - } - public SqlStatementsContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_sqlStatements; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).enterSqlStatements(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).exitSqlStatements(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof IgniteSqlParserVisitor ) return ((IgniteSqlParserVisitor)visitor).visitSqlStatements(this); - else return visitor.visitChildren(this); - } - } - - public final SqlStatementsContext sqlStatements() throws RecognitionException { - SqlStatementsContext _localctx = new SqlStatementsContext(_ctx, getState()); - enterRule(_localctx, 2, RULE_sqlStatements); - int _la; - try { - int _alt; - enterOuterAlt(_localctx, 1); - { - setState(29); - _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,2,_ctx); - while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { - if ( _alt==1 ) { - { - setState(27); - _errHandler.sync(this); - switch (_input.LA(1)) { - case DROP: - { - setState(23); - sqlStatement(); - setState(24); - match(SEMI); - } - break; - case SEMI: - { - setState(26); - emptyStatement(); - } - break; - default: - throw new NoViableAltException(this); - } - } - } - setState(31); - _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,2,_ctx); - } - setState(37); - _errHandler.sync(this); - switch (_input.LA(1)) { - case DROP: - { - setState(32); - sqlStatement(); - setState(34); - _errHandler.sync(this); - _la = _input.LA(1); - if (_la==SEMI) { - { - setState(33); - match(SEMI); - } - } - - } - break; - case SEMI: - { - setState(36); - emptyStatement(); - } - break; - default: - throw new NoViableAltException(this); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class SqlStatementContext extends ParserRuleContext { - public DdlStatementContext ddlStatement() { - return getRuleContext(DdlStatementContext.class,0); - } - public SqlStatementContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_sqlStatement; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).enterSqlStatement(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).exitSqlStatement(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof IgniteSqlParserVisitor ) return ((IgniteSqlParserVisitor)visitor).visitSqlStatement(this); - else return visitor.visitChildren(this); - } - } - - public final SqlStatementContext sqlStatement() throws RecognitionException { - SqlStatementContext _localctx = new SqlStatementContext(_ctx, getState()); - enterRule(_localctx, 4, RULE_sqlStatement); - try { - enterOuterAlt(_localctx, 1); - { - setState(39); - ddlStatement(); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class DdlStatementContext extends ParserRuleContext { - public DropIndexContext dropIndex() { - return getRuleContext(DropIndexContext.class,0); - } - public DdlStatementContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_ddlStatement; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).enterDdlStatement(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).exitDdlStatement(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof IgniteSqlParserVisitor ) return ((IgniteSqlParserVisitor)visitor).visitDdlStatement(this); - else return visitor.visitChildren(this); - } - } - - public final DdlStatementContext ddlStatement() throws RecognitionException { - DdlStatementContext _localctx = new DdlStatementContext(_ctx, getState()); - enterRule(_localctx, 6, RULE_ddlStatement); - try { - enterOuterAlt(_localctx, 1); - { - setState(41); - dropIndex(); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class DropIndexContext extends ParserRuleContext { - public TerminalNode DROP() { return getToken(IgniteSqlParser.DROP, 0); } - public TerminalNode INDEX() { return getToken(IgniteSqlParser.INDEX, 0); } - public IndexNameContext indexName() { - return getRuleContext(IndexNameContext.class,0); - } - public IndexNameWithSchemaContext indexNameWithSchema() { - return getRuleContext(IndexNameWithSchemaContext.class,0); - } - public IfExistsContext ifExists() { - return getRuleContext(IfExistsContext.class,0); - } - public DropIndexContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_dropIndex; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).enterDropIndex(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).exitDropIndex(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof IgniteSqlParserVisitor ) return ((IgniteSqlParserVisitor)visitor).visitDropIndex(this); - else return visitor.visitChildren(this); - } - } - - public final DropIndexContext dropIndex() throws RecognitionException { - DropIndexContext _localctx = new DropIndexContext(_ctx, getState()); - enterRule(_localctx, 8, RULE_dropIndex); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(43); - match(DROP); - setState(44); - match(INDEX); - setState(46); - _errHandler.sync(this); - _la = _input.LA(1); - if (_la==IF) { - { - setState(45); - ifExists(); - } - } - - setState(50); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,6,_ctx) ) { - case 1: - { - setState(48); - indexName(); - } - break; - case 2: - { - setState(49); - indexNameWithSchema(); - } - break; - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class IfExistsContext extends ParserRuleContext { - public TerminalNode IF() { return getToken(IgniteSqlParser.IF, 0); } - public TerminalNode EXISTS() { return getToken(IgniteSqlParser.EXISTS, 0); } - public IfExistsContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_ifExists; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).enterIfExists(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).exitIfExists(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof IgniteSqlParserVisitor ) return ((IgniteSqlParserVisitor)visitor).visitIfExists(this); - else return visitor.visitChildren(this); - } - } - - public final IfExistsContext ifExists() throws RecognitionException { - IfExistsContext _localctx = new IfExistsContext(_ctx, getState()); - enterRule(_localctx, 10, RULE_ifExists); - try { - enterOuterAlt(_localctx, 1); - { - setState(52); - match(IF); - setState(53); - match(EXISTS); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class IndexNameContext extends ParserRuleContext { - public TerminalNode ID() { return getToken(IgniteSqlParser.ID, 0); } - public IndexNameContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_indexName; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).enterIndexName(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).exitIndexName(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof IgniteSqlParserVisitor ) return ((IgniteSqlParserVisitor)visitor).visitIndexName(this); - else return visitor.visitChildren(this); - } - } - - public final IndexNameContext indexName() throws RecognitionException { - IndexNameContext _localctx = new IndexNameContext(_ctx, getState()); - enterRule(_localctx, 12, RULE_indexName); - try { - enterOuterAlt(_localctx, 1); - { - setState(55); - match(ID); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class IndexNameWithSchemaContext extends ParserRuleContext { - public List ID() { return getTokens(IgniteSqlParser.ID); } - public TerminalNode ID(int i) { - return getToken(IgniteSqlParser.ID, i); - } - public TerminalNode DOT() { return getToken(IgniteSqlParser.DOT, 0); } - public IndexNameWithSchemaContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_indexNameWithSchema; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).enterIndexNameWithSchema(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).exitIndexNameWithSchema(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof IgniteSqlParserVisitor ) return ((IgniteSqlParserVisitor)visitor).visitIndexNameWithSchema(this); - else return visitor.visitChildren(this); - } - } - - public final IndexNameWithSchemaContext indexNameWithSchema() throws RecognitionException { - IndexNameWithSchemaContext _localctx = new IndexNameWithSchemaContext(_ctx, getState()); - enterRule(_localctx, 14, RULE_indexNameWithSchema); - try { - enterOuterAlt(_localctx, 1); - { - setState(57); - match(ID); - setState(58); - match(DOT); - setState(59); - match(ID); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class EmptyStatementContext extends ParserRuleContext { - public TerminalNode SEMI() { return getToken(IgniteSqlParser.SEMI, 0); } - public EmptyStatementContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_emptyStatement; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).enterEmptyStatement(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof IgniteSqlParserListener ) ((IgniteSqlParserListener)listener).exitEmptyStatement(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof IgniteSqlParserVisitor ) return ((IgniteSqlParserVisitor)visitor).visitEmptyStatement(this); - else return visitor.visitChildren(this); - } - } - - public final EmptyStatementContext emptyStatement() throws RecognitionException { - EmptyStatementContext _localctx = new EmptyStatementContext(_ctx, getState()); - enterRule(_localctx, 16, RULE_emptyStatement); - try { - enterOuterAlt(_localctx, 1); - { - setState(61); - match(SEMI); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static final String _serializedATN = - "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\fB\4\2\t\2\4\3\t"+ - "\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\3\2\5\2\26"+ - "\n\2\3\2\3\2\3\3\3\3\3\3\3\3\7\3\36\n\3\f\3\16\3!\13\3\3\3\3\3\5\3%\n"+ - "\3\3\3\5\3(\n\3\3\4\3\4\3\5\3\5\3\6\3\6\3\6\5\6\61\n\6\3\6\3\6\5\6\65"+ - "\n\6\3\7\3\7\3\7\3\b\3\b\3\t\3\t\3\t\3\t\3\n\3\n\3\n\2\2\13\2\4\6\b\n"+ - "\f\16\20\22\2\2\2?\2\25\3\2\2\2\4\37\3\2\2\2\6)\3\2\2\2\b+\3\2\2\2\n-"+ - "\3\2\2\2\f\66\3\2\2\2\169\3\2\2\2\20;\3\2\2\2\22?\3\2\2\2\24\26\5\4\3"+ - "\2\25\24\3\2\2\2\25\26\3\2\2\2\26\27\3\2\2\2\27\30\7\2\2\3\30\3\3\2\2"+ - "\2\31\32\5\6\4\2\32\33\7\b\2\2\33\36\3\2\2\2\34\36\5\22\n\2\35\31\3\2"+ - "\2\2\35\34\3\2\2\2\36!\3\2\2\2\37\35\3\2\2\2\37 \3\2\2\2 \'\3\2\2\2!\37"+ - "\3\2\2\2\"$\5\6\4\2#%\7\b\2\2$#\3\2\2\2$%\3\2\2\2%(\3\2\2\2&(\5\22\n\2"+ - "\'\"\3\2\2\2\'&\3\2\2\2(\5\3\2\2\2)*\5\b\5\2*\7\3\2\2\2+,\5\n\6\2,\t\3"+ - "\2\2\2-.\7\4\2\2.\60\7\5\2\2/\61\5\f\7\2\60/\3\2\2\2\60\61\3\2\2\2\61"+ - "\64\3\2\2\2\62\65\5\16\b\2\63\65\5\20\t\2\64\62\3\2\2\2\64\63\3\2\2\2"+ - "\65\13\3\2\2\2\66\67\7\6\2\2\678\7\7\2\28\r\3\2\2\29:\7\n\2\2:\17\3\2"+ - "\2\2;<\7\n\2\2<=\7\t\2\2=>\7\n\2\2>\21\3\2\2\2?@\7\b\2\2@\23\3\2\2\2\t"+ - "\25\35\37$\'\60\64"; - public static final ATN _ATN = - new ATNDeserializer().deserialize(_serializedATN.toCharArray()); - static { - _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; - for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { - _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); - } - } -} \ No newline at end of file diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserBaseListener.java b/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserBaseListener.java deleted file mode 100644 index 5ad23a1f2a..0000000000 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserBaseListener.java +++ /dev/null @@ -1,149 +0,0 @@ -// Generated from IgniteSqlParser.g4 by ANTLR 4.7 - -package org.apache.ignite.internal.parser; - - -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.tree.ErrorNode; -import org.antlr.v4.runtime.tree.TerminalNode; - -/** - * This class provides an empty implementation of {@link IgniteSqlParserListener}, - * which can be extended to create a listener which only needs to handle a subset - * of the available methods. - */ -public class IgniteSqlParserBaseListener implements IgniteSqlParserListener { - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterRoot(IgniteSqlParser.RootContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitRoot(IgniteSqlParser.RootContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterSqlStatements(IgniteSqlParser.SqlStatementsContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitSqlStatements(IgniteSqlParser.SqlStatementsContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterSqlStatement(IgniteSqlParser.SqlStatementContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitSqlStatement(IgniteSqlParser.SqlStatementContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterDdlStatement(IgniteSqlParser.DdlStatementContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitDdlStatement(IgniteSqlParser.DdlStatementContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterDropIndex(IgniteSqlParser.DropIndexContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitDropIndex(IgniteSqlParser.DropIndexContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterIfExists(IgniteSqlParser.IfExistsContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitIfExists(IgniteSqlParser.IfExistsContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterIndexName(IgniteSqlParser.IndexNameContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitIndexName(IgniteSqlParser.IndexNameContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterIndexNameWithSchema(IgniteSqlParser.IndexNameWithSchemaContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitIndexNameWithSchema(IgniteSqlParser.IndexNameWithSchemaContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterEmptyStatement(IgniteSqlParser.EmptyStatementContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitEmptyStatement(IgniteSqlParser.EmptyStatementContext ctx) { } - - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterEveryRule(ParserRuleContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitEveryRule(ParserRuleContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void visitTerminal(TerminalNode node) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void visitErrorNode(ErrorNode node) { } -} \ No newline at end of file diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserBaseVisitor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserBaseVisitor.java deleted file mode 100644 index 163f113484..0000000000 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserBaseVisitor.java +++ /dev/null @@ -1,79 +0,0 @@ -// Generated from IgniteSqlParser.g4 by ANTLR 4.7 - -package org.apache.ignite.internal.parser; - -import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; - -/** - * This class provides an empty implementation of {@link IgniteSqlParserVisitor}, - * which can be extended to create a visitor which only needs to handle a subset - * of the available methods. - * - * @param The return type of the visit operation. Use {@link Void} for - * operations with no return type. - */ -public class IgniteSqlParserBaseVisitor extends AbstractParseTreeVisitor implements IgniteSqlParserVisitor { - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitRoot(IgniteSqlParser.RootContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitSqlStatements(IgniteSqlParser.SqlStatementsContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitSqlStatement(IgniteSqlParser.SqlStatementContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitDdlStatement(IgniteSqlParser.DdlStatementContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitDropIndex(IgniteSqlParser.DropIndexContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitIfExists(IgniteSqlParser.IfExistsContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitIndexName(IgniteSqlParser.IndexNameContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitIndexNameWithSchema(IgniteSqlParser.IndexNameWithSchemaContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitEmptyStatement(IgniteSqlParser.EmptyStatementContext ctx) { return visitChildren(ctx); } -} \ No newline at end of file diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserListener.java b/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserListener.java deleted file mode 100644 index 0b27175378..0000000000 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserListener.java +++ /dev/null @@ -1,102 +0,0 @@ -// Generated from IgniteSqlParser.g4 by ANTLR 4.7 - -package org.apache.ignite.internal.parser; - -import org.antlr.v4.runtime.tree.ParseTreeListener; - -/** - * This interface defines a complete listener for a parse tree produced by - * {@link IgniteSqlParser}. - */ -public interface IgniteSqlParserListener extends ParseTreeListener { - /** - * Enter a parse tree produced by {@link IgniteSqlParser#root}. - * @param ctx the parse tree - */ - void enterRoot(IgniteSqlParser.RootContext ctx); - /** - * Exit a parse tree produced by {@link IgniteSqlParser#root}. - * @param ctx the parse tree - */ - void exitRoot(IgniteSqlParser.RootContext ctx); - /** - * Enter a parse tree produced by {@link IgniteSqlParser#sqlStatements}. - * @param ctx the parse tree - */ - void enterSqlStatements(IgniteSqlParser.SqlStatementsContext ctx); - /** - * Exit a parse tree produced by {@link IgniteSqlParser#sqlStatements}. - * @param ctx the parse tree - */ - void exitSqlStatements(IgniteSqlParser.SqlStatementsContext ctx); - /** - * Enter a parse tree produced by {@link IgniteSqlParser#sqlStatement}. - * @param ctx the parse tree - */ - void enterSqlStatement(IgniteSqlParser.SqlStatementContext ctx); - /** - * Exit a parse tree produced by {@link IgniteSqlParser#sqlStatement}. - * @param ctx the parse tree - */ - void exitSqlStatement(IgniteSqlParser.SqlStatementContext ctx); - /** - * Enter a parse tree produced by {@link IgniteSqlParser#ddlStatement}. - * @param ctx the parse tree - */ - void enterDdlStatement(IgniteSqlParser.DdlStatementContext ctx); - /** - * Exit a parse tree produced by {@link IgniteSqlParser#ddlStatement}. - * @param ctx the parse tree - */ - void exitDdlStatement(IgniteSqlParser.DdlStatementContext ctx); - /** - * Enter a parse tree produced by {@link IgniteSqlParser#dropIndex}. - * @param ctx the parse tree - */ - void enterDropIndex(IgniteSqlParser.DropIndexContext ctx); - /** - * Exit a parse tree produced by {@link IgniteSqlParser#dropIndex}. - * @param ctx the parse tree - */ - void exitDropIndex(IgniteSqlParser.DropIndexContext ctx); - /** - * Enter a parse tree produced by {@link IgniteSqlParser#ifExists}. - * @param ctx the parse tree - */ - void enterIfExists(IgniteSqlParser.IfExistsContext ctx); - /** - * Exit a parse tree produced by {@link IgniteSqlParser#ifExists}. - * @param ctx the parse tree - */ - void exitIfExists(IgniteSqlParser.IfExistsContext ctx); - /** - * Enter a parse tree produced by {@link IgniteSqlParser#indexName}. - * @param ctx the parse tree - */ - void enterIndexName(IgniteSqlParser.IndexNameContext ctx); - /** - * Exit a parse tree produced by {@link IgniteSqlParser#indexName}. - * @param ctx the parse tree - */ - void exitIndexName(IgniteSqlParser.IndexNameContext ctx); - /** - * Enter a parse tree produced by {@link IgniteSqlParser#indexNameWithSchema}. - * @param ctx the parse tree - */ - void enterIndexNameWithSchema(IgniteSqlParser.IndexNameWithSchemaContext ctx); - /** - * Exit a parse tree produced by {@link IgniteSqlParser#indexNameWithSchema}. - * @param ctx the parse tree - */ - void exitIndexNameWithSchema(IgniteSqlParser.IndexNameWithSchemaContext ctx); - /** - * Enter a parse tree produced by {@link IgniteSqlParser#emptyStatement}. - * @param ctx the parse tree - */ - void enterEmptyStatement(IgniteSqlParser.EmptyStatementContext ctx); - /** - * Exit a parse tree produced by {@link IgniteSqlParser#emptyStatement}. - * @param ctx the parse tree - */ - void exitEmptyStatement(IgniteSqlParser.EmptyStatementContext ctx); -} \ No newline at end of file diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserVisitor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserVisitor.java deleted file mode 100644 index 15d9c81fb2..0000000000 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/parser/IgniteSqlParserVisitor.java +++ /dev/null @@ -1,69 +0,0 @@ -// Generated from IgniteSqlParser.g4 by ANTLR 4.7 - -package org.apache.ignite.internal.parser; - -import org.antlr.v4.runtime.tree.ParseTreeVisitor; - -/** - * This interface defines a complete generic visitor for a parse tree produced - * by {@link IgniteSqlParser}. - * - * @param The return type of the visit operation. Use {@link Void} for - * operations with no return type. - */ -public interface IgniteSqlParserVisitor extends ParseTreeVisitor { - /** - * Visit a parse tree produced by {@link IgniteSqlParser#root}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitRoot(IgniteSqlParser.RootContext ctx); - /** - * Visit a parse tree produced by {@link IgniteSqlParser#sqlStatements}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitSqlStatements(IgniteSqlParser.SqlStatementsContext ctx); - /** - * Visit a parse tree produced by {@link IgniteSqlParser#sqlStatement}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitSqlStatement(IgniteSqlParser.SqlStatementContext ctx); - /** - * Visit a parse tree produced by {@link IgniteSqlParser#ddlStatement}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitDdlStatement(IgniteSqlParser.DdlStatementContext ctx); - /** - * Visit a parse tree produced by {@link IgniteSqlParser#dropIndex}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitDropIndex(IgniteSqlParser.DropIndexContext ctx); - /** - * Visit a parse tree produced by {@link IgniteSqlParser#ifExists}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitIfExists(IgniteSqlParser.IfExistsContext ctx); - /** - * Visit a parse tree produced by {@link IgniteSqlParser#indexName}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitIndexName(IgniteSqlParser.IndexNameContext ctx); - /** - * Visit a parse tree produced by {@link IgniteSqlParser#indexNameWithSchema}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitIndexNameWithSchema(IgniteSqlParser.IndexNameWithSchemaContext ctx); - /** - * Visit a parse tree produced by {@link IgniteSqlParser#emptyStatement}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitEmptyStatement(IgniteSqlParser.EmptyStatementContext ctx); -} \ No newline at end of file diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index eed1f195a8..02c0cc2614 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -107,8 +107,10 @@ import org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryContext; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row; import org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table; +import org.apache.ignite.internal.processors.query.h2.parser.GridExperimentalSqlParser; import org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser; import org.apache.ignite.internal.processors.query.h2.sql.GridSqlQuerySplitter; +import org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement; import org.apache.ignite.internal.processors.query.h2.twostep.GridMapQueryExecutor; import org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor; import org.apache.ignite.internal.processors.query.h2.twostep.MapQueryLazyWorker; @@ -1350,6 +1352,14 @@ public class IgniteH2Indexing implements GridQueryIndexing { boolean cachesCreated = false; try { + if (tryExperimentalParser(res, remainingSql)) { + remainingSql = null; + + GridH2QueryContext.clearThreadLocal(); + + continue; + } + try { while (true) { try { @@ -1455,7 +1465,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { if (DdlStatementsProcessor.isDdlStatement(prepared)) { try { - res.add(ddlProc.runDdlStatement(sqlQry, prepared)); + res.add(ddlProc.runDdlStatement(sqlQry, prepared, null)); continue; } @@ -1504,6 +1514,41 @@ public class IgniteH2Indexing implements GridQueryIndexing { } /** + * Try to use experimental parser to parse certain commands. + * + * @param res Results. + * @param sql SQL text. + * @return {@code true} on success. + */ + private boolean tryExperimentalParser(List>> res, String sql) { + String low = sql.substring(0, Math.min(12, sql.length())).toLowerCase(); + + if (!(low.contains("drop") && low.contains("index"))) + return false; + + GridExperimentalSqlParser parser = new GridExperimentalSqlParser(sql); + + try { + List stmts = parser.parse(); + + for (GridSqlStatement s: stmts) { + res.add(ddlProc.runDdlStatement(s.getSQL(), null, s)); + } + + return true; + } + catch (IgniteSQLException e) { + // Just ignore for now + + log.error("Experimental parser error: " + e.getMessage()); + return false; + } + catch (IgniteCheckedException e) { + throw new IgniteSQLException("Failed to execute DDL statement [stmt=" + sql + ']', e); + } + } + + /** * Check expected statement type (when it is set by JDBC) and given statement type. * * @param qry Query. diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java index f39e587177..f5c5359d73 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java @@ -60,6 +60,7 @@ import org.h2.command.ddl.DropIndex; import org.h2.command.ddl.DropTable; import org.h2.table.Column; import org.h2.value.DataType; +import org.jetbrains.annotations.Nullable; import static org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.UPDATE_RESULT_META; import static org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser.PARAM_WRAP_VALUE; @@ -91,17 +92,19 @@ public class DdlStatementsProcessor { * * @param sql SQL. * @param prepared Prepared. + * @param readyMadeStmt Ready-made statement. * @return Cursor on query results. * @throws IgniteCheckedException On error. */ @SuppressWarnings({"unchecked", "ThrowableResultOfMethodCallIgnored"}) - public FieldsQueryCursor> runDdlStatement(String sql, Prepared prepared) + public FieldsQueryCursor> runDdlStatement(String sql, Prepared prepared, GridSqlStatement readyMadeStmt) throws IgniteCheckedException { IgniteInternalFuture fut = null; try { - GridSqlStatement stmt0 = new GridSqlQueryParser(false).parse(prepared); + GridSqlStatement stmt0 = (readyMadeStmt == null) ? + new GridSqlQueryParser(false).parse(prepared) : readyMadeStmt; if (stmt0 instanceof GridSqlCreateIndex) { GridSqlCreateIndex cmd = (GridSqlCreateIndex)stmt0; diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridExperimentalSqlParser.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridExperimentalSqlParser.java new file mode 100644 index 0000000000..099b2464f8 --- /dev/null +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridExperimentalSqlParser.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.query.h2.parser; + +import java.util.List; +import org.antlr.v4.runtime.BailErrorStrategy; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.TokenStream; +import org.antlr.v4.runtime.atn.PredictionMode; +import org.antlr.v4.runtime.misc.ParseCancellationException; +import org.apache.ignite.Ignite; +import org.apache.ignite.internal.parser.IgniteSqlLexer; +import org.apache.ignite.internal.parser.IgniteSqlParser; +import org.apache.ignite.internal.parser.GridExperimentalSqlParserListener; +import org.apache.ignite.internal.processors.query.IgniteSQLException; +import org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement; + +/** + * Use 'mvn generate-sources' to regenerate IgniteSqlLexer and IgniteSqlParser classes + * The resulting files will be put to moudules\indexing\target\generated-sources. + * + * Don't forget to mark the above directory as "Generated Sources Root" in IDEA. + */ +public class GridExperimentalSqlParser { + /** */ + String input; + + /** */ + IgniteSqlLexer lexer; + + /** */ + IgniteSqlParser parser; + + /** */ + GridExperimentalSqlParserListener listener; + + /** + * Constructor. + * + * @param input SQL text. + */ + public GridExperimentalSqlParser(String input) { + this.input = input; + + lexer = new IgniteSqlLexer(CharStreams.fromString(input)); + + lexer.removeErrorListeners(); + + lexer.addErrorListener(GridExperimentalSqlParserErrorListener.INSTANCE); + + TokenStream tokenStream = new CommonTokenStream(lexer); + + parser = new IgniteSqlParser(tokenStream); + + parser.removeErrorListeners(); + + parser.addErrorListener(GridExperimentalSqlParserErrorListener.INSTANCE); + + parser.setErrorHandler(new BailErrorStrategy()); + + listener = new GridExperimentalSqlParserListener(); + + parser.addParseListener(listener); + } + + /** + * @return List of SQL statements. + */ + public List parse() { + try { + // Two stage parsing: SLL fail-over to LL. + try { + parser.getInterpreter().setPredictionMode(PredictionMode.SLL); + + parser.root(); + } + catch (Exception e) { + lexer.reset(); + + parser.reset(); + + parser.getInterpreter().setPredictionMode(PredictionMode.LL); + + parser.root(); + } + } + catch (ParseCancellationException e) { + if (e.getCause() instanceof GridExperimentalSqlParserException) { + GridExperimentalSqlParserException ex = (GridExperimentalSqlParserException)e.getCause(); + + throw new IgniteSQLException(formatParserError(input, ex.getMessage(), ex.getLine(), ex.getPosition()), + ex.getCause()); + } + + throw new IgniteSQLException("Unknown experimental parser error", e); + } + + return listener.getStatements(); + } + + /** + * Formats error message. + * + * @param inputText Input SQL text. + * @param errorMessage Error message. + * @param line Line where error has occurred. + * @param position Position in line where error has occurred. + * @return Formatted error message. + */ + private static String formatParserError(String inputText, String errorMessage, int line, int position) { + String err = "SyntaxError: line " + line + ": position " + position + ": " + errorMessage + ": "; + + StringBuilder sb = new StringBuilder(err); + + String lines[] = inputText.split("\n\r"); + + for (int i = 0; i < lines.length; ++i) { + if (i + 1 == line) { + String l = lines[i]; + sb.append(l.substring(0, position)); + sb.append("[*]"); + sb.append(l.substring(position, l.length())); + } + else { + sb.append(lines[i] + "\n"); + } + } + + return sb.toString(); + } +} diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridExperimentalSqlParserErrorListener.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridExperimentalSqlParserErrorListener.java new file mode 100644 index 0000000000..3e2034c5a0 --- /dev/null +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridExperimentalSqlParserErrorListener.java @@ -0,0 +1,27 @@ +package org.apache.ignite.internal.processors.query.h2.parser; + +import org.antlr.v4.runtime.BaseErrorListener; +import org.antlr.v4.runtime.RecognitionException; +import org.antlr.v4.runtime.Recognizer; +import org.antlr.v4.runtime.atn.ParserATNSimulator; +import org.antlr.v4.runtime.atn.PredictionMode; +import org.antlr.v4.runtime.misc.ParseCancellationException; + +/** Error listener */ +public class GridExperimentalSqlParserErrorListener extends BaseErrorListener { + public static final GridExperimentalSqlParserErrorListener INSTANCE = new GridExperimentalSqlParserErrorListener(); + + /** {@inheritDoc} */ + @Override public void syntaxError(Recognizer recognizer, Object offendingSymbol, int line, + int charPositionInLine, String msg, RecognitionException e) { + + //Skip errors in SLL mode. + if ((recognizer.getInterpreter() instanceof ParserATNSimulator) && + ((ParserATNSimulator)recognizer.getInterpreter()).getPredictionMode() == PredictionMode.SLL) + return; + + throw new ParseCancellationException(msg, + new GridExperimentalSqlParserException(msg, line, charPositionInLine, e)); + } + +} diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridExperimentalSqlParserException.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridExperimentalSqlParserException.java new file mode 100644 index 0000000000..2fbbc81f51 --- /dev/null +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/parser/GridExperimentalSqlParserException.java @@ -0,0 +1,41 @@ +package org.apache.ignite.internal.processors.query.h2.parser; + +import org.apache.ignite.IgniteException; + +/** */ +public class GridExperimentalSqlParserException extends IgniteException { + /** Error line. */ + private int line; + + /** Error position on line. */ + private int pos; + + /** + * Constructor. + * + * @param msg Error message. + * @param line Line number where error has occurred. + * @param pos Position on line where error has occurred. + * @param cause Cause. + */ + public GridExperimentalSqlParserException(String msg, int line, int pos, Exception cause) { + super(msg, cause); + + this.line = line; + this.pos = pos; + } + + /** + * @return Line number where error occurred. + */ + public int getLine() { + return line; + } + + /** + * @return Position of error on line. + */ + public int getPosition() { + return pos; + } +} diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/parser/IgniteExperimentalSqlParserIntegrationSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/parser/IgniteExperimentalSqlParserIntegrationSelfTest.java new file mode 100644 index 0000000000..1eab68defe --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/parser/IgniteExperimentalSqlParserIntegrationSelfTest.java @@ -0,0 +1,97 @@ +package org.apache.ignite.internal.parser; + +import java.util.ArrayList; +import java.util.List; +import org.apache.ignite.cache.CacheKeyConfiguration; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.binary.BinaryMarshaller; +import org.apache.ignite.internal.processors.query.GridQueryProcessor; +import org.apache.ignite.internal.processors.query.IgniteSqlRoutingTest; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * Tests for experimental parser generated by ANTLR4. + */ +public class IgniteExperimentalSqlParserIntegrationSelfTest extends GridCommonAbstractTest { + /** IP finder. */ + private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static String NODE_CLIENT = "client"; + + /** */ + private static int NODE_COUNT = 4; + + private IgniteEx client; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration c = super.getConfiguration(gridName); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(IP_FINDER); + + c.setDiscoverySpi(disco); + + List ccfgs = new ArrayList<>(); + + //CacheConfiguration ccfg = buildCacheConfiguration(gridName); + + //if (ccfg != null) +// ccfgs.add(ccfg); + + //ccfgs.add(buildCacheConfiguration(CACHE_PERSON)); + //ccfgs.add(buildCacheConfiguration(CACHE_CALL)); + + //c.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()])); + + if (gridName.equals(NODE_CLIENT)) + c.setClientMode(true); + + //c.setCacheKeyConfiguration(new CacheKeyConfiguration(IgniteSqlRoutingTest.CallKey.class)); + + return c; + } + + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + startGrids(NODE_COUNT); + + client = (IgniteEx)startGrid(NODE_CLIENT); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + super.afterTestsStopped(); + + stopAllGrids(); + } + + /** + * @throws Exception if failed. + */ + public void testDropIndexExperimental() throws Exception { + GridQueryProcessor queryProc = client.context().query(); + + queryProc.querySqlFieldsNoCache( + new SqlFieldsQuery("CREATE TABLE test(id INT PRIMARY KEY, name CHAR)"), false); + + queryProc.querySqlFieldsNoCache( + new SqlFieldsQuery("CREATE INDEX \"testIndex\" ON test(name)"), false); + + queryProc.querySqlFieldsNoCache( + new SqlFieldsQuery("DROP INDEX \"PUBLIC\".\"testIndex\""), false); + + queryProc.querySqlFieldsNoCache( + new SqlFieldsQuery("CREATE INDEX \"testIndex\" ON test(name)"), false); + } +} diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/parser/IgniteExperimentalSqlParserSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/parser/IgniteExperimentalSqlParserSelfTest.java new file mode 100644 index 0000000000..24a14f4df5 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/parser/IgniteExperimentalSqlParserSelfTest.java @@ -0,0 +1,183 @@ +package org.apache.ignite.internal.parser; + +import java.util.List; +import java.util.concurrent.Callable; +import org.apache.ignite.internal.processors.query.IgniteSQLException; +import org.apache.ignite.internal.processors.query.h2.parser.GridExperimentalSqlParser; +import org.apache.ignite.internal.processors.query.h2.sql.GridSqlDropIndex; +import org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * Tests for experimental parser generated by ANTLR4. + */ +public class IgniteExperimentalSqlParserSelfTest extends GridCommonAbstractTest { + /** + * @throws Exception if failed. + */ + public void testParseDropIndexName() throws Exception { + GridSqlDropIndex cmd = parseSingle("DROP index indexName", GridSqlDropIndex.class); + + assertFalse(cmd.ifExists()); + assertEquals("indexName", cmd.indexName()); + assertEquals("public", cmd.schemaName()); + } + + /** + * @throws Exception if failed. + */ + public void testParseDropIndexSchemaIndexName() throws Exception { + GridSqlDropIndex cmd = parseSingle("DROP index schemaName.indexName", GridSqlDropIndex.class); + + assertFalse(cmd.ifExists()); + assertEquals("indexName", cmd.indexName()); + assertEquals("schemaName", cmd.schemaName()); + } + + /** + * @throws Exception if failed. + */ + public void testParseDropIndexIfExists() throws Exception { + GridSqlDropIndex cmd = parseSingle("DROP index IF exists indexName", GridSqlDropIndex.class); + + assertTrue(cmd.ifExists()); + assertEquals("indexName", cmd.indexName()); + assertEquals("public", cmd.schemaName()); + } + + /** + * @throws Exception if failed. + */ + public void testParseDropIndexQuotedSchemaName() throws Exception { + GridSqlDropIndex cmd = parseSingle("DROP index \"schemaName\".indexName", GridSqlDropIndex.class); + + assertFalse(cmd.ifExists()); + assertEquals("indexName", cmd.indexName()); + assertEquals("schemaName", cmd.schemaName()); + } + + /** + * @throws Exception if failed. + */ + public void testParseDropIndexQuoted() throws Exception { + GridSqlDropIndex cmd = parseSingle("DROP index \"schemaName\".\"indexName\"", GridSqlDropIndex.class); + + assertFalse(cmd.ifExists()); + assertEquals("indexName", cmd.indexName()); + assertEquals("schemaName", cmd.schemaName()); + } + + /** + * @throws Exception if failed. + */ + public void testParseMultipleDropIndex() throws Exception { + List res = parseMultiple("drop index if exists indexName1; drop index schemaName.indexName2"); + + assertNotNull(res); + + assertEquals(2, res.size()); + + GridSqlDropIndex cmd = (GridSqlDropIndex)res.get(0); + + assertTrue(cmd.ifExists()); + assertEquals("indexName1", cmd.indexName()); + assertEquals("public", cmd.schemaName()); + + cmd = (GridSqlDropIndex)res.get(1); + + assertFalse(cmd.ifExists()); + assertEquals("indexName2", cmd.indexName()); + assertEquals("schemaName", cmd.schemaName()); + } + + /** + * @throws Exception if failed. + */ + public void testParseErrorUnsupported() throws Exception { + GridTestUtils.assertThrows(log, new Callable() { + @Override public Object call() throws Exception { + return parseSingle("DROP TABLE tableName", GridSqlStatement.class); + } + }, IgniteSQLException.class, + "SyntaxError: line 1: position 5: no viable alternative at input 'DROP TABLE': DROP [*]TABLE tableName"); + } + + /** + * @throws Exception if failed. + */ + public void testParseErrorUnexpectedToken() throws Exception { + GridTestUtils.assertThrows(log, new Callable() { + @Override public Object call() throws Exception { + return parseSingle("DROP INDEX DROP", GridSqlStatement.class); + } + }, IgniteSQLException.class, + "SyntaxError: line 1: position 11: no viable alternative at input 'DROP INDEX DROP': DROP INDEX [*]DROP"); + } + + /** + * @throws Exception if failed. + */ + public void testParseErrorFromLexer() throws Exception { + GridTestUtils.assertThrows(log, new Callable() { + @Override public Object call() throws Exception { + return parseSingle("DROP INDEX -1234", GridSqlStatement.class); + } + }, IgniteSQLException.class, + "SyntaxError: line 1: position 11: token recognition error at: '-': DROP INDEX [*]-1234"); + } + + /** + * ANTLR Bug reproducer. + * + * @throws Exception if failed. + */ + public void testParseErrorInAntlr() throws Exception { + GridTestUtils.assertThrows(log, new Callable() { + @Override public Object call() throws Exception { + return parseSingle("DROP INDEX \"schemaName\".\"indexName ", GridSqlStatement.class); + } + }, IgniteSQLException.class, ""); + } + + /** + * Parse SQL expecting single statement of certain class. + * + * @param text SQL text. + * @param expClass class of result to expect. + * @param class of result to expect. + * @return SQL statement. + */ + private T parseSingle(String text, Class expClass) { + List result = new GridExperimentalSqlParser(text).parse(); + + assertNotNull(result); + + assertEquals(1, result.size()); + + assertTrue(expClass.isInstance(result.get(0))); + + return (T)result.get(0); + } + + /** + * Parse text expecting multiple statements. + * + * @param text SQL text. + * @return List of SQL statements. + */ + private List parseMultiple(String text) { + List result = new GridExperimentalSqlParser(text).parse(); + + assertNotNull(result); + + assertFalse(F.isEmpty(result)); + + return result; + } + + + + +} -- 2.11.0.windows.3