Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,9 @@ public SQLException newException(SQLExceptionInfo info) {

AUTO_COMMIT_NOT_ENABLED(916, "43M27", "Connection does not have auto-commit enabled"),

ALTER_INDEX_CONSISTENCY_NOT_SUPPORTED(917, "43M28",
"Changing index consistency with ALTER INDEX is not supported yet."),

// SQLCode for testing exceptions
FAILED_KNOWINGLY_FOR_TEST(7777, "TEST", "Exception was thrown to test something");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5967,6 +5967,14 @@ Collections.<Mutation> singletonList(new Put(SchemaUtil.getTableKey(tenantIdByte
}

public MutationState alterIndex(AlterIndexStatement statement) throws SQLException {
// ALTER INDEX ... CONSISTENCY is disabled until the change is coordinated with the other
// clients, the region servers and the index consumers (PHOENIX-8046). The grammar still
// accepts the clause. Removing this check enables the consistency handling below again.
if (statement.getIndexConsistency() != null) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.ALTER_INDEX_CONSISTENCY_NOT_SUPPORTED)
.setSchemaName(statement.getTable().getName().getSchemaName())
.setTableName(statement.getTable().getName().getTableName()).build().buildException();
}
connection.rollback();
boolean wasAutoCommit = connection.getAutoCommit();
String dataTableName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.phoenix.coprocessor.generated.ServerCachingProtos;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.index.IndexMaintainer;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.schema.PTable;
Expand All @@ -41,8 +44,10 @@
import org.apache.phoenix.schema.types.IndexConsistency;
import org.apache.phoenix.util.CDCUtil;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.SchemaUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

Expand Down Expand Up @@ -157,6 +162,7 @@ public void testIndexMaintainerConsistencyFromPTable() throws Exception {
}

@Test
@Ignore("ALTER INDEX ... CONSISTENCY is not supported until PHOENIX-8046 is fixed")
public void testAlterIndexConsistency() throws Exception {
String dataTableName = "\"ScheMa1234-_\".\"alterTable1.1_0-001\"";
String dataTableNameWithoutQuotes = "ScheMa1234-_.alterTable1.1_0-001";
Expand Down Expand Up @@ -207,6 +213,40 @@ public void testAlterIndexConsistency() throws Exception {
}
}

@Test
public void testAlterIndexConsistencyNotSupported() throws Exception {
String schemaName = generateUniqueName();
String dataTableName = SchemaUtil.getTableName(schemaName, generateUniqueName());
String indexName = generateUniqueName();

try (Connection conn =
DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES))) {
PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
conn.createStatement().execute(
"CREATE TABLE " + dataTableName + " (id INTEGER PRIMARY KEY, name VARCHAR, city VARCHAR)");
conn.createStatement()
.execute("CREATE INDEX " + indexName + " ON " + dataTableName + " (name) INCLUDE (city)");

// The parser still accepts the CONSISTENCY clause, but the client rejects the statement.
for (IndexConsistency consistency : IndexConsistency.values()) {
try {
conn.createStatement().execute(
"ALTER INDEX " + indexName + " ON " + dataTableName + " CONSISTENCY=" + consistency);
fail("ALTER INDEX ... CONSISTENCY=" + consistency + " should not be supported");
} catch (SQLException e) {
assertEquals(SQLExceptionCode.ALTER_INDEX_CONSISTENCY_NOT_SUPPORTED.getErrorCode(),
e.getErrorCode());
}
}

// The rejected statements must not change the index or create a CDC object.
PTable index = pconn.getTableNoCache(SchemaUtil.getTableName(schemaName, indexName));
PTable dataTable = pconn.getTableNoCache(dataTableName);
assertNull(index.getIndexConsistency());
assertFalse("Data table should not have a CDC index", CDCUtil.hasCDCIndex(dataTable));
}
}

private void verifyTableDescriptor(PhoenixConnection pconn, PTable... tables) throws Exception {
try (Admin admin = pconn.getQueryServices().getAdmin()) {
for (PTable table : tables) {
Expand Down
Loading