Search in sources :

Example 21 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class IndexTransactionStateTestBase method shouldPerformStringRangeSearchWithChangedEntityInTxState.

@ParameterizedTest
@ValueSource(strings = { "true", "false" })
void shouldPerformStringRangeSearchWithChangedEntityInTxState(boolean needsValues) throws Exception {
    // given
    Set<Pair<Long, Value>> expected = new HashSet<>();
    long entityToChange;
    try (KernelTransaction tx = beginTransaction()) {
        entityToChange = entityWithPropId(tx, "banana");
        entityWithPropId(tx, "apple");
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithProp(tx, "cherry"));
        entityWithProp(tx, "dragonfruit");
        IndexDescriptor index = tx.schemaRead().indexGetForName(INDEX_NAME);
        TextValue newProperty = stringValue("kiwi");
        setProperty(tx, entityToChange, newProperty);
        int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
        assertEntityAndValueForSeek(expected, tx, index, needsValues, "berry", PropertyIndexQuery.range(prop, "b", true, "d", false));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TextValue(org.neo4j.values.storable.TextValue) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Pair(org.neo4j.internal.helpers.collection.Pair) HashSet(java.util.HashSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class TxStateIndexChanges method indexUpdatesWithValuesForRangeSeekByPrefix.

static AddedWithValuesAndRemoved indexUpdatesWithValuesForRangeSeekByPrefix(ReadableTransactionState txState, IndexDescriptor descriptor, Value[] equalityPrefix, TextValue prefix, IndexOrder indexOrder) {
    NavigableMap<ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
    if (sortedUpdates == null) {
        return EMPTY_ADDED_AND_REMOVED_WITH_VALUES;
    }
    int keySize = descriptor.schema().getPropertyIds().length;
    ValueTuple floor = getCompositeValueTuple(keySize, equalityPrefix, prefix, true);
    ValueTuple maxString = getCompositeValueTuple(keySize, equalityPrefix, Values.MAX_STRING, false);
    MutableList<EntityWithPropertyValues> added = Lists.mutable.empty();
    MutableLongSet removed = LongSets.mutable.empty();
    for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : sortedUpdates.subMap(floor, maxString).entrySet()) {
        ValueTuple key = entry.getKey();
        Value prefixKey = key.valueAt(equalityPrefix.length);
        // Needs to check type since the subMap might include non-TextValue for composite index
        if (prefixKey.valueGroup() == ValueGroup.TEXT && ((TextValue) prefixKey).startsWith(prefix)) {
            LongDiffSets diffSets = entry.getValue();
            Value[] values = key.getValues();
            diffSets.getAdded().each(nodeId -> added.add(new EntityWithPropertyValues(nodeId, values)));
            removed.addAll(diffSets.getRemoved());
        } else {
            break;
        }
    }
    return new AddedWithValuesAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) NavigableMap(java.util.NavigableMap) Map(java.util.Map) UnmodifiableMap(org.eclipse.collections.impl.UnmodifiableMap) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets)

Example 23 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class TemporalFunction method apply.

@Override
public final AnyValue apply(Context ctx, AnyValue[] input) throws ProcedureException {
    if (input == null || (input.length > 0 && (input[0] == NO_VALUE || input[0] == null))) {
        return NO_VALUE;
    } else if (input.length == 0 || input[0].equals(DEFAULT_TEMPORAL_ARGUMENT_VALUE)) {
        return now(ctx.statementClock(), null, defaultZone);
    } else if (input[0] instanceof TextValue) {
        return parse((TextValue) input[0], defaultZone);
    } else if (input[0] instanceof TemporalValue) {
        return select(input[0], defaultZone);
    } else if (input[0] instanceof MapValue) {
        MapValue map = (MapValue) input[0];
        String timezone = onlyTimezone(map);
        if (timezone != null) {
            return now(ctx.statementClock(), timezone, defaultZone);
        }
        return build(map, defaultZone);
    } else {
        throw new ProcedureException(Status.Procedure.ProcedureCallFailed, "Invalid call signature for " + getClass().getSimpleName() + ": Provided input was " + Arrays.toString(input));
    }
}
Also used : TextValue(org.neo4j.values.storable.TextValue) TemporalValue(org.neo4j.values.storable.TemporalValue) MapValue(org.neo4j.values.virtual.MapValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException)

