@Test public void testHandleCreateTableMutationCode() throws SQLException { MetaDataProtocol.MetaDataMutationResult result = new MetaDataProtocol.MetaDataMutationResult (MetaDataProtocol.MutationCode.UNALLOWED_TABLE_MUTATION ,new PSchema(schema), EnvironmentEdgeManager.currentTimeMillis()); try { mockClient.handleCreateTableMutationCode(result, result.getMutationCode(), stmt, schema, baseTable, null); fail(); } catch (SQLException e) { assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode()); } }
@VisibleForTesting public boolean handleCreateTableMutationCode(MetaDataMutationResult result, MutationCode code, CreateTableStatement statement, String schemaName, String tableName, PTable parent) throws SQLException { switch(code) { case TABLE_ALREADY_EXISTS: if(result.getTable() != null) { addTableToCache(result); } if(!statement.ifNotExists()) { throw new TableAlreadyExistsException(schemaName, tableName, result.getTable()); } return true; case NEWER_TABLE_FOUND: if (!statement.ifNotExists()) { throw new NewerTableAlreadyExistsException(schemaName, tableName, result.getTable()); } return false; case UNALLOWED_TABLE_MUTATION: throwsSQLExceptionUtil("CANNOT_MUTATE_TABLE",schemaName,tableName); case CONCURRENT_TABLE_MUTATION: addTableToCache(result); throw new ConcurrentTableMutationException(schemaName, tableName); case AUTO_PARTITION_SEQUENCE_NOT_FOUND: throw new SQLExceptionInfo.Builder(SQLExceptionCode.AUTO_PARTITION_SEQUENCE_UNDEFINED) .setSchemaName(schemaName).setTableName(tableName).build().buildException(); case CANNOT_COERCE_AUTO_PARTITION_ID: case UNABLE_TO_CREATE_CHILD_LINK: case PARENT_TABLE_NOT_FOUND: case TABLE_NOT_IN_REGION: throwsSQLExceptionUtil(String.valueOf(code), schemaName, tableName); case TOO_MANY_INDEXES: case UNABLE_TO_UPDATE_PARENT_TABLE: throwsSQLExceptionUtil(String.valueOf(code), SchemaUtil.getSchemaNameFromFullName( parent.getPhysicalName().getString()),SchemaUtil.getTableNameFromFullName( parent.getPhysicalName().getString())); default: throw new SQLExceptionInfo.Builder(SQLExceptionCode.UNEXPECTED_MUTATION_CODE) .setSchemaName(schemaName).setTableName(tableName).setMessage("mutation code: " + code).build().buildException(); } }
MetaDataClient { @VisibleForTesting public boolean handleCreateTableMutationCode(MetaDataMutationResult result, MutationCode code, CreateTableStatement statement, String schemaName, String tableName, PTable parent) throws SQLException { switch(code) { case TABLE_ALREADY_EXISTS: if(result.getTable() != null) { addTableToCache(result); } if(!statement.ifNotExists()) { throw new TableAlreadyExistsException(schemaName, tableName, result.getTable()); } return true; case NEWER_TABLE_FOUND: if (!statement.ifNotExists()) { throw new NewerTableAlreadyExistsException(schemaName, tableName, result.getTable()); } return false; case UNALLOWED_TABLE_MUTATION: throwsSQLExceptionUtil("CANNOT_MUTATE_TABLE",schemaName,tableName); case CONCURRENT_TABLE_MUTATION: addTableToCache(result); throw new ConcurrentTableMutationException(schemaName, tableName); case AUTO_PARTITION_SEQUENCE_NOT_FOUND: throw new SQLExceptionInfo.Builder(SQLExceptionCode.AUTO_PARTITION_SEQUENCE_UNDEFINED) .setSchemaName(schemaName).setTableName(tableName).build().buildException(); case CANNOT_COERCE_AUTO_PARTITION_ID: case UNABLE_TO_CREATE_CHILD_LINK: case PARENT_TABLE_NOT_FOUND: case TABLE_NOT_IN_REGION: throwsSQLExceptionUtil(String.valueOf(code), schemaName, tableName); case TOO_MANY_INDEXES: case UNABLE_TO_UPDATE_PARENT_TABLE: throwsSQLExceptionUtil(String.valueOf(code), SchemaUtil.getSchemaNameFromFullName( parent.getPhysicalName().getString()),SchemaUtil.getTableNameFromFullName( parent.getPhysicalName().getString())); default: throw new SQLExceptionInfo.Builder(SQLExceptionCode.UNEXPECTED_MUTATION_CODE) .setSchemaName(schemaName).setTableName(tableName).setMessage("mutation code: " + code).build().buildException(); } } }
MetaDataClient { @VisibleForTesting public boolean handleCreateTableMutationCode(MetaDataMutationResult result, MutationCode code, CreateTableStatement statement, String schemaName, String tableName, PTable parent) throws SQLException { switch(code) { case TABLE_ALREADY_EXISTS: if(result.getTable() != null) { addTableToCache(result); } if(!statement.ifNotExists()) { throw new TableAlreadyExistsException(schemaName, tableName, result.getTable()); } return true; case NEWER_TABLE_FOUND: if (!statement.ifNotExists()) { throw new NewerTableAlreadyExistsException(schemaName, tableName, result.getTable()); } return false; case UNALLOWED_TABLE_MUTATION: throwsSQLExceptionUtil("CANNOT_MUTATE_TABLE",schemaName,tableName); case CONCURRENT_TABLE_MUTATION: addTableToCache(result); throw new ConcurrentTableMutationException(schemaName, tableName); case AUTO_PARTITION_SEQUENCE_NOT_FOUND: throw new SQLExceptionInfo.Builder(SQLExceptionCode.AUTO_PARTITION_SEQUENCE_UNDEFINED) .setSchemaName(schemaName).setTableName(tableName).build().buildException(); case CANNOT_COERCE_AUTO_PARTITION_ID: case UNABLE_TO_CREATE_CHILD_LINK: case PARENT_TABLE_NOT_FOUND: case TABLE_NOT_IN_REGION: throwsSQLExceptionUtil(String.valueOf(code), schemaName, tableName); case TOO_MANY_INDEXES: case UNABLE_TO_UPDATE_PARENT_TABLE: throwsSQLExceptionUtil(String.valueOf(code), SchemaUtil.getSchemaNameFromFullName( parent.getPhysicalName().getString()),SchemaUtil.getTableNameFromFullName( parent.getPhysicalName().getString())); default: throw new SQLExceptionInfo.Builder(SQLExceptionCode.UNEXPECTED_MUTATION_CODE) .setSchemaName(schemaName).setTableName(tableName).setMessage("mutation code: " + code).build().buildException(); } } MetaDataClient(PhoenixConnection connection); }
MetaDataClient { @VisibleForTesting public boolean handleCreateTableMutationCode(MetaDataMutationResult result, MutationCode code, CreateTableStatement statement, String schemaName, String tableName, PTable parent) throws SQLException { switch(code) { case TABLE_ALREADY_EXISTS: if(result.getTable() != null) { addTableToCache(result); } if(!statement.ifNotExists()) { throw new TableAlreadyExistsException(schemaName, tableName, result.getTable()); } return true; case NEWER_TABLE_FOUND: if (!statement.ifNotExists()) { throw new NewerTableAlreadyExistsException(schemaName, tableName, result.getTable()); } return false; case UNALLOWED_TABLE_MUTATION: throwsSQLExceptionUtil("CANNOT_MUTATE_TABLE",schemaName,tableName); case CONCURRENT_TABLE_MUTATION: addTableToCache(result); throw new ConcurrentTableMutationException(schemaName, tableName); case AUTO_PARTITION_SEQUENCE_NOT_FOUND: throw new SQLExceptionInfo.Builder(SQLExceptionCode.AUTO_PARTITION_SEQUENCE_UNDEFINED) .setSchemaName(schemaName).setTableName(tableName).build().buildException(); case CANNOT_COERCE_AUTO_PARTITION_ID: case UNABLE_TO_CREATE_CHILD_LINK: case PARENT_TABLE_NOT_FOUND: case TABLE_NOT_IN_REGION: throwsSQLExceptionUtil(String.valueOf(code), schemaName, tableName); case TOO_MANY_INDEXES: case UNABLE_TO_UPDATE_PARENT_TABLE: throwsSQLExceptionUtil(String.valueOf(code), SchemaUtil.getSchemaNameFromFullName( parent.getPhysicalName().getString()),SchemaUtil.getTableNameFromFullName( parent.getPhysicalName().getString())); default: throw new SQLExceptionInfo.Builder(SQLExceptionCode.UNEXPECTED_MUTATION_CODE) .setSchemaName(schemaName).setTableName(tableName).setMessage("mutation code: " + code).build().buildException(); } } MetaDataClient(PhoenixConnection connection); PhoenixConnection getConnection(); long getCurrentTime(String schemaName, String tableName); MetaDataMutationResult updateCache(String schemaName, String tableName); MetaDataMutationResult updateCache(String schemaName, String tableName,
            boolean alwaysHitServer); MetaDataMutationResult updateCache(PName tenantId, String schemaName, String tableName, boolean alwaysHitServer); MetaDataMutationResult updateCache(List<String> functionNames); MetaDataMutationResult updateCache(PName tenantId, List<String> functionNames); MetaDataMutationResult updateCache(PName origTenantId, String schemaName, String tableName,
            boolean alwaysHitServer, Long resolvedTimestamp); MetaDataMutationResult updateCache(String schemaName); MetaDataMutationResult updateCache(String schemaName, boolean alwaysHitServer); MetaDataMutationResult updateCache(PName tenantId, List<String> functionNames,
            boolean alwaysHitServer); MutationState createTable(CreateTableStatement statement, byte[][] splits, PTable parent, String viewStatement, ViewType viewType, PDataType viewIndexIdType, byte[][] viewColumnConstants, BitSet isViewColumnReferenced); MutationState updateStatistics(UpdateStatisticsStatement updateStatisticsStmt); MutationState declareCursor(DeclareCursorStatement statement, QueryPlan queryPlan); MutationState open(OpenStatement statement); MutationState close(CloseStatement statement); MutationState createIndex(CreateIndexStatement statement, byte[][] splits); MutationState dropSequence(DropSequenceStatement statement); MutationState createSequence(CreateSequenceStatement statement, long startWith,
            long incrementBy, long cacheSize, long minValue, long maxValue); MutationState createFunction(CreateFunctionStatement stmt); @VisibleForTesting boolean handleCreateTableMutationCode(MetaDataMutationResult result, MutationCode code,
                 CreateTableStatement statement, String schemaName, String tableName,
                 PTable parent); MutationState dropTable(DropTableStatement statement); MutationState dropFunction(DropFunctionStatement statement); MutationState dropIndex(DropIndexStatement statement); MutationState addColumn(AddColumnStatement statement); MutationState addColumn(PTable table, List<ColumnDef> origColumnDefs,
            ListMultimap<String, Pair<String, Object>> stmtProperties, boolean ifNotExists,
            boolean removeTableProps, NamedTableNode namedTableNode, PTableType tableType, boolean cascade, List<NamedNode> indexes); MutationState dropColumn(DropColumnStatement statement); MutationState alterIndex(AlterIndexStatement statement); MutationState createSchema(CreateSchemaStatement create); MutationState dropSchema(DropSchemaStatement executableDropSchemaStatement); MutationState useSchema(UseSchemaStatement useSchemaStatement); MutationState changePermissions(ChangePermsStatement changePermsStatement); }
