use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class SymbolPrinterTest method prepare.
@Before
public void prepare() throws Exception {
String createTableStmt = "create table doc.formatter (" + " foo text," + " bar bigint," + " \"CraZy\" ip," + " \"1a\" int," + " \"select\" char," + " idx int," + " s_arr array(text)" + ")";
RelationName name = new RelationName(DocSchemaInfo.NAME, TABLE_NAME);
DocTableInfo tableInfo = SQLExecutor.tableInfo(name, createTableStmt, clusterService);
Map<RelationName, AnalyzedRelation> sources = Map.of(name, new TableRelation(tableInfo));
sqlExpressions = new SqlExpressions(sources);
}
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 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);
}
Aggregations