Search in sources :

Example 61 with Multimap

use of com.google.common.collect.Multimap in project janusgraph by JanusGraph.

the class ElasticSearchIndex method getNewDocument.

public Map<String, Object> getNewDocument(final List<IndexEntry> additions, KeyInformation.StoreRetriever information) throws BackendException {
    // JSON writes duplicate fields one after another, which forces us
    // at this stage to make de-duplication on the IndexEntry list. We don't want to pay the
    // price map storage on the Mutation level because none of other backends need that.
    final Multimap<String, IndexEntry> unique = LinkedListMultimap.create();
    for (final IndexEntry e : additions) {
        unique.put(e.field, e);
    }
    final Map<String, Object> doc = new HashMap<>();
    for (final Map.Entry<String, Collection<IndexEntry>> add : unique.asMap().entrySet()) {
        final KeyInformation keyInformation = information.get(add.getKey());
        final Object value;
        switch(keyInformation.getCardinality()) {
            case SINGLE:
                value = convertToEsType(Iterators.getLast(add.getValue().iterator()).value, Mapping.getMapping(keyInformation));
                break;
            case SET:
            case LIST:
                value = add.getValue().stream().map(v -> convertToEsType(v.value, Mapping.getMapping(keyInformation))).filter(v -> {
                    Preconditions.checkArgument(!(v instanceof byte[]), "Collections not supported for " + add.getKey());
                    return true;
                }).toArray();
                break;
            default:
                value = null;
                break;
        }
        doc.put(add.getKey(), value);
        if (hasDualStringMapping(information.get(add.getKey())) && keyInformation.getDataType() == String.class) {
            doc.put(getDualMappingName(add.getKey()), value);
        }
    }
    return doc;
}
Also used : PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) INDEX_MAX_RESULT_SET_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_MAX_RESULT_SET_SIZE) StringUtils(org.apache.commons.lang.StringUtils) Date(java.util.Date) Spliterators(java.util.Spliterators) LoggerFactory(org.slf4j.LoggerFactory) ConfigOption(org.janusgraph.diskstorage.configuration.ConfigOption) Geoshape(org.janusgraph.core.attribute.Geoshape) AbstractESCompat(org.janusgraph.diskstorage.es.compat.AbstractESCompat) BaseTransaction(org.janusgraph.diskstorage.BaseTransaction) IndexProvider(org.janusgraph.diskstorage.indexing.IndexProvider) Cardinality(org.janusgraph.core.Cardinality) IndexEntry(org.janusgraph.diskstorage.indexing.IndexEntry) KeyInformation(org.janusgraph.diskstorage.indexing.KeyInformation) AttributeUtil(org.janusgraph.graphdb.database.serialize.AttributeUtil) Map(java.util.Map) IndexQuery(org.janusgraph.diskstorage.indexing.IndexQuery) SerializationFeature(org.apache.tinkerpop.shaded.jackson.databind.SerializationFeature) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) ES6Compat(org.janusgraph.diskstorage.es.compat.ES6Compat) And(org.janusgraph.graphdb.query.condition.And) Mapping(org.janusgraph.core.schema.Mapping) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ES_GEO_COORDS_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_GEO_COORDS_KEY) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) List(java.util.List) INDEX_NAME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_NAME) Parameter(org.janusgraph.core.schema.Parameter) Stream(java.util.stream.Stream) ObjectWriter(org.apache.tinkerpop.shaded.jackson.databind.ObjectWriter) HttpAuthTypes(org.janusgraph.diskstorage.es.rest.util.HttpAuthTypes) Spliterator(java.util.Spliterator) PreInitializeConfigOptions(org.janusgraph.graphdb.configuration.PreInitializeConfigOptions) Not(org.janusgraph.graphdb.query.condition.Not) IntStream(java.util.stream.IntStream) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) ConfigNamespace(org.janusgraph.diskstorage.configuration.ConfigNamespace) Condition(org.janusgraph.graphdb.query.condition.Condition) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) Rectangle(org.locationtech.spatial4j.shape.Rectangle) ImmutableList(com.google.common.collect.ImmutableList) Cmp(org.janusgraph.core.attribute.Cmp) IndexFeatures(org.janusgraph.diskstorage.indexing.IndexFeatures) Or(org.janusgraph.graphdb.query.condition.Or) JanusGraphException(org.janusgraph.core.JanusGraphException) ES1Compat(org.janusgraph.diskstorage.es.compat.ES1Compat) StreamSupport(java.util.stream.StreamSupport) Geo(org.janusgraph.core.attribute.Geo) BackendException(org.janusgraph.diskstorage.BackendException) JanusGraphPredicate(org.janusgraph.graphdb.query.JanusGraphPredicate) Logger(org.slf4j.Logger) Configuration(org.janusgraph.diskstorage.configuration.Configuration) BaseTransactionConfigurable(org.janusgraph.diskstorage.BaseTransactionConfigurable) RawQuery(org.janusgraph.diskstorage.indexing.RawQuery) ES_TYPE_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_TYPE_KEY) IOException(java.io.IOException) ES_DOC_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_DOC_KEY) DefaultTransaction(org.janusgraph.diskstorage.util.DefaultTransaction) Text(org.janusgraph.core.attribute.Text) IndexMapping(org.janusgraph.diskstorage.es.IndexMappings.IndexMapping) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) ES2Compat(org.janusgraph.diskstorage.es.compat.ES2Compat) ConfigOption.disallowEmpty(org.janusgraph.diskstorage.configuration.ConfigOption.disallowEmpty) Preconditions(com.google.common.base.Preconditions) ParameterType(org.janusgraph.graphdb.types.ParameterType) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) INDEX_NS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_NS) ES5Compat(org.janusgraph.diskstorage.es.compat.ES5Compat) IndexMutation(org.janusgraph.diskstorage.indexing.IndexMutation) HashMap(java.util.HashMap) IndexEntry(org.janusgraph.diskstorage.indexing.IndexEntry) Collection(java.util.Collection) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) KeyInformation(org.janusgraph.diskstorage.indexing.KeyInformation)

Aggregations

Multimap (com.google.common.collect.Multimap)61 HashMultimap (com.google.common.collect.HashMultimap)25 List (java.util.List)25 Test (org.junit.Test)20 Map (java.util.Map)17 ImmutableList (com.google.common.collect.ImmutableList)15 Collection (java.util.Collection)14 Set (java.util.Set)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 HashMap (java.util.HashMap)13 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 ArrayList (java.util.ArrayList)11 Collectors (java.util.stream.Collectors)11 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)10 Nullable (javax.annotation.Nullable)10 IOException (java.io.IOException)9 Stream (java.util.stream.Stream)9 InetAddress (java.net.InetAddress)8 Objects (java.util.Objects)8