Search in sources :

Example 1 with UpdateById

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));
}
Also used : UpdateById(io.crate.planner.node.dml.UpdateById) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 2 with UpdateById

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));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) WhereClauseOptimizer(io.crate.planner.WhereClauseOptimizer) UpdateById(io.crate.planner.node.dml.UpdateById)

Example 3 with UpdateById

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"));
}
Also used : UpdateById(io.crate.planner.node.dml.UpdateById) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 4 with UpdateById

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));
}
Also used : LogicalPlan(io.crate.planner.operators.LogicalPlan) UpdateById(io.crate.planner.node.dml.UpdateById) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

UpdateById (io.crate.planner.node.dml.UpdateById)4 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)3 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)3 Test (org.junit.Test)3 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1 WhereClauseOptimizer (io.crate.planner.WhereClauseOptimizer)1 LogicalPlan (io.crate.planner.operators.LogicalPlan)1