You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by gj...@apache.org on 2019/03/05 18:04:56 UTC
[phoenix] branch 4.x-HBase-1.2 updated: PHOENIX-4345 Error message
for incorrect index is not accurate
This is an automated email from the ASF dual-hosted git repository.
gjacoby pushed a commit to branch 4.x-HBase-1.2
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x-HBase-1.2 by this push:
new a979346 PHOENIX-4345 Error message for incorrect index is not accurate
a979346 is described below
commit a9793464dc8dfd239878b4a8195942529e593b7c
Author: Xinyi Yan <xy...@salesforce.com>
AuthorDate: Wed Feb 27 23:33:23 2019 -0800
PHOENIX-4345 Error message for incorrect index is not accurate
Signed-off-by: Geoffrey Jacoby <gj...@apache.org>
---
.../apache/phoenix/end2end/index/IndexUsageIT.java | 40 ++++++++++++++++++++++
.../org/apache/phoenix/compile/FromCompiler.java | 12 ++++++-
.../apache/phoenix/exception/SQLExceptionCode.java | 7 ++++
...dException.java => IndexNotFoundException.java} | 35 +++++--------------
.../org/apache/phoenix/schema/MetaDataClient.java | 7 +++-
.../phoenix/schema/TableNotFoundException.java | 4 +++
6 files changed, 77 insertions(+), 28 deletions(-)
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexUsageIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexUsageIT.java
index f114010..6433f5a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexUsageIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexUsageIT.java
@@ -35,6 +35,7 @@ import java.sql.SQLException;
import java.util.Properties;
import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.execute.CommitException;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.util.DateUtil;
@@ -772,4 +773,43 @@ public class IndexUsageIT extends ParallelStatsDisabledIT {
}
}
+ @Test
+ public void testIndexNotFoundForWrongIndexNameRebuild() throws Exception{
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ String dataTableName = generateUniqueName();
+ String wrongIndexName = generateUniqueName();
+
+ try {
+ conn.createStatement().execute("CREATE TABLE " + dataTableName +
+ " (k VARCHAR NOT NULL PRIMARY KEY, v VARCHAR)");
+
+ conn.createStatement().execute(
+ "ALTER INDEX " + wrongIndexName + " ON " + dataTableName + " rebuild");
+
+ }catch (SQLException e) {
+ assertEquals(e.getErrorCode(), SQLExceptionCode.INDEX_UNDEFINED.getErrorCode());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testIndexNotFoundForDropWongIndexName() throws Exception{
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ String dataTableName = generateUniqueName();
+ String wrongIndexName = generateUniqueName();
+
+ try {
+ conn.createStatement().execute("CREATE TABLE " + dataTableName +
+ " (k VARCHAR NOT NULL PRIMARY KEY, v VARCHAR)");
+ conn.createStatement().execute("DROP INDEX " + wrongIndexName + " ON " +
+ dataTableName);
+ }catch (SQLException e) {
+ assertEquals(e.getErrorCode(), SQLExceptionCode.INDEX_UNDEFINED.getErrorCode());
+ } finally {
+ conn.close();
+ }
+ }
}
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
index 2701af0..9ed206e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
@@ -64,6 +64,7 @@ import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
import org.apache.phoenix.schema.ColumnNotFoundException;
import org.apache.phoenix.schema.ColumnRef;
import org.apache.phoenix.schema.FunctionNotFoundException;
+import org.apache.phoenix.schema.IndexNotFoundException;
import org.apache.phoenix.schema.MetaDataClient;
import org.apache.phoenix.schema.MetaDataEntityNotFoundException;
import org.apache.phoenix.schema.PColumn;
@@ -265,6 +266,15 @@ public class FromCompiler {
return visitor;
}
+ public static ColumnResolver getIndexResolver(SingleTableStatement statement,
+ PhoenixConnection connection) throws SQLException {
+ try {
+ return getResolver(statement, connection);
+ } catch (TableNotFoundException e) {
+ throw new IndexNotFoundException(e.getSchemaName(), e.getTableName(), e.getTimeStamp());
+ }
+ }
+
public static ColumnResolver getResolver(SingleTableStatement statement, PhoenixConnection connection, Map<String, UDFParseNode> udfParseNodes)
throws SQLException {
SingleTableColumnResolver visitor = new SingleTableColumnResolver(connection, statement.getTable(), true, 0, udfParseNodes);
@@ -287,7 +297,7 @@ public class FromCompiler {
.build();
return new SingleTableColumnResolver(connection, new TableRef(tableRef.getTableAlias(), t, tableRef.getLowerBoundTimeStamp(), tableRef.hasDynamicCols()));
}
-
+
public static ColumnResolver getResolver(TableRef tableRef)
throws SQLException {
SingleTableColumnResolver visitor = new SingleTableColumnResolver(tableRef);
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 cf0b9ae..fc991a7 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
@@ -34,6 +34,7 @@ import org.apache.phoenix.schema.ColumnNotFoundException;
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.ReadOnlyTableException;
import org.apache.phoenix.schema.SchemaAlreadyExistsException;
import org.apache.phoenix.schema.SchemaNotFoundException;
@@ -225,6 +226,12 @@ public enum SQLExceptionCode {
return new TableNotFoundException(info.getSchemaName(), info.getTableName());
}
}),
+ INDEX_UNDEFINED(1042, "42M06", "Index undefined.", new Factory() {
+ @Override
+ public SQLException newException(SQLExceptionInfo info) {
+ return new IndexNotFoundException(info.getSchemaName(), info.getTableName());
+ }
+ }),
TABLE_ALREADY_EXIST(1013, "42M04", "Table already exists.", new Factory() {
@Override
public SQLException newException(SQLExceptionInfo info) {
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableNotFoundException.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/IndexNotFoundException.java
similarity index 52%
copy from phoenix-core/src/main/java/org/apache/phoenix/schema/TableNotFoundException.java
copy to phoenix-core/src/main/java/org/apache/phoenix/schema/IndexNotFoundException.java
index 298a288..f7f0727 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableNotFoundException.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/IndexNotFoundException.java
@@ -18,43 +18,26 @@
package org.apache.phoenix.schema;
import org.apache.hadoop.hbase.HConstants;
-
import org.apache.phoenix.exception.SQLExceptionCode;
-import org.apache.phoenix.exception.SQLExceptionInfo;
import org.apache.phoenix.util.SchemaUtil;
+public class IndexNotFoundException extends TableNotFoundException {
+ private static SQLExceptionCode code = SQLExceptionCode.INDEX_UNDEFINED;
-/**
- *
- * Exception thrown when a table name could not be found in the schema
- *
- *
- * @since 0.1
- */
-public class TableNotFoundException extends MetaDataEntityNotFoundException {
- private static final long serialVersionUID = 1L;
- private static SQLExceptionCode code = SQLExceptionCode.TABLE_UNDEFINED;
- private final long timestamp;
-
- public TableNotFoundException(TableNotFoundException e, long timestamp) {
+ public IndexNotFoundException(IndexNotFoundException e, long timestamp) {
this(e.getSchemaName(),e.getTableName(), timestamp);
}
- public TableNotFoundException(String tableName) {
- this(SchemaUtil.getSchemaNameFromFullName(tableName), SchemaUtil.getTableNameFromFullName(tableName));
+ public IndexNotFoundException(String tableName) {
+ this(SchemaUtil.getSchemaNameFromFullName(tableName),
+ SchemaUtil.getTableNameFromFullName(tableName));
}
- public TableNotFoundException(String schemaName, String tableName) {
+ public IndexNotFoundException(String schemaName, String tableName) {
this(schemaName, tableName, HConstants.LATEST_TIMESTAMP);
}
-
- public TableNotFoundException(String schemaName, String tableName, long timestamp) {
- super(new SQLExceptionInfo.Builder(code).setSchemaName(schemaName).setTableName(tableName).build().toString(),
- code.getSQLState(), code.getErrorCode(), schemaName, tableName, null);
- this.timestamp = timestamp;
- }
- public long getTimeStamp() {
- return timestamp;
+ public IndexNotFoundException(String schemaName, String tableName, long timestamp) {
+ super(schemaName, tableName, timestamp, code);
}
}
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 269d121..c50f644 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
@@ -3169,6 +3169,9 @@ public class MetaDataClient {
}
} catch (TableNotFoundException e) {
if (!ifExists) {
+ if (tableType == PTableType.INDEX)
+ throw new IndexNotFoundException(e.getSchemaName(),
+ e.getTableName(), e.getTimeStamp());
throw e;
}
}
@@ -4298,7 +4301,9 @@ public class MetaDataClient {
String indexName = statement.getTable().getName().getTableName();
boolean isAsync = statement.isAsync();
String tenantId = connection.getTenantId() == null ? null : connection.getTenantId().getString();
- PTable table = FromCompiler.getResolver(statement, connection).getTables().get(0).getTable();
+ PTable table = FromCompiler.getIndexResolver(statement, connection)
+ .getTables().get(0).getTable();
+
String schemaName = statement.getTable().getName().getSchemaName();
String tableName = table.getTableName().getString();
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableNotFoundException.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableNotFoundException.java
index 298a288..ebc6b4d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableNotFoundException.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableNotFoundException.java
@@ -49,6 +49,10 @@ public class TableNotFoundException extends MetaDataEntityNotFoundException {
}
public TableNotFoundException(String schemaName, String tableName, long timestamp) {
+ this(schemaName, tableName, timestamp, code);
+ }
+
+ public TableNotFoundException(String schemaName, String tableName, long timestamp, SQLExceptionCode code) {
super(new SQLExceptionInfo.Builder(code).setSchemaName(schemaName).setTableName(tableName).build().toString(),
code.getSQLState(), code.getErrorCode(), schemaName, tableName, null);
this.timestamp = timestamp;