use of org.apache.phoenix.schema.TableNotFoundException in project phoenix by apache.
the class ConnectionQueryServicesImpl method dropTables.
private void dropTables(final List<byte[]> tableNamesToDelete) throws SQLException {
SQLException sqlE = null;
try (HBaseAdmin admin = getAdmin()) {
if (tableNamesToDelete != null) {
for (byte[] tableName : tableNamesToDelete) {
try {
HTableDescriptor htableDesc = this.getTableDescriptor(tableName);
admin.disableTable(tableName);
admin.deleteTable(tableName);
tableStatsCache.invalidateAll(htableDesc);
clearTableRegionCache(tableName);
} catch (TableNotFoundException ignore) {
}
}
}
} catch (IOException e) {
sqlE = ServerUtil.parseServerException(e);
} finally {
if (sqlE != null) {
throw sqlE;
}
}
}
use of org.apache.phoenix.schema.TableNotFoundException in project phoenix by apache.
the class ConnectionlessQueryServicesImpl method getTable.
@Override
public MetaDataMutationResult getTable(PName tenantId, byte[] schemaBytes, byte[] tableBytes, long tableTimestamp, long clientTimestamp) throws SQLException {
// to get anything from the server (since we don't have a connection)
try {
String fullTableName = SchemaUtil.getTableName(schemaBytes, tableBytes);
PTable table = metaData.getTableRef(new PTableKey(tenantId, fullTableName)).getTable();
return new MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS, 0, table, true);
} catch (TableNotFoundException e) {
return new MetaDataMutationResult(MutationCode.TABLE_NOT_FOUND, 0, null);
}
}
use of org.apache.phoenix.schema.TableNotFoundException in project phoenix by apache.
the class LocalIndexIT method testLocalIndexCreationWithSplitsShouldFail.
@Test
public void testLocalIndexCreationWithSplitsShouldFail() throws Exception {
String tableName = schemaName + "." + generateUniqueName();
String indexName = "IDX_" + generateUniqueName();
createBaseTable(tableName, null, null);
Connection conn1 = getConnection();
Connection conn2 = getConnection();
try {
conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)" + " split on (1,2,3)");
fail("Local index cannot be pre-split");
} catch (SQLException e) {
}
try {
conn2.createStatement().executeQuery("SELECT * FROM " + tableName).next();
conn2.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, indexName));
fail("Local index should not be created.");
} catch (TableNotFoundException e) {
}
}
use of org.apache.phoenix.schema.TableNotFoundException in project phoenix by apache.
the class IndexMetadataIT method testIndexCreateDrop.
@Test
public void testIndexCreateDrop() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
String indexDataTable = generateUniqueName();
String fullIndexDataTable = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable;
String indexName = generateUniqueName();
try {
String tableDDL = "create table " + fullIndexDataTable + TestUtil.TEST_TABLE_SCHEMA;
conn.createStatement().execute(tableDDL);
String ddl = "CREATE INDEX " + indexName + " ON " + fullIndexDataTable + " (varchar_col1 ASC, varchar_col2 ASC, int_pk DESC)" + " INCLUDE (int_col1, int_col2)";
conn.createStatement().execute(ddl);
// Verify the metadata for index is correct.
ResultSet rs = conn.getMetaData().getIndexInfo(null, INDEX_DATA_SCHEMA, indexDataTable, false, false);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName, 1, "A:VARCHAR_COL1", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName, 2, "B:VARCHAR_COL2", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName, 3, ":INT_PK", Order.DESC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName, 4, ":VARCHAR_PK", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName, 5, ":CHAR_PK", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName, 6, ":LONG_PK", Order.DESC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName, 7, ":DECIMAL_PK", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName, 8, ":DATE_PK", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName, 9, "A:INT_COL1", null);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName, 10, "B:INT_COL2", null);
assertFalse(rs.next());
rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(INDEX_DATA_SCHEMA), StringUtil.escapeLike(indexName), new String[] { PTableType.INDEX.getValue().getString() });
assertTrue(rs.next());
assertEquals(PIndexState.ACTIVE.toString(), rs.getString("INDEX_STATE"));
// Verify that there is a row inserted into the data table for the index table.
rs = IndexTestUtil.readDataTableIndexRow(conn, INDEX_DATA_SCHEMA, indexDataTable, indexName);
assertTrue(rs.next());
assertEquals(indexName, rs.getString(1));
assertFalse(rs.next());
assertActiveIndex(conn, INDEX_DATA_SCHEMA, indexDataTable);
ddl = "ALTER INDEX " + indexName + " ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable + " UNUSABLE";
conn.createStatement().execute(ddl);
// Verify the metadata for index is correct.
rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(INDEX_DATA_SCHEMA), indexName, new String[] { PTableType.INDEX.toString() });
assertTrue(rs.next());
assertEquals(indexName, rs.getString(3));
assertEquals(PIndexState.INACTIVE.toString(), rs.getString("INDEX_STATE"));
assertFalse(rs.next());
assertActiveIndex(conn, INDEX_DATA_SCHEMA, indexDataTable);
ddl = "ALTER INDEX " + indexName + " ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable + " USABLE";
conn.createStatement().execute(ddl);
// Verify the metadata for index is correct.
rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(INDEX_DATA_SCHEMA), indexName, new String[] { PTableType.INDEX.toString() });
assertTrue(rs.next());
assertEquals(indexName, rs.getString(3));
assertEquals(PIndexState.ACTIVE.toString(), rs.getString("INDEX_STATE"));
assertFalse(rs.next());
assertActiveIndex(conn, INDEX_DATA_SCHEMA, indexDataTable);
ddl = "ALTER INDEX " + indexName + " ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable + " DISABLE";
conn.createStatement().execute(ddl);
// Verify the metadata for index is correct.
rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(INDEX_DATA_SCHEMA), indexName, new String[] { PTableType.INDEX.toString() });
assertTrue(rs.next());
assertEquals(indexName, rs.getString(3));
assertEquals(PIndexState.DISABLE.toString(), rs.getString("INDEX_STATE"));
assertFalse(rs.next());
assertNoActiveIndex(conn, INDEX_DATA_SCHEMA, indexDataTable);
try {
ddl = "ALTER INDEX " + indexName + " ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable + " USABLE";
conn.createStatement().execute(ddl);
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.INVALID_INDEX_STATE_TRANSITION.getErrorCode(), e.getErrorCode());
}
try {
ddl = "ALTER INDEX " + indexName + " ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable + " UNUSABLE";
conn.createStatement().execute(ddl);
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.INVALID_INDEX_STATE_TRANSITION.getErrorCode(), e.getErrorCode());
}
ddl = "ALTER INDEX " + indexName + " ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable + " REBUILD";
conn.createStatement().execute(ddl);
// Verify the metadata for index is correct.
rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(INDEX_DATA_SCHEMA), indexName, new String[] { PTableType.INDEX.toString() });
assertTrue(rs.next());
assertEquals(indexName, rs.getString(3));
assertEquals(PIndexState.ACTIVE.toString(), rs.getString("INDEX_STATE"));
assertFalse(rs.next());
assertActiveIndex(conn, INDEX_DATA_SCHEMA, indexDataTable);
ddl = "ALTER INDEX " + indexName + " ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable + " REBUILD ASYNC";
conn.createStatement().execute(ddl);
// Verify the metadata for index is correct.
rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(INDEX_DATA_SCHEMA), indexName, new String[] { PTableType.INDEX.toString() });
assertTrue(rs.next());
assertEquals(indexName, rs.getString(3));
assertEquals(PIndexState.BUILDING.toString(), rs.getString("INDEX_STATE"));
assertFalse(rs.next());
ddl = "DROP INDEX " + indexName + " ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable;
conn.createStatement().execute(ddl);
assertNoActiveIndex(conn, INDEX_DATA_SCHEMA, indexDataTable);
// Assert the rows for index table is completely removed.
rs = conn.getMetaData().getIndexInfo(null, INDEX_DATA_SCHEMA, indexDataTable, false, false);
assertFalse(rs.next());
// Assert the row in the original data table is removed.
// Verify that there is a row inserted into the data table for the index table.
rs = IndexTestUtil.readDataTableIndexRow(conn, INDEX_DATA_SCHEMA, indexDataTable, indexName);
assertFalse(rs.next());
// Create another two indexes, and drops the table, verifies the indexes are dropped as well.
ddl = "CREATE INDEX " + indexName + "1 ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable + " (varchar_col1 ASC, varchar_col2 ASC, int_pk DESC)" + " INCLUDE (int_col1, int_col2)";
conn.createStatement().execute(ddl);
ddl = "CREATE INDEX " + indexName + "2 ON " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable + " (varchar_col1 ASC, varchar_col2 ASC, int_pk DESC)" + " INCLUDE (long_pk, int_col2)";
conn.createStatement().execute(ddl);
rs = conn.getMetaData().getIndexInfo(null, INDEX_DATA_SCHEMA, indexDataTable, false, false);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "1", 1, "A:VARCHAR_COL1", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "1", 2, "B:VARCHAR_COL2", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "1", 3, ":INT_PK", Order.DESC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "1", 4, ":VARCHAR_PK", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "1", 5, ":CHAR_PK", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "1", 6, ":LONG_PK", Order.DESC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "1", 7, ":DECIMAL_PK", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "1", 8, ":DATE_PK", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "1", 9, "A:INT_COL1", null);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "1", 10, "B:INT_COL2", null);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "2", 1, "A:VARCHAR_COL1", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "2", 2, "B:VARCHAR_COL2", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "2", 3, ":INT_PK", Order.DESC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "2", 4, ":VARCHAR_PK", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "2", 5, ":CHAR_PK", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "2", 6, ":LONG_PK", Order.DESC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "2", 7, ":DECIMAL_PK", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "2", 8, ":DATE_PK", Order.ASC);
assertIndexInfoMetadata(rs, INDEX_DATA_SCHEMA, indexDataTable, indexName + "2", 9, "B:INT_COL2", null);
assertFalse(rs.next());
// Create another table in the same schema
String diffTableNameInSameSchema = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable + "2";
conn.createStatement().execute("CREATE TABLE " + diffTableNameInSameSchema + "(k INTEGER PRIMARY KEY)");
try {
conn.createStatement().execute("DROP INDEX " + indexName + "1 ON " + diffTableNameInSameSchema);
fail("Should have realized index " + indexName + "1 is not on the table");
} catch (TableNotFoundException ignore) {
}
ddl = "DROP TABLE " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTable;
conn.createStatement().execute(ddl);
rs = conn.getMetaData().getIndexInfo(null, INDEX_DATA_SCHEMA, indexDataTable, false, false);
assertFalse(rs.next());
rs = IndexTestUtil.readDataTableIndexRow(conn, INDEX_DATA_SCHEMA, indexDataTable, indexName + "1");
assertFalse(rs.next());
rs = IndexTestUtil.readDataTableIndexRow(conn, INDEX_DATA_SCHEMA, indexDataTable, indexName + "2");
assertFalse(rs.next());
} finally {
conn.close();
}
}
use of org.apache.phoenix.schema.TableNotFoundException in project phoenix by apache.
the class PhoenixRuntime method getTableNoCache.
public static PTable getTableNoCache(Connection conn, String name) throws SQLException {
String schemaName = SchemaUtil.getSchemaNameFromFullName(name);
String tableName = SchemaUtil.getTableNameFromFullName(name);
PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
MetaDataMutationResult result = new MetaDataClient(pconn).updateCache(pconn.getTenantId(), schemaName, tableName, true);
if (result.getMutationCode() != MutationCode.TABLE_ALREADY_EXISTS) {
throw new TableNotFoundException(schemaName, tableName);
}
return result.getTable();
}
Aggregations