You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by vj...@apache.org on 2023/10/27 17:10:45 UTC
(phoenix) branch master updated: PHOENIX-7070 : Child View of ReadOnly View is marked as updatable View (#1723)
This is an automated email from the ASF dual-hosted git repository.
vjasani 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 0a3941f2a2 PHOENIX-7070 : Child View of ReadOnly View is marked as updatable View (#1723)
0a3941f2a2 is described below
commit 0a3941f2a2a5b4a328cb1d8b155d43b70bcfec85
Author: Divneet18 <di...@ucsd.edu>
AuthorDate: Fri Oct 27 10:10:39 2023 -0700
PHOENIX-7070 : Child View of ReadOnly View is marked as updatable View (#1723)
---
.../phoenix/end2end/ReadOnlyViewOnReadOnlyIT.java | 109 +++++++++++++++++++++
.../phoenix/compile/CreateTableCompiler.java | 5 +-
2 files changed, 113 insertions(+), 1 deletion(-)
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReadOnlyViewOnReadOnlyIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReadOnlyViewOnReadOnlyIT.java
new file mode 100644
index 0000000000..5825990a47
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ReadOnlyViewOnReadOnlyIT.java
@@ -0,0 +1,109 @@
+/*
+ * 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.phoenix.end2end;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.UPDATE_CACHE_FREQUENCY;
+import static org.junit.Assert.assertEquals;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(NeedsOwnMiniClusterTest.class)
+public class ReadOnlyViewOnReadOnlyIT extends BaseTenantSpecificViewIndexIT {
+ private static final long DEFAULT_TTL_FOR_TEST = 86400;
+ private Connection getTenantConnection(final String tenantId) throws Exception {
+ Properties tenantProps = new Properties();
+ tenantProps.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+ return DriverManager.getConnection(getUrl(), tenantProps);
+ }
+ @Test
+ public void testReadOnlyTenantViewOnReadOnly() throws Exception {
+
+ try(Connection connection = DriverManager.getConnection(getUrl())) {
+ PhoenixConnection conn = connection.unwrap(PhoenixConnection.class);
+ //base table
+ String tableName = generateUniqueName();
+ conn.createStatement().execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ + " ID INTEGER NOT NULL,"
+ + " COL1 INTEGER NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CREATED_DATE DATE,"
+ + " CREATION_TIME BIGINT,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (ID, COL1, COL2))"
+ + " TTL = " + DEFAULT_TTL_FOR_TEST
+ + "," + UPDATE_CACHE_FREQUENCY + " = 100000000"
+ + ", MULTI_TENANT = true");
+
+ //global parent view
+ String viewName = "VIEW_" + tableName + "_" + generateUniqueName();
+ conn.createStatement().execute("CREATE VIEW " + viewName
+ + " (" + generateUniqueName() + " SMALLINT) as select * from "
+ + tableName + " where id > 1 "
+ + (false ? "TTL = 1000" : ""));
+
+ //tenant child view
+ String TENANT_ID = generateUniqueName();
+ try (Connection tenantConn = getTenantConnection(TENANT_ID)) {
+ final Statement tenantStmt = tenantConn.createStatement();
+ tenantStmt.execute("CREATE VIEW " + "TENANT_VIEW_" + viewName + " AS SELECT * FROM " + viewName);
+
+ assertEquals(PTable.ViewType.READ_ONLY, PhoenixRuntime.getTable(conn, viewName).getViewType());
+ assertEquals(PTable.ViewType.READ_ONLY, PhoenixRuntime.getTable(tenantConn, "TENANT_VIEW_" + viewName).getViewType());
+ }
+ }
+ }
+
+ @Test
+ public void testReadOnlyViewOnReadOnly() throws Exception {
+ try(Connection connection = DriverManager.getConnection(getUrl())) {
+ PhoenixConnection conn = connection.unwrap(PhoenixConnection.class);
+ //base table
+ String tableName = generateUniqueName();
+ conn.createStatement().execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ + " ID INTEGER NOT NULL,"
+ + " COL1 INTEGER NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CREATED_DATE DATE,"
+ + " CREATION_TIME BIGINT,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (ID, COL1, COL2))"
+ + " TTL = " + DEFAULT_TTL_FOR_TEST + "," + UPDATE_CACHE_FREQUENCY + " = 100000000");
+
+ //global parent view
+ String viewName = "VIEW_" + tableName + "_" + generateUniqueName();
+ conn.createStatement().execute("CREATE VIEW " + viewName
+ + " (" + generateUniqueName() + " SMALLINT) as select * from "
+ + tableName + " where id > 1 "
+ + (false ? "TTL = 1000" : ""));
+
+ //global child view
+ String childView = "VIEW_" + viewName + "_" + generateUniqueName();
+ conn.createStatement().execute("CREATE VIEW " + childView + " AS SELECT * FROM " + viewName);
+
+ assertEquals(PTable.ViewType.READ_ONLY, PhoenixRuntime.getTable(conn,viewName).getViewType());
+ assertEquals(PTable.ViewType.READ_ONLY, PhoenixRuntime.getTable(conn,childView).getViewType());
+
+ }
+ }
+}
\ No newline at end of file
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 1baa2ae756..3986ea6607 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
@@ -104,7 +104,7 @@ public class CreateTableCompiler {
PrimaryKeyConstraint pkConstraint = create.getPrimaryKeyConstraint();
for (int i = 0; i < columnDefs.size(); i++) {
ColumnDef columnDef = columnDefs.get(i);
- if(columnDef.getColumnDefName().getFamilyName()!=null && columnDef.getColumnDefName().getFamilyName().contains(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) {
+ if (columnDef.getColumnDefName().getFamilyName()!=null && columnDef.getColumnDefName().getFamilyName().contains(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.UNALLOWED_COLUMN_FAMILY)
.build().buildException();
}
@@ -138,6 +138,9 @@ public class CreateTableCompiler {
viewTypeToBe = parentToBe.getViewType() == ViewType.MAPPED ? ViewType.MAPPED : ViewType.UPDATABLE;
if (whereNode == null) {
viewStatementToBe = parentToBe.getViewStatement();
+ if (parentToBe.getViewType() == ViewType.READ_ONLY) {
+ viewTypeToBe = ViewType.READ_ONLY;
+ }
} else {
whereNode = StatementNormalizer.normalize(whereNode, resolver);
if (whereNode.isStateless()) {