}
public MutationPlan compile(DeleteStatement delete) throws SQLException {
final PhoenixConnection connection = statement.getConnection();
final boolean isAutoCommit = connection.getAutoCommit();
final ConnectionQueryServices services = connection.getQueryServices();
final ColumnResolver resolver = FromCompiler.getResolver(delete, connection);
final TableRef tableRef = resolver.getTables().get(0);
if (tableRef.getTable().getType() == PTableType.VIEW) {
throw new ReadOnlyTableException("Mutations not allowed for a view (" + tableRef.getTable() + ")");
}
final boolean hasLimit = delete.getLimit() != null;
boolean runOnServer = isAutoCommit && !hasLimit && !hasImmutableIndex(tableRef);
HintNode hint = delete.getHint();
if (runOnServer && !delete.getHint().hasHint(Hint.USE_INDEX_OVER_DATA_TABLE)) {
hint = HintNode.create(hint, Hint.USE_DATA_OVER_INDEX_TABLE);
}
PTable table = tableRef.getTable();
List<AliasedNode> aliasedNodes = Lists.newArrayListWithExpectedSize(table.getPKColumns().size());
for (int i = table.getBucketNum() == null ? 0 : 1; i < table.getPKColumns().size(); i++) {
PColumn column = table.getPKColumns().get(i);
String name = column.getName().getString();
aliasedNodes.add(FACTORY.aliasedNode(null, FACTORY.column(null, name, name)));
}
SelectStatement select = FACTORY.select(
Collections.singletonList(delete.getTable()),
hint, false, aliasedNodes, delete.getWhere(),
Collections.<ParseNode>emptyList(), null,
delete.getOrderBy(), delete.getLimit(),
delete.getBindCount(), false);
DeletingParallelIteratorFactory parallelIteratorFactory = hasLimit ? null : new DeletingParallelIteratorFactory(connection, tableRef);
final QueryPlan plan = new QueryOptimizer(services).optimize(select, statement, Collections.<PColumn>emptyList(), parallelIteratorFactory);
runOnServer &= plan.getTableRef().equals(tableRef);
final int maxSize = services.getProps().getInt(QueryServices.MAX_MUTATION_SIZE_ATTRIB,QueryServicesOptions.DEFAULT_MAX_MUTATION_SIZE);
if (hasImmutableIndexWithKeyValueColumns(tableRef)) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.NO_DELETE_IF_IMMUTABLE_INDEX).setSchemaName(tableRef.getTable().getSchemaName().getString())
.setTableName(tableRef.getTable().getTableName().getString()).build().buildException();
}