ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [10/28] ignite git commit: IGNITE-6851: SQL: fixed CREATE INDEX parsing, so that index name is now optional.
Date Mon, 13 Nov 2017 09:52:04 GMT
IGNITE-6851: SQL: fixed CREATE INDEX parsing, so that index name is now optional.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a82ff061
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a82ff061
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a82ff061

Branch: refs/heads/ignite-zk
Commit: a82ff0610cd20a5f86ea3b9ef7545786df841691
Parents: 85cf958
Author: devozerov <vozerov@gridgain.com>
Authored: Fri Nov 10 10:58:42 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Fri Nov 10 10:58:42 2017 +0300

----------------------------------------------------------------------
 .../internal/sql/command/SqlCreateIndexCommand.java | 16 +++++++++++++++-
 .../internal/sql/SqlParserCreateIndexSelfTest.java  |  4 ++++
 2 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a82ff061/modules/core/src/main/java/org/apache/ignite/internal/sql/command/SqlCreateIndexCommand.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/sql/command/SqlCreateIndexCommand.java
b/modules/core/src/main/java/org/apache/ignite/internal/sql/command/SqlCreateIndexCommand.java
index 897aea5..ef89a5a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/sql/command/SqlCreateIndexCommand.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/sql/command/SqlCreateIndexCommand.java
@@ -23,6 +23,7 @@ import org.apache.ignite.internal.sql.SqlLexerToken;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.Collection;
 import java.util.Collections;
@@ -129,7 +130,7 @@ public class SqlCreateIndexCommand implements SqlCommand {
     @Override public SqlCommand parse(SqlLexer lex) {
         ifNotExists = parseIfNotExists(lex);
 
-        idxName = parseIdentifier(lex, IF);
+        idxName = parseIndexName(lex);
 
         skipIfMatchesKeyword(lex, ON);
 
@@ -143,6 +144,19 @@ public class SqlCreateIndexCommand implements SqlCommand {
         return this;
     }
 
+    /**
+     * Pasrse index name.
+     *
+     * @param lex Lexer.
+     * @return Index name.
+     */
+    private static @Nullable String parseIndexName(SqlLexer lex) {
+        if (matchesKeyword(lex.lookAhead(), ON))
+            return null;
+
+        return parseIdentifier(lex, IF);
+    }
+
     /*
      * @param lex Lexer.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/a82ff061/modules/core/src/test/java/org/apache/ignite/internal/sql/SqlParserCreateIndexSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/sql/SqlParserCreateIndexSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/sql/SqlParserCreateIndexSelfTest.java
index 5de0a3a..e7bc3e9 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/sql/SqlParserCreateIndexSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/sql/SqlParserCreateIndexSelfTest.java
@@ -90,6 +90,10 @@ public class SqlParserCreateIndexSelfTest extends SqlParserAbstractSelfTest
{
         parseValidate("schema", "CREATE INDEX idx ON tbl(a)", "schema", "TBL", "IDX", "A",
false);
         parseValidate("sChema", "CREATE INDEX idx ON tbl(a)", "sChema", "TBL", "IDX", "A",
false);
 
+        // No index name.
+        parseValidate(null, "CREATE INDEX ON tbl(a)", null, "TBL", null, "A", false);
+        parseValidate(null, "CREATE INDEX ON schema.tbl(a)", "SCHEMA", "TBL", null, "A",
false);
+
         // NOT EXISTS
         SqlCreateIndexCommand cmd;
 


Mime
View raw message