use of io.crate.planner.node.dml.UpdateById in project crate by crate.
the class UpdatePlannerTest method testUpdatePlanWithMultiplePrimaryKeyValues.
@Test
public void testUpdatePlanWithMultiplePrimaryKeyValues() throws Exception {
UpdateById update = e.plan("update users set name='Vogon lyric fan' where id in (1,2,3)");
assertThat(update.docKeys().size(), is(3));
}
use of io.crate.planner.node.dml.UpdateById in project crate by crate.
the class UpdatePlanner method plan.
private static Plan plan(DocTableRelation docTable, Map<Reference, Symbol> assignmentByTargetCol, Symbol query, PlannerContext plannerCtx, @Nullable List<Symbol> returnValues) {
EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(plannerCtx.nodeContext());
DocTableInfo tableInfo = docTable.tableInfo();
WhereClauseOptimizer.DetailedQuery detailedQuery = WhereClauseOptimizer.optimize(normalizer, query, tableInfo, plannerCtx.transactionContext(), plannerCtx.nodeContext());
if (detailedQuery.docKeys().isPresent()) {
return new UpdateById(tableInfo, assignmentByTargetCol, detailedQuery.docKeys().get(), returnValues, plannerCtx.nodeContext());
}
return new Update((plannerContext, params, subQueryValues) -> updateByQuery(plannerContext, docTable, assignmentByTargetCol, detailedQuery, params, subQueryValues, returnValues));
}
use of io.crate.planner.node.dml.UpdateById in project crate by crate.
the class UpdatePlannerTest method testUpdateByIdPlan.
@Test
public void testUpdateByIdPlan() throws Exception {
UpdateById updateById = e.plan("update users set name='Vogon lyric fan' where id=1");
assertThat(updateById.assignmentByTargetCol().keySet(), contains(isReference("name")));
assertThat(updateById.assignmentByTargetCol().values(), contains(isLiteral("Vogon lyric fan")));
assertThat(updateById.docKeys().size(), is(1));
assertThat(updateById.docKeys().getOnlyKey().getId(txnCtx, e.nodeCtx, Row.EMPTY, SubQueryResults.EMPTY), is("1"));
}
use of io.crate.planner.node.dml.UpdateById in project crate by crate.
the class UpdatePlannerTest method testUpdatePlanWithMultiplePrimaryKeyValuesPartitioned.
@Test
public void testUpdatePlanWithMultiplePrimaryKeyValuesPartitioned() throws Exception {
Plan update = e.plan("update parted_pks set name='Vogon lyric fan' where " + "(id=2 and date = 0) OR" + "(id=3 and date=123)");
assertThat(update, instanceOf(UpdateById.class));
assertThat(((UpdateById) update).docKeys().size(), is(2));
}
Aggregations