You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by td...@apache.org on 2017/11/02 21:29:09 UTC

phoenix git commit: PHOENIX-3460 Namespace separator : should not be allowed in table or schema name

Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 6e80b0fb0 -> 52c57b1d5


PHOENIX-3460 Namespace separator : should not be allowed in table or schema name


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 52c57b1d55f2cd3890056b5ea587257660bcbb47
Parents: 6e80b0f
Author: Thomas D'Silva <td...@apache.org>
Authored: Thu Nov 2 12:08:07 2017 -0700
Committer: Thomas D'Silva <td...@apache.org>
Committed: Thu Nov 2 14:15:08 2017 -0700

----------------------------------------------------------------------
 phoenix-core/src/main/antlr3/PhoenixSQL.g       | 15 ++++++++++----
 .../apache/phoenix/parse/QueryParserTest.java   | 21 ++++++++++++++++++++
 2 files changed, 32 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/52c57b1d/phoenix-core/src/main/antlr3/PhoenixSQL.g
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/antlr3/PhoenixSQL.g b/phoenix-core/src/main/antlr3/PhoenixSQL.g
index ed5e154..45acb88 100644
--- a/phoenix-core/src/main/antlr3/PhoenixSQL.g
+++ b/phoenix-core/src/main/antlr3/PhoenixSQL.g
@@ -1063,14 +1063,21 @@ cursor_name returns [CursorName ret]
 
 // TODO: figure out how not repeat this two times
 table_name returns [TableName ret]
-    :   t=identifier {$ret = factory.table(null, t); }
-    |   s=identifier DOT t=identifier {$ret = factory.table(s, t); }
+    :   t=table_identifier {$ret = factory.table(null, t); }
+    |   s=table_identifier DOT t=table_identifier {$ret = factory.table(s, t); }
     ;
 
 // TODO: figure out how not repeat this two times
 from_table_name returns [TableName ret]
-    :   t=identifier {$ret = factory.table(null, t); }
-    |   s=identifier DOT t=identifier {$ret = factory.table(s, t); }
+    :   t=table_identifier {$ret = factory.table(null, t); }
+    |   s=table_identifier DOT t=table_identifier {$ret = factory.table(s, t); }
+    ;
+
+table_identifier returns [String ret]
+    :   c=identifier {
+           if (c.contains(QueryConstants.NAMESPACE_SEPARATOR) ) { throw new RuntimeException("Table or schema name cannot contain colon"); }
+           $ret = c;
+    }
     ;
     
 // The lowest level function, which includes literals, binds, but also parenthesized expressions, functions, and case statements.

http://git-wip-us.apache.org/repos/asf/phoenix/blob/52c57b1d/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java b/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java
index e7127b7..431f60b 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java
@@ -29,6 +29,7 @@ import java.sql.SQLFeatureNotSupportedException;
 import java.util.List;
 
 import org.apache.hadoop.hbase.util.Pair;
+import org.apache.phoenix.exception.PhoenixParserException;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixStatement.Operation;
 import org.apache.phoenix.schema.SortOrder;
@@ -56,6 +57,15 @@ public class QueryParserTest {
         assertEquals("Expected equality:\n" + sql + "\n" + newSQL, stmt, newStmt);
     }
     
+    private void parseQueryThatShouldFail(String sql) throws Exception {
+        try {
+            parseQuery(sql);
+            fail("Query should throw a PhoenixParserException \n " + sql);
+        }
+        catch (PhoenixParserException e){
+        }
+    }
+
     @Test
     public void testParsePreQuery0() throws Exception {
         String sql = ((
@@ -782,4 +792,15 @@ public class QueryParserTest {
         String sql = Joiner.on(unicodeEnSpace).join(new String[] {"SELECT", "*", "FROM", "T"});
         parseQuery(sql);
     }
+
+    @Test
+    public void testInvalidTableOrSchemaName() throws Exception {
+        // namespace separator (:) cannot be used
+        parseQueryThatShouldFail("create table a:b (id varchar not null primary key)");
+        parseQueryThatShouldFail("create table \"a:b\" (id varchar not null primary key)");
+        // name separator (.) cannot be used without double quotes
+        parseQueryThatShouldFail("create table a.b.c.d (id varchar not null primary key)");
+        parseQuery("create table \"a.b\".\"c.d\" (id varchar not null primary key)");
+        parseQuery("create table \"a.b.c.d\" (id varchar not null primary key)");
+    }
 }