Search in sources :

Example 11 with TextValue

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

the class Neo4jPackV1Test method shouldPackUtf8.

@Test
void shouldPackUtf8() throws IOException {
    // Given
    String value = "\uD83D\uDE31";
    byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
    TextValue textValue = utf8Value(bytes, 0, bytes.length);
    PackedOutputArray output = new PackedOutputArray();
    Neo4jPack.Packer packer = neo4jPack.newPacker(output);
    packer.pack(textValue);
    // When
    AnyValue unpacked = unpacked(output.bytes());
    assertThat(unpacked).isInstanceOf(UTF8StringValue.class);
    // Then
    assertThat(unpacked).isEqualTo(textValue);
}
Also used : TextValue(org.neo4j.values.storable.TextValue) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Example 12 with TextValue

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

the class PrimitiveOnlyValueWriterTest method shouldConvertStringValueToString.

@Test
void shouldConvertStringValueToString() {
    PrimitiveOnlyValueWriter writer = new PrimitiveOnlyValueWriter();
    TextValue value = stringValue("Hello");
    assertEquals("Hello", writer.valueAsObject(value));
}
Also used : TextValue(org.neo4j.values.storable.TextValue) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with TextValue

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

the class BuiltInDbmsProceduresIT method listCapabilities.

@Test
void listCapabilities() throws KernelException {
    QualifiedName procedureName = procedureName("dbms", "listCapabilities");
    int procedureId = procs().procedureGet(procedureName).id();
    RawIterator<AnyValue[], ProcedureException> callResult = procs().procedureCallDbms(procedureId, new AnyValue[] {}, ProcedureCallContext.EMPTY);
    List<AnyValue[]> capabilities = asList(callResult);
    List<String> capabilityNames = capabilities.stream().map(c -> ((TextValue) c[0]).stringValue()).collect(Collectors.toList());
    assertThat(capabilityNames).containsExactlyInAnyOrder(TestCapabilities.my_custom_capability.name().fullName(), TestCapabilities.my_dynamic_capability.name().fullName());
}
Also used : AnyValue(org.neo4j.values.AnyValue) Arrays(java.util.Arrays) Label(org.neo4j.graphdb.Label) RawIterator(org.neo4j.collection.RawIterator) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) Iterators.asList(org.neo4j.internal.helpers.collection.Iterators.asList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) ProcedureSignature.procedureName(org.neo4j.internal.kernel.api.procs.ProcedureSignature.procedureName) Public(org.neo4j.annotations.Public) Values(org.neo4j.values.storable.Values) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CapabilitiesRegistry(org.neo4j.capabilities.CapabilitiesRegistry) Capability(org.neo4j.capabilities.Capability) CapabilitiesSettings(org.neo4j.capabilities.CapabilitiesSettings) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FALSE(org.neo4j.configuration.SettingValueParsers.FALSE) CapabilityProviderContext(org.neo4j.capabilities.CapabilityProviderContext) INTEGER(org.neo4j.capabilities.Type.INTEGER) DOUBLE(org.neo4j.capabilities.Type.DOUBLE) CapabilityProvider(org.neo4j.capabilities.CapabilityProvider) Name(org.neo4j.capabilities.Name) DBMSCapabilities(org.neo4j.capabilities.DBMSCapabilities) BooleanValue(org.neo4j.values.storable.BooleanValue) BOOLEAN(org.neo4j.capabilities.Type.BOOLEAN) TextValue(org.neo4j.values.storable.TextValue) Label.label(org.neo4j.graphdb.Label.label) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Collectors(java.util.stream.Collectors) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) List(java.util.List) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) ArrayUtils.toArray(org.apache.commons.lang3.ArrayUtils.toArray) Description(org.neo4j.configuration.Description) KernelException(org.neo4j.exceptions.KernelException) Matchers.contains(org.hamcrest.Matchers.contains) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CapabilityDeclaration(org.neo4j.capabilities.CapabilityDeclaration) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest) TextValue(org.neo4j.values.storable.TextValue) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 14 with TextValue

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

the class BuiltInDbmsProceduresIT method listCapabilitiesShouldNotReturnBlocked.

