Search in sources :

Example 1 with Mapper

use of org.elasticsearch.index.mapper.Mapper in project crate by crate.

the class TransportShardUpsertActionTest method testValidateMapping.

@Test
public void testValidateMapping() throws Exception {
    // Create valid nested mapping with underscore.
    Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build();
    Mapper.BuilderContext builderContext = new Mapper.BuilderContext(settings, new ContentPath());
    Mapper outerMapper = new ObjectMapper.Builder("valid").add(new ObjectMapper.Builder("_invalid")).build(builderContext);
    TransportShardUpsertAction.validateMapping(Arrays.asList(outerMapper).iterator(), false);
    // Create invalid mapping
    expectedException.expect(InvalidColumnNameException.class);
    expectedException.expectMessage("system column pattern");
    outerMapper = new ObjectMapper.Builder("_invalid").build(builderContext);
    TransportShardUpsertAction.validateMapping(Arrays.asList(outerMapper).iterator(), false);
}
Also used : ObjectMapper(org.elasticsearch.index.mapper.ObjectMapper) Mapper(org.elasticsearch.index.mapper.Mapper) ContentPath(org.elasticsearch.index.mapper.ContentPath) SessionSettings(io.crate.metadata.settings.SessionSettings) Settings(org.elasticsearch.common.settings.Settings) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 2 with Mapper

use of org.elasticsearch.index.mapper.Mapper in project crate by crate.

the class TransportShardUpsertActionTest method testValidateMapping.

@Test
public void testValidateMapping() throws Exception {
    /**
         * create a mapping which contains an invalid column name
         * {
         *      "valid": {},
         *      "_invalid": {}
         * }
         */
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Column name must not start with '_'");
    Mapper.BuilderContext builderContext = new Mapper.BuilderContext(null, new ContentPath());
    Mapper.Builder validInnerMapper = new ObjectMapper.Builder("valid");
    Mapper.Builder invalidInnerMapper = new ObjectMapper.Builder("_invalid");
    Mapper outerMapper = new ObjectMapper.Builder("outer").add(validInnerMapper).add(invalidInnerMapper).build(builderContext);
    TransportShardUpsertAction.validateMapping(Arrays.asList(outerMapper).iterator());
}
Also used : ObjectMapper(org.elasticsearch.index.mapper.object.ObjectMapper) Mapper(org.elasticsearch.index.mapper.Mapper) MapBuilder(org.elasticsearch.common.collect.MapBuilder) ContentPath(org.elasticsearch.index.mapper.ContentPath) ObjectMapper(org.elasticsearch.index.mapper.object.ObjectMapper) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with Mapper

use of org.elasticsearch.index.mapper.Mapper in project crate by crate.

the class TransportShardUpsertAction method validateMapping.

@VisibleForTesting
static void validateMapping(Iterator<Mapper> mappers) {
    while (mappers.hasNext()) {
        Mapper mapper = mappers.next();
        AnalyzedColumnDefinition.validateName(mapper.simpleName());
        validateMapping(mapper.iterator());
    }
}
Also used : ParentFieldMapper(org.elasticsearch.index.mapper.internal.ParentFieldMapper) Mapper(org.elasticsearch.index.mapper.Mapper) RoutingFieldMapper(org.elasticsearch.index.mapper.internal.RoutingFieldMapper) TTLFieldMapper(org.elasticsearch.index.mapper.internal.TTLFieldMapper) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with Mapper

use of org.elasticsearch.index.mapper.Mapper in project crate by crate.

the class TransportShardAction method validateMapping.

@VisibleForTesting
public static void validateMapping(Iterator<Mapper> mappers, boolean nested) {
    while (mappers.hasNext()) {
        Mapper mapper = mappers.next();
        if (nested) {
            ColumnIdent.validateObjectKey(mapper.simpleName());
        } else {
            ColumnIdent.validateColumnName(mapper.simpleName());
        }
        validateMapping(mapper.iterator(), true);
    }
}
Also used : Mapper(org.elasticsearch.index.mapper.Mapper) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Aggregations

Mapper (org.elasticsearch.index.mapper.Mapper)4 ContentPath (org.elasticsearch.index.mapper.ContentPath)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)1 SessionSettings (io.crate.metadata.settings.SessionSettings)1 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1 CrateUnitTest (io.crate.test.integration.CrateUnitTest)1 MapBuilder (org.elasticsearch.common.collect.MapBuilder)1 Settings (org.elasticsearch.common.settings.Settings)1 ObjectMapper (org.elasticsearch.index.mapper.ObjectMapper)1 ParentFieldMapper (org.elasticsearch.index.mapper.internal.ParentFieldMapper)1 RoutingFieldMapper (org.elasticsearch.index.mapper.internal.RoutingFieldMapper)1 TTLFieldMapper (org.elasticsearch.index.mapper.internal.TTLFieldMapper)1 ObjectMapper (org.elasticsearch.index.mapper.object.ObjectMapper)1