Example 24 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class PrimitiveOnlyValueWriterTest method shouldConvertMultipleValues.

@Test
void shouldConvertMultipleValues() {
    PrimitiveOnlyValueWriter writer = new PrimitiveOnlyValueWriter();
    TextValue value1 = stringValue("Hello");
    TextValue value2 = stringValue(" ");
    TextValue value3 = stringValue("World!");
    LongValue value4 = longValue(42);
    assertEquals("Hello", writer.valueAsObject(value1));
    assertEquals(" ", writer.valueAsObject(value2));
    assertEquals("World!", writer.valueAsObject(value3));
    assertEquals(42L, writer.valueAsObject(value4));
}
Also used : TextValue(org.neo4j.values.storable.TextValue) LongValue(org.neo4j.values.storable.LongValue) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class FulltextIndexProvider method validateIndexRef.

private void validateIndexRef(IndexRef<?> ref) {
    String providerName = getProviderDescriptor().name();
    if (ref.getIndexType() != IndexType.FULLTEXT) {
        throw new IllegalArgumentException("The '" + providerName + "' index provider only supports FULLTEXT index types: " + ref);
    }
    if (!ref.schema().isFulltextSchemaDescriptor()) {
        throw new IllegalArgumentException("The " + ref.schema() + " index schema is not a full-text index schema, " + "which it is required to be for the '" + providerName + "' index provider to be able to create an index.");
    }
    Value value = ref.getIndexConfig().get(ANALYZER);
    if (value != null) {
        if (value.valueGroup() == ValueGroup.TEXT) {
            String analyzerName = ((TextValue) value).stringValue();
            Optional<AnalyzerProvider> analyzerProvider = listAvailableAnalyzers().filter(analyzer -> analyzer.getName().equals(analyzerName)).findFirst();
            if (analyzerProvider.isPresent()) {
                // Verify that the analyzer provider works.
                Analyzer analyzer = analyzerProvider.get().createAnalyzer();
                Objects.requireNonNull(analyzer, "The '" + analyzerName + "' analyzer returned a 'null' analyzer.");
            } else {
                throw new IllegalArgumentException("No such full-text analyzer: '" + analyzerName + "'.");
            }
        } else {
            throw new IllegalArgumentException("Wrong index setting value type for fulltext analyzer: '" + value + "'.");
        }
    }
    TokenHolder propertyKeyTokens = tokenHolders.propertyKeyTokens();
    for (int propertyId : ref.schema().getPropertyIds()) {
        try {
            NamedToken token = propertyKeyTokens.getTokenById(propertyId);
            if (token.name().equals(LuceneFulltextDocumentStructure.FIELD_ENTITY_ID)) {
                throw new IllegalArgumentException("Unable to index the property, the name is reserved for internal use " + LuceneFulltextDocumentStructure.FIELD_ENTITY_ID);
            }
        } catch (TokenNotFoundException e) {
            throw new IllegalArgumentException("Schema references non-existing property key token id: " + propertyId + ".", e);
        }
    }
}
Also used : AnalyzerProvider(org.neo4j.graphdb.schema.AnalyzerProvider) DroppableLuceneIndex(org.neo4j.kernel.api.impl.index.DroppableLuceneIndex) SchemaIndex(org.neo4j.kernel.api.impl.schema.SchemaIndex) Log(org.neo4j.logging.Log) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenNameLookup(org.neo4j.common.TokenNameLookup) IndexType(org.neo4j.internal.schema.IndexType) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) Config(org.neo4j.configuration.Config) DatabaseIndex(org.neo4j.kernel.api.impl.index.DatabaseIndex) Value(org.neo4j.values.storable.Value) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.IndexSamplingConfig) StringUtils(org.apache.commons.lang3.StringUtils) FulltextIndexSettings.createAnalyzer(org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettings.createAnalyzer) LuceneSchemaIndexBuilder(org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexBuilder) DroppableIndex(org.neo4j.kernel.api.impl.index.DroppableIndex) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Exceptions(org.neo4j.internal.helpers.Exceptions) PageCache(org.neo4j.io.pagecache.PageCache) StringUtils.defaultIfEmpty(org.apache.commons.lang3.StringUtils.defaultIfEmpty) IndexStorageFactory(org.neo4j.kernel.api.impl.index.storage.IndexStorageFactory) PartitionedIndexStorage(org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage) TextValue(org.neo4j.values.storable.TextValue) MinimalIndexAccessor(org.neo4j.kernel.api.index.MinimalIndexAccessor) Services(org.neo4j.service.Services) Objects(java.util.Objects) Stream(java.util.stream.Stream) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Optional(java.util.Optional) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) DirectoryFactory(org.neo4j.kernel.api.impl.index.storage.DirectoryFactory) IndexCapability(org.neo4j.internal.schema.IndexCapability) FulltextSettings(org.neo4j.configuration.FulltextSettings) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) ANALYZER(org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettingsKeys.ANALYZER) LuceneMinimalIndexAccessor(org.neo4j.kernel.api.impl.index.LuceneMinimalIndexAccessor) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) ReadOnlyIndexPartitionFactory(org.neo4j.kernel.api.impl.index.partition.ReadOnlyIndexPartitionFactory) IndexProvider(org.neo4j.kernel.api.index.IndexProvider) ByteBufferFactory(org.neo4j.io.memory.ByteBufferFactory) Values(org.neo4j.values.storable.Values) TokenHolder(org.neo4j.token.api.TokenHolder) JobScheduler(org.neo4j.scheduler.JobScheduler) IndexConfig(org.neo4j.internal.schema.IndexConfig) MemoryTracker(org.neo4j.memory.MemoryTracker) FulltextIndexSettings.isEventuallyConsistent(org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettings.isEventuallyConsistent) Analyzer(org.apache.lucene.analysis.Analyzer) IOException(java.io.IOException) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) StoreMigrationParticipant(org.neo4j.storageengine.migration.StoreMigrationParticipant) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) TokenHolders(org.neo4j.token.TokenHolders) TokenNotFoundException(org.neo4j.token.api.TokenNotFoundException) FulltextIndexSettings.createPropertyNames(org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettings.createPropertyNames) NamedToken(org.neo4j.token.api.NamedToken) ValueGroup(org.neo4j.values.storable.ValueGroup) SchemaIndexMigrator(org.neo4j.storageengine.migration.SchemaIndexMigrator) IndexRef(org.neo4j.internal.schema.IndexRef) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) AnalyzerProvider(org.neo4j.graphdb.schema.AnalyzerProvider) TextValue(org.neo4j.values.storable.TextValue) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) TokenHolder(org.neo4j.token.api.TokenHolder) FulltextIndexSettings.createAnalyzer(org.neo4j.kernel.api.impl.fulltext.FulltextIndexSettings.createAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) NamedToken(org.neo4j.token.api.NamedToken) TokenNotFoundException(org.neo4j.token.api.TokenNotFoundException)

Aggregations

TextValue (org.neo4j.values.storable.TextValue)29 Test (org.junit.jupiter.api.Test)12 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)7 AnyValue (org.neo4j.values.AnyValue)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 BooleanValue (org.neo4j.values.storable.BooleanValue)6 Config (org.neo4j.configuration.Config)5 Value (org.neo4j.values.storable.Value)5 Arrays (java.util.Arrays)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ArrayUtils.toArray (org.apache.commons.lang3.ArrayUtils.toArray)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Matchers.contains (org.hamcrest.Matchers.contains)4 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 Public (org.neo4j.annotations.Public)4 CapabilitiesRegistry (org.neo4j.capabilities.CapabilitiesRegistry)4