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));
}
}
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);
}
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));
}
}
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));
}
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);
}
}
}
Aggregations