You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by "Swaroopa Kadam (JIRA)" <ji...@apache.org> on 2019/08/06 21:08:00 UTC
[jira] [Created] (PHOENIX-5429) IndexTool doesn't rebuild indexes
from data table after truncating the index table
Swaroopa Kadam created PHOENIX-5429:
---------------------------------------
Summary: IndexTool doesn't rebuild indexes from data table after truncating the index table
Key: PHOENIX-5429
URL: https://issues.apache.org/jira/browse/PHOENIX-5429
Project: Phoenix
Issue Type: Bug
Affects Versions: 4.14.2
Reporter: Swaroopa Kadam
Assignee: Gokcen Iskender
Fix For: 4.15.0, 5.1.0, 4.14.3
Following test fails. with AssertionError at the last assertion.
{code:java}
@Test
public void testIndexRebuildTask() throws Throwable {
String TENANT1 = "tenant1";
String baseTable = generateUniqueName();
String viewName = generateUniqueName();
Connection conn = null;
Connection viewConn = null;
try {
conn = DriverManager.getConnection(getUrl());
conn.setAutoCommit(false);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, TENANT1);
viewConn =DriverManager.getConnection(getUrl(), props);
String ddlFormat =
"CREATE TABLE IF NOT EXISTS " + baseTable + " ("
+ " %s PK2 VARCHAR NOT NULL, V1 VARCHAR, V2 VARCHAR "
+ " CONSTRAINT NAME_PK PRIMARY KEY (%s PK2)" + " ) %s";
conn.createStatement().execute(generateDDL(ddlFormat));
conn.commit();
// Create a view
String viewDDL = "CREATE VIEW " + viewName + " AS SELECT * FROM " + baseTable;
viewConn.createStatement().execute(viewDDL);
// Create index
String indexName = generateUniqueName();
String idxSDDL = String.format("CREATE INDEX %s ON %s (V1)", indexName, viewName);
viewConn.createStatement().execute(idxSDDL);
// Insert rows
int numOfValues = 1000;
for (int i=0; i < numOfValues; i++){
viewConn.createStatement().execute(
String.format("UPSERT INTO %s VALUES('%s', '%s', '%s')", viewName, String.valueOf(i), "y",
"z"));
}
viewConn.commit();
String viewIndexTableName = MetaDataUtil.getViewIndexPhysicalName(baseTable);
ConnectionQueryServices queryServices = conn.unwrap(PhoenixConnection.class).getQueryServices();
int count = getUtility().countRows(queryServices.getTable(Bytes.toBytes(viewIndexTableName)));
assertTrue(count == numOfValues);
// Remove index contents and try again
Admin admin = queryServices.getAdmin();
TableName tableName = TableName.valueOf(viewIndexTableName);
admin.disableTable(tableName);
admin.truncateTable(tableName, true);
IndexToolIT.runIndexTool(true, false, "", viewName, indexName, TENANT1);
// See that index is rebuilt and confirm index has rows
Table htable= queryServices.getTable(Bytes.toBytes(viewIndexTableName));
count = getUtility().countRows(htable);
assertEquals(numOfValues, count);
} finally {
if (conn != null) {
conn.commit();
conn.close();
}
if (viewConn != null) {
viewConn.close();
}
}
}
{code}
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)