MetaDataClient { @VisibleForTesting public boolean handleCreateTableMutationCode(MetaDataMutationResult result, MutationCode code, CreateTableStatement statement, String schemaName, String tableName, PTable parent) throws SQLException { switch(code) { case TABLE_ALREADY_EXISTS: if(result.getTable() != null) { addTableToCache(result); } if(!statement.ifNotExists()) { throw new TableAlreadyExistsException(schemaName, tableName, result.getTable()); } return true; case NEWER_TABLE_FOUND: if (!statement.ifNotExists()) { throw new NewerTableAlreadyExistsException(schemaName, tableName, result.getTable()); } return false; case UNALLOWED_TABLE_MUTATION: throwsSQLExceptionUtil("CANNOT_MUTATE_TABLE",schemaName,tableName); case CONCURRENT_TABLE_MUTATION: addTableToCache(result); throw new ConcurrentTableMutationException(schemaName, tableName); case AUTO_PARTITION_SEQUENCE_NOT_FOUND: throw new SQLExceptionInfo.Builder(SQLExceptionCode.AUTO_PARTITION_SEQUENCE_UNDEFINED) .setSchemaName(schemaName).setTableName(tableName).build().buildException(); case CANNOT_COERCE_AUTO_PARTITION_ID: case UNABLE_TO_CREATE_CHILD_LINK: case PARENT_TABLE_NOT_FOUND: case TABLE_NOT_IN_REGION: throwsSQLExceptionUtil(String.valueOf(code), schemaName, tableName); case TOO_MANY_INDEXES: case UNABLE_TO_UPDATE_PARENT_TABLE: throwsSQLExceptionUtil(String.valueOf(code), SchemaUtil.getSchemaNameFromFullName( parent.getPhysicalName().getString()),SchemaUtil.getTableNameFromFullName( parent.getPhysicalName().getString())); default: throw new SQLExceptionInfo.Builder(SQLExceptionCode.UNEXPECTED_MUTATION_CODE) .setSchemaName(schemaName).setTableName(tableName).setMessage("mutation code: " + code).build().buildException(); } } MetaDataClient(PhoenixConnection connection); PhoenixConnection getConnection(); long getCurrentTime(String schemaName, String tableName); MetaDataMutationResult updateCache(String schemaName, String tableName); MetaDataMutationResult updateCache(String schemaName, String tableName,
            boolean alwaysHitServer); MetaDataMutationResult updateCache(PName tenantId, String schemaName, String tableName, boolean alwaysHitServer); MetaDataMutationResult updateCache(List<String> functionNames); MetaDataMutationResult updateCache(PName tenantId, List<String> functionNames); MetaDataMutationResult updateCache(PName origTenantId, String schemaName, String tableName,
            boolean alwaysHitServer, Long resolvedTimestamp); MetaDataMutationResult updateCache(String schemaName); MetaDataMutationResult updateCache(String schemaName, boolean alwaysHitServer); MetaDataMutationResult updateCache(PName tenantId, List<String> functionNames,
            boolean alwaysHitServer); MutationState createTable(CreateTableStatement statement, byte[][] splits, PTable parent, String viewStatement, ViewType viewType, PDataType viewIndexIdType, byte[][] viewColumnConstants, BitSet isViewColumnReferenced); MutationState updateStatistics(UpdateStatisticsStatement updateStatisticsStmt); MutationState declareCursor(DeclareCursorStatement statement, QueryPlan queryPlan); MutationState open(OpenStatement statement); MutationState close(CloseStatement statement); MutationState createIndex(CreateIndexStatement statement, byte[][] splits); MutationState dropSequence(DropSequenceStatement statement); MutationState createSequence(CreateSequenceStatement statement, long startWith,
            long incrementBy, long cacheSize, long minValue, long maxValue); MutationState createFunction(CreateFunctionStatement stmt); @VisibleForTesting boolean handleCreateTableMutationCode(MetaDataMutationResult result, MutationCode code,
                 CreateTableStatement statement, String schemaName, String tableName,
                 PTable parent); MutationState dropTable(DropTableStatement statement); MutationState dropFunction(DropFunctionStatement statement); MutationState dropIndex(DropIndexStatement statement); MutationState addColumn(AddColumnStatement statement); MutationState addColumn(PTable table, List<ColumnDef> origColumnDefs,
            ListMultimap<String, Pair<String, Object>> stmtProperties, boolean ifNotExists,
            boolean removeTableProps, NamedTableNode namedTableNode, PTableType tableType, boolean cascade, List<NamedNode> indexes); MutationState dropColumn(DropColumnStatement statement); MutationState alterIndex(AlterIndexStatement statement); MutationState createSchema(CreateSchemaStatement create); MutationState dropSchema(DropSchemaStatement executableDropSchemaStatement); MutationState useSchema(UseSchemaStatement useSchemaStatement); MutationState changePermissions(ChangePermsStatement changePermsStatement); static final String CREATE_VIEW_LINK; static final String UPDATE_ENCODED_COLUMN_COUNTER; static final String MUTATE_TABLE; static final String UPDATE_INDEX_STATE; static final String EMPTY_TABLE; }