@Test
void listCapabilitiesShouldNotReturnBlocked() throws KernelException {
    // set blocked capabilities
    Config config = dependencyResolver.resolveDependency(Config.class);
    config.set(CapabilitiesSettings.dbms_capabilities_blocked, List.of("my.**"));
    QualifiedName procedureName = procedureName("dbms", "listCapabilities");
    int procedureId = procs().procedureGet(procedureName).id();
    RawIterator<AnyValue[], ProcedureException> callResult = procs().procedureCallDbms(procedureId, new AnyValue[] {}, ProcedureCallContext.EMPTY);
    List<AnyValue[]> capabilities = asList(callResult);
    List<String> capabilityNames = capabilities.stream().map(c -> ((TextValue) c[0]).stringValue()).collect(Collectors.toList());
    assertThat(capabilityNames).doesNotContain(TestCapabilities.my_custom_capability.name().fullName());
}
Also used : AnyValue(org.neo4j.values.AnyValue) Arrays(java.util.Arrays) Label(org.neo4j.graphdb.Label) RawIterator(org.neo4j.collection.RawIterator) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) Iterators.asList(org.neo4j.internal.helpers.collection.Iterators.asList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) ProcedureSignature.procedureName(org.neo4j.internal.kernel.api.procs.ProcedureSignature.procedureName) Public(org.neo4j.annotations.Public) Values(org.neo4j.values.storable.Values) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CapabilitiesRegistry(org.neo4j.capabilities.CapabilitiesRegistry) Capability(org.neo4j.capabilities.Capability) CapabilitiesSettings(org.neo4j.capabilities.CapabilitiesSettings) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FALSE(org.neo4j.configuration.SettingValueParsers.FALSE) CapabilityProviderContext(org.neo4j.capabilities.CapabilityProviderContext) INTEGER(org.neo4j.capabilities.Type.INTEGER) DOUBLE(org.neo4j.capabilities.Type.DOUBLE) CapabilityProvider(org.neo4j.capabilities.CapabilityProvider) Name(org.neo4j.capabilities.Name) DBMSCapabilities(org.neo4j.capabilities.DBMSCapabilities) BooleanValue(org.neo4j.values.storable.BooleanValue) BOOLEAN(org.neo4j.capabilities.Type.BOOLEAN) TextValue(org.neo4j.values.storable.TextValue) Label.label(org.neo4j.graphdb.Label.label) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Collectors(java.util.stream.Collectors) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) List(java.util.List) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) ArrayUtils.toArray(org.apache.commons.lang3.ArrayUtils.toArray) Description(org.neo4j.configuration.Description) KernelException(org.neo4j.exceptions.KernelException) Matchers.contains(org.hamcrest.Matchers.contains) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CapabilityDeclaration(org.neo4j.capabilities.CapabilityDeclaration) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest) Config(org.neo4j.configuration.Config) TextValue(org.neo4j.values.storable.TextValue) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 15 with TextValue

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

the class CompositeIndexAccessorCompatibility method mustThrowOnIllegalCompositeQueriesAndMustNotThrowOnLegalQueries.

/* Composite query validity */
/**
 * This test verify behavior for all different index patterns on a two column composite index.
 * A composite query need to have decreasing precision among the queries.
 * This means a range or exists query can only be followed by and exists query.
 * Prefix query is also included under "range".
 * Contains or suffix queries are not allowed in a composite query at all.
 *
 * Those are all the different combinations:
 * x = exact
 * < = range (also include stringPrefix)
 * - = exists
 * ! = stringContains or stringSuffix
 * ? = any predicate
 * Index patterns
 * x x ok
 * x < ok
 * x - ok
 * < x not ok
 * < < not ok
 * < - ok
 * - x not ok
 * - < not ok
 * - - ok
 * ! ? not ok
 */
