use of org.neo4j.values.storable.ValueGroup in project neo4j by neo4j.
the class CompositeIndexAccessorCompatibility method testIndexSeekExactWithRange.
private void testIndexSeekExactWithRange(Value base1, Value base2, Value obj1, Value obj2, Value obj3, Value obj4, Value obj5) throws Exception {
Assume.assumeTrue("Assume support for granular composite queries", testSuite.supportsGranularCompositeQueries());
updateAndCommit(asList(add(1L, descriptor.schema(), base1, obj1), add(2L, descriptor.schema(), base1, obj2), add(3L, descriptor.schema(), base1, obj3), add(4L, descriptor.schema(), base1, obj4), add(5L, descriptor.schema(), base1, obj5), add(6L, descriptor.schema(), base2, obj1), add(7L, descriptor.schema(), base2, obj2), add(8L, descriptor.schema(), base2, obj3), add(9L, descriptor.schema(), base2, obj4), add(10L, descriptor.schema(), base2, obj5)));
assertThat(query(exact(0, base1), range(1, obj2, true, obj4, false))).isEqualTo(asList(2L, 3L));
assertThat(query(exact(0, base1), range(1, obj4, true, null, false))).isEqualTo(asList(4L, 5L));
assertThat(query(exact(0, base1), range(1, obj4, false, null, true))).isEqualTo(singletonList(5L));
assertThat(query(exact(0, base1), range(1, obj5, false, obj2, true))).isEqualTo(EMPTY_LIST);
assertThat(query(exact(0, base1), range(1, null, false, obj3, false))).isEqualTo(asList(1L, 2L));
assertThat(query(exact(0, base1), range(1, null, true, obj3, true))).isEqualTo(asList(1L, 2L, 3L));
assertThat(query(exact(0, base1), range(1, obj1, false, obj2, true))).isEqualTo(singletonList(2L));
assertThat(query(exact(0, base1), range(1, obj1, false, obj3, false))).isEqualTo(singletonList(2L));
assertThat(query(exact(0, base2), range(1, obj2, true, obj4, false))).isEqualTo(asList(7L, 8L));
assertThat(query(exact(0, base2), range(1, obj4, true, null, false))).isEqualTo(asList(9L, 10L));
assertThat(query(exact(0, base2), range(1, obj4, false, null, true))).isEqualTo(singletonList(10L));
assertThat(query(exact(0, base2), range(1, obj5, false, obj2, true))).isEqualTo(EMPTY_LIST);
assertThat(query(exact(0, base2), range(1, null, false, obj3, false))).isEqualTo(asList(6L, 7L));
assertThat(query(exact(0, base2), range(1, null, true, obj3, true))).isEqualTo(asList(6L, 7L, 8L));
assertThat(query(exact(0, base2), range(1, obj1, false, obj2, true))).isEqualTo(singletonList(7L));
assertThat(query(exact(0, base2), range(1, obj1, false, obj3, false))).isEqualTo(singletonList(7L));
ValueGroup valueGroup = obj1.valueGroup();
if (valueGroup != GEOMETRY && valueGroup != GEOMETRY_ARRAY) {
assertThat(query(exact(0, base1), range(1, valueGroup))).isEqualTo(asList(1L, 2L, 3L, 4L, 5L));
assertThat(query(exact(0, base2), range(1, valueGroup))).isEqualTo(asList(6L, 7L, 8L, 9L, 10L));
} else {
CoordinateReferenceSystem crs = getCrs(obj1);
assertThat(query(exact(0, base1), range(1, crs))).isEqualTo(asList(1L, 2L, 3L, 4L, 5L));
assertThat(query(exact(0, base2), range(1, crs))).isEqualTo(asList(6L, 7L, 8L, 9L, 10L));
}
}
use of org.neo4j.values.storable.ValueGroup in project neo4j by neo4j.
the class CompositeIndexAccessorCompatibility method testIndexSeekRangeWithExists.
private void testIndexSeekRangeWithExists(Value obj1, Value obj2, Value obj3, Value obj4, Value obj5) throws Exception {
Assume.assumeTrue("Assume support for granular composite queries", testSuite.supportsGranularCompositeQueries());
updateAndCommit(asList(add(1L, descriptor.schema(), obj1, Values.of(100)), add(2L, descriptor.schema(), obj2, Values.of("someString")), add(3L, descriptor.schema(), obj3, Values.of(epochDate(300))), add(4L, descriptor.schema(), obj4, Values.of(true)), add(5L, descriptor.schema(), obj5, Values.of(42))));
assertThat(query(range(0, obj2, true, obj4, false), exists(1))).isEqualTo(asList(2L, 3L));
assertThat(query(range(0, obj4, true, null, false), exists(1))).isEqualTo(asList(4L, 5L));
assertThat(query(range(0, obj4, false, null, true), exists(1))).isEqualTo(singletonList(5L));
assertThat(query(range(0, obj5, false, obj2, true), exists(1))).isEqualTo(EMPTY_LIST);
assertThat(query(range(0, null, false, obj3, false), exists(1))).isEqualTo(asList(1L, 2L));
assertThat(query(range(0, null, true, obj3, true), exists(1))).isEqualTo(asList(1L, 2L, 3L));
ValueGroup valueGroup = obj1.valueGroup();
if (valueGroup != GEOMETRY && valueGroup != GEOMETRY_ARRAY) {
// This cannot be done for spatial values because each bound in a spatial query needs a coordinate reference system,
// and those are provided by Value instances, e.g. PointValue
assertThat(query(range(0, obj1.valueGroup()), exists(1))).isEqualTo(asList(1L, 2L, 3L, 4L, 5L));
}
assertThat(query(range(0, obj1, false, obj2, true), exists(1))).isEqualTo(singletonList(2L));
assertThat(query(range(0, obj1, false, obj3, false), exists(1))).isEqualTo(singletonList(2L));
}
use of org.neo4j.values.storable.ValueGroup in project neo4j by neo4j.
the class NativeIndexAccessorTests method expectIndexOrder.
private static void expectIndexOrder(Value[] allValues, ValueGroup valueGroup, ValueIndexReader reader, IndexOrder supportedOrder, PropertyIndexQuery.RangePredicate<?> supportedQuery) throws IndexNotApplicableKernelException {
Value[] expectedValues = Arrays.stream(allValues).filter(v -> v.valueGroup() == valueGroup).toArray(Value[]::new);
if (supportedOrder == IndexOrder.ASCENDING) {
Arrays.sort(expectedValues, Values.COMPARATOR);
} else if (supportedOrder == IndexOrder.DESCENDING) {
Arrays.sort(expectedValues, Values.COMPARATOR.reversed());
}
SimpleEntityValueClient client = new SimpleEntityValueClient();
reader.query(NULL_CONTEXT, client, constrained(supportedOrder, true), supportedQuery);
int i = 0;
while (client.next()) {
assertEquals(expectedValues[i++], client.values[0], "values in order");
}
assertEquals(i, expectedValues.length, "found all values");
}
use of org.neo4j.values.storable.ValueGroup in project neo4j by neo4j.
the class PropertyIndexQuery method range.
public static <VALUE extends Value> RangePredicate<?> range(int propertyKeyId, VALUE from, boolean fromInclusive, VALUE to, boolean toInclusive) {
if (from == null && to == null) {
throw new IllegalArgumentException("Cannot create RangePredicate without at least one bound");
}
ValueGroup valueGroup = from != null ? from.valueGroup() : to.valueGroup();
switch(valueGroup) {
case NUMBER:
return NumberRangePredicate.create(propertyKeyId, (NumberValue) from, fromInclusive, (NumberValue) to, toInclusive);
case TEXT:
return new TextRangePredicate(propertyKeyId, (TextValue) from, fromInclusive, (TextValue) to, toInclusive);
case GEOMETRY:
PointValue pFrom = (PointValue) from;
PointValue pTo = (PointValue) to;
CoordinateReferenceSystem crs = pFrom != null ? pFrom.getCoordinateReferenceSystem() : pTo.getCoordinateReferenceSystem();
return new GeometryRangePredicate(propertyKeyId, crs, pFrom, fromInclusive, pTo, toInclusive);
default:
return new RangePredicate<>(propertyKeyId, valueGroup, from, fromInclusive, to, toInclusive);
}
}
use of org.neo4j.values.storable.ValueGroup in project neo4j by neo4j.
the class GenericKeyStateTest method copyShouldCopyExtremeValues.
@Test
void copyShouldCopyExtremeValues() {
// Given
GenericKey extreme = newKeyState();
GenericKey copy = newKeyState();
for (ValueGroup valueGroup : ValueGroup.values()) {
if (valueGroup != ValueGroup.NO_VALUE) {
extreme.initValueAsLowest(valueGroup);
copy.copyFrom(extreme);
assertEquals(0, extreme.compareValueTo(copy), "states not equals after copy, valueGroup=" + valueGroup);
extreme.initValueAsHighest(valueGroup);
copy.copyFrom(extreme);
assertEquals(0, extreme.compareValueTo(copy), "states not equals after copy, valueGroup=" + valueGroup);
}
}
}
Aggregations