You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ch...@apache.org on 2019/07/08 20:23:50 UTC
[phoenix] branch master updated: PHOENIX-5386: Disallow creating
views on top of SYSTEM tables
This is an automated email from the ASF dual-hosted git repository.
chinmayskulkarni pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push:
new 5425298 PHOENIX-5386: Disallow creating views on top of SYSTEM tables
5425298 is described below
commit 5425298e66e231bed55b700c4e5724c330944a6d
Author: Chinmay Kulkarni <ch...@gmail.com>
AuthorDate: Sat Jul 6 01:00:36 2019 -0700
PHOENIX-5386: Disallow creating views on top of SYSTEM tables
---
.../it/java/org/apache/phoenix/end2end/ViewIT.java | 20 +++++++++++++++++---
.../apache/phoenix/compile/CreateTableCompiler.java | 6 ++++++
.../apache/phoenix/exception/SQLExceptionCode.java | 3 +++
3 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
index b9ef3ac..a65440b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
@@ -55,10 +55,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.curator.shaded.com.google.common.collect.Lists;
import org.apache.hadoop.hbase.DoNotRetryIOException;
-import org.apache.hadoop.hbase.HBaseTestingUtility;
-import org.apache.hadoop.hbase.MiniHBaseCluster;
import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import org.apache.hadoop.hbase.util.Pair;
@@ -68,6 +65,7 @@ import org.apache.phoenix.coprocessor.MetaDataEndpointObserver;
import org.apache.phoenix.coprocessor.PhoenixMetaDataCoprocessorHost;
import org.apache.phoenix.coprocessor.PhoenixMetaDataCoprocessorHost.PhoenixMetaDataControllerEnvironment;
import org.apache.phoenix.exception.PhoenixIOException;
+import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.query.KeyRange;
import org.apache.phoenix.query.QueryServices;
@@ -969,6 +967,22 @@ public class ViewIT extends SplitSystemCatalogIT {
}
}
+ @Test
+ public void testDisallowCreatingViewsOnSystemTable() throws SQLException {
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ String viewDDL = "CREATE VIEW " + generateUniqueName() + " AS SELECT * FROM " +
+ "SYSTEM.CATALOG";
+ try {
+ conn.createStatement().execute(viewDDL);
+ fail("Should have thrown an exception");
+ } catch (SQLException sqlE) {
+ assertEquals("Expected a different Error code",
+ SQLExceptionCode.CANNOT_CREATE_VIEWS_ON_SYSTEM_TABLES.getErrorCode(),
+ sqlE.getErrorCode());
+ }
+ }
+ }
+
private class CreateViewRunnable implements Callable<Exception> {
private final String fullTableName;
private final String fullViewName;
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
index 6329467..776859e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
@@ -125,6 +125,12 @@ public class CreateTableCompiler {
// Used to track column references in a view
ExpressionCompiler expressionCompiler = new ColumnTrackingExpressionCompiler(context, isViewColumnReferencedToBe);
parentToBe = tableRef.getTable();
+ // Disallow creating views on top of SYSTEM tables. See PHOENIX-5386
+ if (parentToBe.getType() == PTableType.SYSTEM) {
+ throw new SQLExceptionInfo
+ .Builder(SQLExceptionCode.CANNOT_CREATE_VIEWS_ON_SYSTEM_TABLES)
+ .build().buildException();
+ }
viewTypeToBe = parentToBe.getViewType() == ViewType.MAPPED ? ViewType.MAPPED : ViewType.UPDATABLE;
if (whereNode == null) {
viewStatementToBe = parentToBe.getViewStatement();
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index b773649..fa9625c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -35,6 +35,7 @@ import org.apache.phoenix.schema.ConcurrentTableMutationException;
import org.apache.phoenix.schema.FunctionAlreadyExistsException;
import org.apache.phoenix.schema.FunctionNotFoundException;
import org.apache.phoenix.schema.IndexNotFoundException;
+import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.ReadOnlyTableException;
import org.apache.phoenix.schema.SchemaAlreadyExistsException;
import org.apache.phoenix.schema.SchemaNotFoundException;
@@ -406,6 +407,8 @@ public enum SQLExceptionCode {
INVALID_IMMUTABLE_STORAGE_SCHEME_AND_COLUMN_QUALIFIER_BYTES(1137, "XCL37", "If IMMUTABLE_STORAGE_SCHEME property is not set to ONE_CELL_PER_COLUMN COLUMN_ENCODED_BYTES cannot be 0"),
INVALID_IMMUTABLE_STORAGE_SCHEME_CHANGE(1138, "XCL38", "IMMUTABLE_STORAGE_SCHEME property cannot be changed from/to ONE_CELL_PER_COLUMN "),
CANNOT_SET_GUIDE_POST_WIDTH(1139, "XCL39", "Guide post width can only be set on base data tables"),
+ CANNOT_CREATE_VIEWS_ON_SYSTEM_TABLES(1141, "XCL41", "Cannot create views on tables of type" +
+ PTableType.SYSTEM),
/**
* Implementation defined class. Phoenix internal error. (errorcode 20, sqlstate INT).
*/