@Test
public void mustThrowOnIllegalCompositeQueriesAndMustNotThrowOnLegalQueries() throws Exception {
    Assume.assumeTrue("Assume support for granular composite queries", testSuite.supportsGranularCompositeQueries());
    // given
    Value someValue = Values.of(true);
    TextValue someString = stringValue("");
    PropertyIndexQuery firstExact = exact(100, someValue);
    PropertyIndexQuery firstRange = range(100, someValue, true, someValue, true);
    PropertyIndexQuery firstPrefix = stringPrefix(100, someString);
    PropertyIndexQuery firstExist = exists(100);
    PropertyIndexQuery firstSuffix = stringSuffix(100, someString);
    PropertyIndexQuery firstContains = stringContains(100, someString);
    PropertyIndexQuery secondExact = exact(200, someValue);
    PropertyIndexQuery secondRange = range(200, someValue, true, someValue, true);
    PropertyIndexQuery secondExist = exists(200);
    PropertyIndexQuery secondPrefix = stringPrefix(100, someString);
    PropertyIndexQuery secondSuffix = stringSuffix(100, someString);
    PropertyIndexQuery secondContains = stringContains(100, someString);
    List<Pair<PropertyIndexQuery[], Boolean>> queries = Arrays.asList(of(new PropertyIndexQuery[] { firstExact, secondExact }, true), of(new PropertyIndexQuery[] { firstExact, secondRange }, true), of(new PropertyIndexQuery[] { firstExact, secondExist }, true), of(new PropertyIndexQuery[] { firstExact, secondPrefix }, true), of(new PropertyIndexQuery[] { firstExact, secondSuffix }, false), of(new PropertyIndexQuery[] { firstExact, secondContains }, false), of(new PropertyIndexQuery[] { firstRange, secondExact }, false), of(new PropertyIndexQuery[] { firstRange, secondRange }, false), of(new PropertyIndexQuery[] { firstRange, secondExist }, true), of(new PropertyIndexQuery[] { firstRange, secondPrefix }, false), of(new PropertyIndexQuery[] { firstRange, secondSuffix }, false), of(new PropertyIndexQuery[] { firstRange, secondContains }, false), of(new PropertyIndexQuery[] { firstPrefix, secondExact }, false), of(new PropertyIndexQuery[] { firstPrefix, secondRange }, false), of(new PropertyIndexQuery[] { firstPrefix, secondExist }, true), of(new PropertyIndexQuery[] { firstPrefix, secondPrefix }, false), of(new PropertyIndexQuery[] { firstPrefix, secondSuffix }, false), of(new PropertyIndexQuery[] { firstPrefix, secondContains }, false), of(new PropertyIndexQuery[] { firstExist, secondExact }, false), of(new PropertyIndexQuery[] { firstExist, secondRange }, false), of(new PropertyIndexQuery[] { firstExist, secondExist }, true), of(new PropertyIndexQuery[] { firstExist, secondPrefix }, false), of(new PropertyIndexQuery[] { firstExist, secondSuffix }, false), of(new PropertyIndexQuery[] { firstExist, secondContains }, false), of(new PropertyIndexQuery[] { firstSuffix, secondExact }, false), of(new PropertyIndexQuery[] { firstSuffix, secondRange }, false), of(new PropertyIndexQuery[] { firstSuffix, secondExist }, false), of(new PropertyIndexQuery[] { firstSuffix, secondPrefix }, false), of(new PropertyIndexQuery[] { firstSuffix, secondSuffix }, false), of(new PropertyIndexQuery[] { firstSuffix, secondContains }, false), of(new PropertyIndexQuery[] { firstContains, secondExact }, false), of(new PropertyIndexQuery[] { firstContains, secondRange }, false), of(new PropertyIndexQuery[] { firstContains, secondExist }, false), of(new PropertyIndexQuery[] { firstContains, secondPrefix }, false), of(new PropertyIndexQuery[] { firstContains, secondSuffix }, false), of(new PropertyIndexQuery[] { firstContains, secondContains }, false));
    SimpleEntityValueClient client = new SimpleEntityValueClient();
    try (ValueIndexReader reader = accessor.newValueReader()) {
        for (Pair<PropertyIndexQuery[], Boolean> pair : queries) {
            PropertyIndexQuery[] theQuery = pair.first();
            Boolean legal = pair.other();
            if (legal) {
                // when
                reader.query(NULL_CONTEXT, client, unconstrained(), theQuery);
            // then should not throw
            } else {
                try {
                    // when
                    reader.query(NULL_CONTEXT, client, unconstrained(), theQuery);
                    fail("Expected index reader to throw for illegal composite query. Query was, " + Arrays.toString(theQuery));
                } catch (IllegalArgumentException e) {
                    // then
                    assertThat(e.getMessage()).contains("Tried to query index with illegal composite query.");
                }
            }
        }
    }
}
Also used : PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) TextValue(org.neo4j.values.storable.TextValue) ArrayValue(org.neo4j.values.storable.ArrayValue) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) PointValue(org.neo4j.values.storable.PointValue) LocalDateTimeValue(org.neo4j.values.storable.LocalDateTimeValue) TimeValue(org.neo4j.values.storable.TimeValue) DateTimeValue(org.neo4j.values.storable.DateTimeValue) Values.intValue(org.neo4j.values.storable.Values.intValue) Values.pointValue(org.neo4j.values.storable.Values.pointValue) LocalTimeValue(org.neo4j.values.storable.LocalTimeValue) BooleanValue(org.neo4j.values.storable.BooleanValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) DateValue(org.neo4j.values.storable.DateValue) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient) Pair(org.neo4j.internal.helpers.collection.Pair) Test(org.junit.Test)

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