use of io.crate.types.ObjectType in project crate by crate.
the class DataTypeTest method test_is_compatible_type_on_nested_types_with_different_names_same_inner_types.
@Test
public void test_is_compatible_type_on_nested_types_with_different_names_same_inner_types() {
ObjectType obj1 = ObjectType.builder().setInnerType("obj1", ObjectType.builder().setInnerType("a", DataTypes.INTEGER).build()).build();
ObjectType obj2 = ObjectType.builder().setInnerType("obj2", ObjectType.builder().setInnerType("a", DataTypes.INTEGER).build()).build();
assertThat(DataTypes.isCompatibleType(obj1, obj2), is(true));
ObjectType obj3 = ObjectType.builder().setInnerType("obj", ObjectType.builder().setInnerType("a", DataTypes.INTEGER).build()).build();
ObjectType obj4 = ObjectType.builder().setInnerType("obj", ObjectType.builder().setInnerType("b", DataTypes.INTEGER).build()).build();
assertThat(DataTypes.isCompatibleType(obj3, obj4), is(true));
}
use of io.crate.types.ObjectType in project crate by crate.
the class DataTypeTest method test_is_compatible_type_with_different_names_same_inner_types.
@Test
public void test_is_compatible_type_with_different_names_same_inner_types() {
ObjectType obj1 = ObjectType.builder().setInnerType("a", DataTypes.STRING).build();
ObjectType obj2 = ObjectType.builder().setInnerType("b", DataTypes.STRING).build();
assertThat(DataTypes.isCompatibleType(obj1, obj2), is(true));
}
use of io.crate.types.ObjectType in project crate by crate.
the class Literal method typeMatchesValue.
private static <T> boolean typeMatchesValue(DataType<T> type, T value) {
if (value == null) {
return true;
}
if (type.id() == ObjectType.ID) {
// noinspection unchecked
Map<String, Object> mapValue = (Map<String, Object>) value;
ObjectType objectType = ((ObjectType) type);
for (String key : mapValue.keySet()) {
DataType<?> innerType = objectType.innerType(key);
// noinspection unchecked
if (typeMatchesValue((DataType<Object>) innerType, mapValue.get(key)) == false) {
return false;
}
}
// lets do the expensive "deep" map value conversion only after everything else succeeded
Map<String, Object> safeValue = objectType.sanitizeValue(value);
return safeValue.size() == mapValue.size();
}
return Objects.equals(type.sanitizeValue(value), value);
}
use of io.crate.types.ObjectType in project crate by crate.
the class DocIndexMetadataTest method test_resolve_inner_object_types.
@Test
public void test_resolve_inner_object_types() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("properties").startObject("object").field("type", "object").startObject("properties").startObject("nestedObject").field("type", "object").startObject("properties").startObject("nestedNestedString").field("type", "string").endObject().endObject().endObject().startObject("nestedString").field("type", "string").endObject().endObject().endObject().endObject().endObject().endObject();
IndexMetadata metadata = getIndexMetadata("test", builder);
DocIndexMetadata md = newMeta(metadata, "test");
ObjectType objectType = (ObjectType) md.references().get(new ColumnIdent("object")).valueType();
assertThat(objectType.resolveInnerType(List.of("nestedString")), is(DataTypes.STRING));
assertThat(objectType.resolveInnerType(List.of("nestedObject")).id(), is(ObjectType.ID));
assertThat(objectType.resolveInnerType(List.of("nestedObject", "nestedNestedString")), is(DataTypes.STRING));
}
Aggregations