use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class UpdateAnalyzerTest method testUpdateInvalidType.
@Test
public void testUpdateInvalidType() throws Exception {
Object[] params = { new Object[] { new Object[] { "a", "b" } } };
AnalyzedUpdateStatement update = analyze("update users set tags=? where id=1");
expectedException.expect(ConversionException.class);
expectedException.expectMessage("Cannot cast value `[[a, b]]` to type `text_array`");
Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
assignments.bindSources(((DocTableInfo) update.table().tableInfo()), new RowN(params), SubQueryResults.EMPTY);
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class UpdateAnalyzerTest method testUpdateDynamicNestedArrayParam.
@Test
public void testUpdateDynamicNestedArrayParam() throws Exception {
Object[] params = { new Object[] { new Object[] { 1.9, 4.8 }, new Object[] { 9.7, 12.7 } } };
AnalyzedUpdateStatement update = analyze("update users set new=? where id=1");
Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
Symbol[] sources = assignments.bindSources(((DocTableInfo) update.table().tableInfo()), new RowN(params), SubQueryResults.EMPTY);
DataType dataType = sources[0].valueType();
assertThat(dataType, is(new ArrayType(new ArrayType(DoubleType.INSTANCE))));
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class UpdateAnalyzerTest method testUpdateWithEmptyObjectArray.
@Test
public void testUpdateWithEmptyObjectArray() throws Exception {
Object[] params = { new Map[0], 0 };
AnalyzedUpdateStatement update = analyze("update users set friends=? where other_id=0");
Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
Symbol[] sources = assignments.bindSources(((DocTableInfo) update.table().tableInfo()), new RowN(params), SubQueryResults.EMPTY);
assertThat(sources[0].valueType().id(), is(ArrayType.ID));
assertThat(((ArrayType) sources[0].valueType()).innerType().id(), is(ObjectType.ID));
assertThat(((List) ((Literal) sources[0]).value()).size(), is(0));
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class UpdateAnalyzerTest method testUpdateAssignmentConvertableType.
@Test
public void testUpdateAssignmentConvertableType() throws Exception {
AnalyzedUpdateStatement update = analyze("update users set other_id=9.9");
Reference ref = update.assignmentByTargetCol().keySet().iterator().next();
assertThat(ref, not(instanceOf(DynamicReference.class)));
assertEquals(DataTypes.LONG, ref.valueType());
Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
Symbol[] sources = assignments.bindSources(((DocTableInfo) update.table().tableInfo()), Row.EMPTY, SubQueryResults.EMPTY);
assertThat(sources[0], isLiteral(9L));
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class DocTableRelationTest method testUpdatingCompoundPrimaryKeyThrowsCorrectException.
@Test
public void testUpdatingCompoundPrimaryKeyThrowsCorrectException() {
DocTableInfo tableInfo = SQLExecutor.tableInfo(new RelationName("doc", "t1"), "create table doc.t1 (i int, j int, primary key (i, j))", clusterService);
DocTableRelation rel = new DocTableRelation(tableInfo);
expectedException.expect(ColumnValidationException.class);
expectedException.expectMessage("Validation failed for i: Updating a primary key is not supported");
rel.ensureColumnCanBeUpdated(new ColumnIdent("i"));
}
Aggregations