use of io.crate.expression.reference.Doc in project crate by crate.
the class UpdateSourceGenTest method testNestedGeneratedColumnRaiseErrorIfGivenByUserDoesNotMatch.
@Test
public void testNestedGeneratedColumnRaiseErrorIfGivenByUserDoesNotMatch() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table t (x int, obj object as (y as 'foo'))").build();
AnalyzedUpdateStatement update = e.analyze("update t set x = 4, obj = {y='bar'}");
Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
DocTableInfo table = (DocTableInfo) update.table().tableInfo();
UpdateSourceGen updateSourceGen = new UpdateSourceGen(txnCtx, e.nodeCtx, table, assignments.targetNames());
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Given value bar for generated column obj['y'] does not match calculation 'foo' = foo");
updateSourceGen.generateSource(new Doc(1, table.concreteIndices()[0], "1", 1, 1, 1, emptyMap(), () -> "{}"), assignments.sources(), new Object[0]);
}
use of io.crate.expression.reference.Doc in project crate by crate.
the class UpdateSourceGenTest method testNestedGeneratedColumnIsGenerated.
@Test
public void testNestedGeneratedColumnIsGenerated() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table t (x int, obj object as (y as x + 1))").build();
AnalyzedUpdateStatement update = e.analyze("update t set x = 4");
Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
DocTableInfo table = (DocTableInfo) update.table().tableInfo();
UpdateSourceGen updateSourceGen = new UpdateSourceGen(txnCtx, e.nodeCtx, table, assignments.targetNames());
Map<String, Object> updatedSource = updateSourceGen.generateSource(new Doc(1, table.concreteIndices()[0], "1", 1, 1, 1, emptyMap(), () -> "{}"), assignments.sources(), new Object[0]);
assertThat(updatedSource, is(Map.of("obj", Map.of("y", 5), "x", 4)));
}
use of io.crate.expression.reference.Doc in project crate by crate.
the class DocRefResolverTest method testSystemColumnsCollectExpressions.
@Test
public void testSystemColumnsCollectExpressions() throws Exception {
List<Reference> references = List.of(refInfo("t1._id", DocSysColumns.COLUMN_IDENTS.get(DocSysColumns.ID), RowGranularity.DOC), refInfo("t1._version", DocSysColumns.COLUMN_IDENTS.get(DocSysColumns.VERSION), RowGranularity.DOC), refInfo("t1._doc", DocSysColumns.COLUMN_IDENTS.get(DocSysColumns.DOC), RowGranularity.DOC), refInfo("t1._raw", DocSysColumns.COLUMN_IDENTS.get(DocSysColumns.RAW), RowGranularity.DOC), refInfo("t1._docid", DocSysColumns.COLUMN_IDENTS.get(DocSysColumns.DOCID), RowGranularity.DOC), refInfo("t1._seq_no", DocSysColumns.COLUMN_IDENTS.get(DocSysColumns.SEQ_NO), RowGranularity.DOC), refInfo("t1._primary_term", DocSysColumns.COLUMN_IDENTS.get(DocSysColumns.PRIMARY_TERM), RowGranularity.DOC));
List<CollectExpression<Doc, ?>> collectExpressions = new ArrayList<>(4);
for (Reference reference : references) {
CollectExpression<Doc, ?> collectExpression = REF_RESOLVER.getImplementation(reference);
collectExpression.setNextRow(GET_RESULT);
collectExpressions.add(collectExpression);
}
assertThat(collectExpressions.get(0).value(), is("abc"));
assertThat(collectExpressions.get(1).value(), is(1L));
assertThat(collectExpressions.get(2).value(), is(XContentHelper.convertToMap(SOURCE, false, XContentType.JSON).v2()));
assertThat(collectExpressions.get(3).value(), is(SOURCE.utf8ToString()));
assertThat(collectExpressions.get(4).value(), is(2));
assertThat(collectExpressions.get(5).value(), is(1L));
assertThat(collectExpressions.get(6).value(), is(1L));
}
Aggregations