You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2017/11/15 18:34:47 UTC

[19/40] phoenix git commit: PHOENIX-4343 In CREATE TABLE allow setting guide post width only on base data tables

PHOENIX-4343 In CREATE TABLE allow setting guide post width only on base data tables


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

Branch: refs/heads/4.x-HBase-1.2
Commit: 32beb7073ec9147391a6591afdafdc304426384d
Parents: 4fdf708
Author: Samarth Jain <sa...@apache.org>
Authored: Wed Nov 1 23:21:01 2017 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed Nov 15 10:02:14 2017 -0800

----------------------------------------------------------------------
 .../apache/phoenix/end2end/CreateTableIT.java   | 73 ++++++++++++++++++++
 .../end2end/ExplainPlanWithStatsEnabledIT.java  |  2 +-
 .../phoenix/exception/SQLExceptionCode.java     |  2 +-
 .../apache/phoenix/schema/MetaDataClient.java   |  7 ++
 4 files changed, 82 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/32beb707/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
index 93bb02b..1abc653 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
@@ -27,6 +27,7 @@ import static org.junit.Assert.fail;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -35,6 +36,7 @@ import java.util.Properties;
 
 import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.GlobalPermissionOrBuilder;
 import org.apache.hadoop.hbase.regionserver.BloomType;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.exception.SQLExceptionCode;
@@ -743,4 +745,75 @@ public class CreateTableIT extends ParallelStatsDisabledIT {
         }
         conn2.close();
     }
+
+    @Test
+    public void testSettingGuidePostWidth() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String dataTable = generateUniqueName();
+            int guidePostWidth = 20;
+            String ddl =
+                    "CREATE TABLE " + dataTable + " (k INTEGER PRIMARY KEY, a bigint, b bigint)"
+                            + " GUIDE_POSTS_WIDTH=" + guidePostWidth;
+            conn.createStatement().execute(ddl);
+            assertEquals(20, checkGuidePostWidth(dataTable));
+            String viewName = "V_" + generateUniqueName();
+            ddl =
+                    "CREATE VIEW " + viewName + " AS SELECT * FROM " + dataTable
+                            + " GUIDE_POSTS_WIDTH=" + guidePostWidth;
+            try {
+                conn.createStatement().execute(ddl);
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_SET_GUIDE_POST_WIDTH.getErrorCode(),
+                    e.getErrorCode());
+            }
+
+            // let the view creation go through
+            ddl = "CREATE VIEW " + viewName + " AS SELECT * FROM " + dataTable;
+            conn.createStatement().execute(ddl);
+
+            String globalIndex = "GI_" + generateUniqueName();
+            ddl =
+                    "CREATE INDEX " + globalIndex + " ON " + dataTable
+                            + "(a) INCLUDE (b) GUIDE_POSTS_WIDTH = " + guidePostWidth;
+            try {
+                conn.createStatement().execute(ddl);
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_SET_GUIDE_POST_WIDTH.getErrorCode(),
+                    e.getErrorCode());
+            }
+            String localIndex = "LI_" + generateUniqueName();
+            ddl =
+                    "CREATE LOCAL INDEX " + localIndex + " ON " + dataTable
+                            + "(b) INCLUDE (a) GUIDE_POSTS_WIDTH = " + guidePostWidth;
+            try {
+                conn.createStatement().execute(ddl);
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_SET_GUIDE_POST_WIDTH.getErrorCode(),
+                    e.getErrorCode());
+            }
+            String viewIndex = "VI_" + generateUniqueName();
+            ddl =
+                    "CREATE LOCAL INDEX " + viewIndex + " ON " + dataTable
+                            + "(b) INCLUDE (a) GUIDE_POSTS_WIDTH = " + guidePostWidth;
+            try {
+                conn.createStatement().execute(ddl);
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.CANNOT_SET_GUIDE_POST_WIDTH.getErrorCode(),
+                    e.getErrorCode());
+            }
+        }
+    }
+
+    private int checkGuidePostWidth(String tableName) throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String query =
+                    "SELECT GUIDE_POSTS_WIDTH FROM SYSTEM.CATALOG WHERE TABLE_NAME = ? AND COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL";
+            PreparedStatement stmt = conn.prepareStatement(query);
+            stmt.setString(1, tableName);
+            ResultSet rs = stmt.executeQuery();
+            assertTrue(rs.next());
+            return rs.getInt(1);
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/32beb707/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
index b5e4588..e76b147 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
@@ -73,7 +73,7 @@ public class ExplainPlanWithStatsEnabledIT extends ParallelStatsEnabledIT {
             throws Exception {
         try (Connection conn = DriverManager.getConnection(getUrl())) {
             conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + table
-                    + " (c1.a) INCLUDE (c2.b) GUIDE_POSTS_WIDTH = " + guidePostWidth);
+                    + " (c1.a) INCLUDE (c2.b) ");
             conn.createStatement().execute("UPDATE STATISTICS " + indexName);
         }
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/32beb707/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
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 cfeb212..e51fd9f 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
@@ -378,7 +378,7 @@ public enum SQLExceptionCode {
     MAX_COLUMNS_EXCEEDED(1136, "XCL36", "The number of columns exceed the maximum supported by the table's qualifier encoding scheme"),
     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"),
     /**
      * Implementation defined class. Phoenix internal error. (errorcode 20, sqlstate INT).
      */

http://git-wip-us.apache.org/repos/asf/phoenix/blob/32beb707/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 7ce2167..338b325 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -1949,6 +1949,13 @@ public class MetaDataClient {
             }
             String autoPartitionSeq = (String) TableProperty.AUTO_PARTITION_SEQ.getValue(tableProps);
             Long guidePostsWidth = (Long) TableProperty.GUIDE_POSTS_WIDTH.getValue(tableProps);
+
+            // We only allow setting guide post width for a base table
+            if (guidePostsWidth != null && tableType != PTableType.TABLE) {
+                throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_SET_GUIDE_POST_WIDTH)
+                        .setSchemaName(schemaName).setTableName(tableName).build().buildException();
+            }
+
             Boolean storeNullsProp = (Boolean) TableProperty.STORE_NULLS.getValue(tableProps);
             if (storeNullsProp == null) {
                 if (parent == null) {