use of io.crate.types.ArrayType in project crate by crate.
the class DataTypeTest method testForValueWithArrayWithNullValues.
@Test
public void testForValueWithArrayWithNullValues() {
DataType dataType = DataTypes.guessType(new String[] { "foo", null, "bar" });
assertEquals(dataType, new ArrayType(DataTypes.STRING));
}
use of io.crate.types.ArrayType in project crate by crate.
the class LiteralTest method testNestedArrayLiteral.
@Test
public void testNestedArrayLiteral() throws Exception {
for (DataType<?> type : DataTypes.PRIMITIVE_TYPES) {
DataType<?> nestedType = new ArrayType<>(new ArrayType<>(type));
Object value;
if (type.id() == BooleanType.ID) {
value = true;
} else if (type.id() == DataTypes.IP.id()) {
value = type.sanitizeValue("123.34.243.23");
} else if (type.id() == DataTypes.INTERVAL.id()) {
value = type.sanitizeValue(new Period().withSeconds(100));
} else {
value = type.implicitCast("0");
}
var nestedValue = List.of(List.of(value));
Literal<?> nestedLiteral = Literal.ofUnchecked(nestedType, nestedValue);
assertThat(nestedLiteral.valueType(), is(nestedType));
assertThat(nestedLiteral.value(), is(nestedValue));
}
}
use of io.crate.types.ArrayType in project crate by crate.
the class UpdateAnalyzerTest method testUpdateDynamicNestedArrayParamLiteral.
@Test
public void testUpdateDynamicNestedArrayParamLiteral() throws Exception {
AnalyzedUpdateStatement update = analyze("update users set new=[[1.9, 4.8], [9.7, 12.7]]");
DataType dataType = update.assignmentByTargetCol().values().iterator().next().valueType();
assertThat(dataType, is(new ArrayType(new ArrayType(DoubleType.INSTANCE))));
}
use of io.crate.types.ArrayType 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.types.ArrayType 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));
}
Aggregations