You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by pb...@apache.org on 2018/11/26 10:39:35 UTC
[06/12] phoenix git commit: PHOENIX-4971 Drop index will execute
successfully using Incorrect name of parent tables
PHOENIX-4971 Drop index will execute successfully using Incorrect name of parent tables
Signed-off-by: Geoffrey Jacoby <gj...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/76f07482
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/76f07482
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/76f07482
Branch: refs/heads/4.x-cdh5.15
Commit: 76f07482081a0115c503a4a226ba84e854d35513
Parents: 4bbe8e2
Author: Jaanai <cl...@gmail.com>
Authored: Sun Oct 28 11:10:51 2018 +0000
Committer: pboado <pe...@gmail.com>
Committed: Sun Nov 25 22:09:09 2018 +0000
----------------------------------------------------------------------
.../phoenix/end2end/index/DropMetadataIT.java | 24 +++++++++++++++++++-
.../phoenix/exception/SQLExceptionCode.java | 2 ++
.../apache/phoenix/schema/MetaDataClient.java | 15 ++++++++++++
3 files changed, 40 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/76f07482/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
index b92ed8d..a285526 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
@@ -18,9 +18,13 @@
package org.apache.phoenix.end2end.index;
import static org.apache.phoenix.util.TestUtil.HBASE_NATIVE_SCHEMA_NAME;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.sql.Connection;
import java.sql.DriverManager;
+import java.sql.SQLException;
+
import java.util.Properties;
import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -29,6 +33,7 @@ import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.util.PropertiesUtil;
@@ -56,7 +61,24 @@ public class DropMetadataIT extends ParallelStatsDisabledIT {
String url = QueryUtil.getConnectionUrl(props, config, PRINCIPAL);
return DriverManager.getConnection(url, props);
}
-
+
+ @Test
+ public void testDropIndexTableHasSameNameWithDataTable() {
+ String tableName = generateUniqueName();
+ String indexName = "IDX_" + tableName;
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ String createTable = "CREATE TABLE " + tableName + " (id varchar not null primary key, col integer)";
+ conn.createStatement().execute(createTable);
+ String createIndex = "CREATE INDEX " + indexName + " on " + tableName + "(col)";
+ conn.createStatement().execute(createIndex);
+ String dropIndex = "DROP INDEX " + indexName + " on " + indexName;
+ conn.createStatement().execute(dropIndex);
+ fail("should not execute successfully");
+ } catch (SQLException e) {
+ assertTrue(SQLExceptionCode.PARENT_TABLE_NOT_FOUND.getErrorCode() == e.getErrorCode());
+ }
+ }
+
@Test
public void testDropViewKeepsHTable() throws Exception {
Connection conn = getConnection();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/76f07482/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 d84857d..6696521 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
@@ -184,6 +184,8 @@ public enum SQLExceptionCode {
INVALID_REPLAY_AT(533, "42910", "Value of REPLAY_AT cannot be less than zero."),
UNEQUAL_SCN_AND_BUILD_INDEX_AT(534, "42911", "If both specified, values of CURRENT_SCN and BUILD_INDEX_AT must be equal."),
ONLY_INDEX_UPDATABLE_AT_SCN(535, "42912", "Only an index may be updated when the BUILD_INDEX_AT property is specified"),
+ PARENT_TABLE_NOT_FOUND(536, "42913", "Can't drop the index because the parent table in the DROP statement is incorrect."),
+
/**
* HBase and Phoenix specific implementation defined sub-classes.
* Column family related exceptions.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/76f07482/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 66e8baa..6563c40 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
@@ -23,6 +23,7 @@ import static org.apache.hadoop.hbase.HColumnDescriptor.TTL;
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.ANALYZE_TABLE;
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.RUN_UPDATE_STATS_ASYNC_ATTRIB;
import static org.apache.phoenix.exception.SQLExceptionCode.INSUFFICIENT_MULTI_TENANT_COLUMNS;
+import static org.apache.phoenix.exception.SQLExceptionCode.PARENT_TABLE_NOT_FOUND;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.APPEND_ONLY_SCHEMA;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ARG_POSITION;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ARRAY_SIZE;
@@ -3036,6 +3037,20 @@ public class MetaDataClient {
}
MutationState dropTable(String schemaName, String tableName, String parentTableName, PTableType tableType,
boolean ifExists, boolean cascade, boolean skipAddingParentColumns) throws SQLException {
+ // Checking the parent table whether exists
+ String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
+ try {
+ PTable ptable = connection.getTable(new PTableKey(connection.getTenantId(), fullTableName));
+ if (parentTableName != null &&!parentTableName.equals(ptable.getParentTableName().getString())) {
+ throw new SQLExceptionInfo.Builder(PARENT_TABLE_NOT_FOUND)
+ .setSchemaName(schemaName).setTableName(tableName).build().buildException();
+ }
+ } catch (TableNotFoundException e) {
+ if (!ifExists) {
+ throw e;
+ }
+ }
+
connection.rollback();
boolean wasAutoCommit = connection.getAutoCommit();
PName tenantId = connection.getTenantId();