phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdsi...@apache.org
Subject phoenix git commit: PHOENIX-3460 Namespace separator : should not be allowed in table or schema name
Date Thu, 02 Nov 2017 21:29:19 GMT
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 51a34bb89 -> d36558f4a


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/d36558f4
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/d36558f4
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/d36558f4

Branch: refs/heads/5.x-HBase-2.0
Commit: d36558f4ad7be955f307eec02c59cd989ea138bb
Parents: 51a34bb
Author: Thomas D'Silva <tdsilva@apache.org>
Authored: Thu Nov 2 12:08:07 2017 -0700
Committer: Thomas D'Silva <tdsilva@apache.org>
Committed: Thu Nov 2 14:15:56 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/d36558f4/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 721b514..93e0ede 100644
--- a/phoenix-core/src/main/antlr3/PhoenixSQL.g
+++ b/phoenix-core/src/main/antlr3/PhoenixSQL.g
@@ -1071,14 +1071,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/d36558f4/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)");
+    }
 }


Mime
View raw message