Search in sources :

Example 1 with ObjectType

use of io.crate.types.ObjectType in project crate by crate.

the class SubscriptObjectFunction method tryToInferReturnTypeFromObjectTypeAndArguments.

static Symbol tryToInferReturnTypeFromObjectTypeAndArguments(Function func) {
    if (!func.valueType().equals(DataTypes.UNDEFINED)) {
        return func;
    }
    var arguments = func.arguments();
    ObjectType objectType = (ObjectType) arguments.get(0).valueType();
    List<String> path = maybeCreatePath(arguments);
    if (path == null) {
        return func;
    } else {
        DataType<?> returnType = objectType.resolveInnerType(path);
        return returnType.equals(DataTypes.UNDEFINED) ? func : new Function(func.signature(), func.arguments(), returnType);
    }
}
Also used : ObjectType(io.crate.types.ObjectType) Function(io.crate.expression.symbol.Function)

Example 2 with ObjectType

use of io.crate.types.ObjectType in project crate by crate.

the class DataTypeTest method test_is_compatible_type_with_same_names_same_inner_types.

@Test
public void test_is_compatible_type_with_same_names_same_inner_types() {
    ObjectType obj1 = ObjectType.builder().setInnerType("a", DataTypes.STRING).build();
    ObjectType obj2 = ObjectType.builder().setInnerType("a", DataTypes.STRING).build();
    assertThat(DataTypes.isCompatibleType(obj1, obj2), is(true));
}
Also used : ObjectType(io.crate.types.ObjectType) Test(org.junit.Test)

Example 3 with ObjectType

use of io.crate.types.ObjectType in project crate by crate.

the class DataTypeTest method test_is_compatible_type_on_nested_types_with_same_names_same_inner_types.

@Test
public void test_is_compatible_type_on_nested_types_with_same_names_same_inner_types() {
    ObjectType obj1 = ObjectType.builder().setInnerType("obj", ObjectType.builder().setInnerType("a", DataTypes.INTEGER).build()).build();
    ObjectType obj2 = ObjectType.builder().setInnerType("obj", ObjectType.builder().setInnerType("a", DataTypes.INTEGER).build()).build();
    assertThat(DataTypes.isCompatibleType(obj1, obj2), is(true));
}
Also used : ObjectType(io.crate.types.ObjectType) Test(org.junit.Test)

Example 4 with ObjectType

use of io.crate.types.ObjectType in project crate by crate.

the class DataTypeTest method test_is_compatible_type_on_nested_types_with_same_names_different_inner_types.

@Test
public void test_is_compatible_type_on_nested_types_with_same_names_different_inner_types() {
    ObjectType obj1 = ObjectType.builder().setInnerType("obj", ObjectType.builder().setInnerType("a", DataTypes.INTEGER).build()).build();
    ObjectType obj2 = ObjectType.builder().setInnerType("obj", ObjectType.builder().setInnerType("a", DataTypes.STRING).build()).build();
    assertThat(DataTypes.isCompatibleType(obj1, obj2), is(false));
}
Also used : ObjectType(io.crate.types.ObjectType) Test(org.junit.Test)

Example 5 with ObjectType

use of io.crate.types.ObjectType in project crate by crate.

the class DataTypeTest method test_is_compatible_type_with_same_names_different_inner_types.

@Test
public void test_is_compatible_type_with_same_names_different_inner_types() {
    ObjectType obj1 = ObjectType.builder().setInnerType("a", DataTypes.INTEGER).build();
    ObjectType obj2 = ObjectType.builder().setInnerType("a", DataTypes.STRING).build();
    assertThat(DataTypes.isCompatibleType(obj1, obj2), is(false));
}
Also used : ObjectType(io.crate.types.ObjectType) Test(org.junit.Test)

Aggregations

ObjectType (io.crate.types.ObjectType)9 Test (org.junit.Test)7 Function (io.crate.expression.symbol.Function)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1 DataType (io.crate.types.DataType)1 Map (java.util.Map)1 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1