use of io.crate.planner.NoopPlan in project crate by crate.
the class DeleteStatementPlanner method deleteByQuery.
private static Plan deleteByQuery(DocTableInfo tableInfo, List<WhereClause> whereClauses, Planner.Context context) {
List<Plan> planNodes = new ArrayList<>();
List<String> indicesToDelete = new ArrayList<>();
for (WhereClause whereClause : whereClauses) {
String[] indices = Planner.indices(tableInfo, whereClause);
if (indices.length > 0) {
if (!whereClause.hasQuery() && tableInfo.isPartitioned()) {
indicesToDelete.addAll(Arrays.asList(indices));
} else {
planNodes.add(collectWithDeleteProjection(tableInfo, whereClause, context));
}
}
}
if (!indicesToDelete.isEmpty()) {
assert planNodes.isEmpty() : "If a partition can be deleted that must be true for all bulk operations";
return new ESDeletePartition(context.jobId(), indicesToDelete.toArray(new String[0]));
}
if (planNodes.isEmpty()) {
return new NoopPlan(context.jobId());
}
return new Delete(planNodes, context.jobId());
}
use of io.crate.planner.NoopPlan in project crate by crate.
the class ESGetStatementPlanner method convert.
public static Plan convert(QueriedDocTable table, Planner.Context context) {
QuerySpec querySpec = table.querySpec();
Optional<DocKeys> optKeys = querySpec.where().docKeys();
assert !querySpec.hasAggregates() : "Can't create ESGet plan for queries with aggregates";
assert !querySpec.groupBy().isPresent() : "Can't create ESGet plan for queries with group by";
assert optKeys.isPresent() : "Can't create ESGet without docKeys";
DocTableInfo tableInfo = table.tableRelation().tableInfo();
DocKeys docKeys = optKeys.get();
if (docKeys.withVersions()) {
throw new VersionInvalidException();
}
Limits limits = context.getLimits(querySpec);
if (limits.hasLimit() && limits.finalLimit() == 0) {
return new NoopPlan(context.jobId());
}
table.tableRelation().validateOrderBy(querySpec.orderBy());
return new ESGet(context.nextExecutionPhaseId(), tableInfo, querySpec.outputs(), optKeys.get(), querySpec.orderBy(), limits.finalLimit(), limits.offset(), context.jobId());
}
use of io.crate.planner.NoopPlan in project crate by crate.
the class DeleteStatementPlanner method planDelete.
public static Plan planDelete(DeleteAnalyzedStatement analyzedStatement, Planner.Context context) {
DocTableRelation tableRelation = analyzedStatement.analyzedRelation();
List<WhereClause> whereClauses = new ArrayList<>(analyzedStatement.whereClauses().size());
List<DocKeys.DocKey> docKeys = new ArrayList<>(analyzedStatement.whereClauses().size());
Map<Integer, Integer> itemToBulkIdx = new HashMap<>();
int bulkIdx = -1;
int itemIdx = 0;
for (WhereClause whereClause : analyzedStatement.whereClauses()) {
bulkIdx++;
if (whereClause.noMatch()) {
continue;
}
if (whereClause.docKeys().isPresent() && whereClause.docKeys().get().size() == 1) {
DocKeys.DocKey docKey = whereClause.docKeys().get().getOnlyKey();
if (docKey.id() != null) {
docKeys.add(docKey);
itemToBulkIdx.put(itemIdx, bulkIdx);
itemIdx++;
}
} else if (!whereClause.noMatch()) {
whereClauses.add(whereClause);
}
}
if (!docKeys.isEmpty()) {
return new ESDelete(context.jobId(), context.nextExecutionPhaseId(), tableRelation.tableInfo(), docKeys, itemToBulkIdx, analyzedStatement.whereClauses().size());
} else if (!whereClauses.isEmpty()) {
return deleteByQuery(tableRelation.tableInfo(), whereClauses, context);
}
return new NoopPlan(context.jobId());
}
Aggregations