use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.
the class KeyExpressionTest method testFunctionEvalToWrongType.
@Test
public void testFunctionEvalToWrongType() throws Exception {
assertThrows(KeyExpression.InvalidResultException.class, () -> {
final KeyExpression expression = function("substr", concat(field("field"), field("field"), value(2)));
expression.validate(TestScalarFieldAccess.getDescriptor());
evaluate(expression, plantsBoxesAndBowls);
});
}
use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.
the class KeyExpressionTest method testSubstrFunctionStaticFanout.
@Test
public void testSubstrFunctionStaticFanout() throws Exception {
final KeyExpression expression = function("substr", concat(field("repeat_me", FanType.FanOut), value(0), value(3)));
expression.validate(TestScalarFieldAccess.getDescriptor());
List<Key.Evaluated> results = evaluate(expression, plantsBoxesAndBowls);
assertEquals(2, results.size(), "Wrong number of results");
assertEquals(ImmutableList.of(Key.Evaluated.scalar("Box"), Key.Evaluated.scalar("Bow")), results);
}
use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.
the class KeyExpressionTest method testFieldThenConcatenateRepeated.
@Test
public void testFieldThenConcatenateRepeated() throws Exception {
final KeyExpression expression = Key.Expressions.concat(field("field"), field("repeat_me", FanType.Concatenate));
expression.validate(TestScalarFieldAccess.getDescriptor());
assertFalse(expression.createsDuplicates());
assertEquals(Collections.singletonList(Key.Evaluated.concatenate("Plants", Arrays.asList("Boxes", "Bowls"))), evaluate(expression, plantsBoxesAndBowls));
assertEquals(Collections.singletonList(Key.Evaluated.concatenate(NULL, Collections.emptyList())), evaluate(expression, emptyScalar));
assertEquals(Collections.singletonList(Key.Evaluated.concatenate(NULL, Collections.emptyList())), evaluate(expression, null));
}
use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.
the class KeyExpressionTest method testDoubleNested.
@Test
public void testDoubleNested() throws Exception {
final KeyExpression expression = concat(field("id"), field("order", FanType.FanOut).nest(field("id"), field("item", FanType.FanOut).nest(field("id"), field("name"))), field("first_name"), field("last_name"));
expression.validate(Customer.getDescriptor());
assertTrue(expression.createsDuplicates());
// note Same as testDoubleNestedWithExtraConcats
assertEquals(Arrays.asList(concatenate("customer1", "order1", "i1", "a1", "1 first name", "1 last name"), concatenate("customer1", "order1", "j1", "a2", "1 first name", "1 last name"), concatenate("customer1", "order2", "i2", "b1", "1 first name", "1 last name"), concatenate("customer1", "order2", "j2", "b2", "1 first name", "1 last name"), concatenate("customer1", "order3", "i3", "c1", "1 first name", "1 last name"), concatenate("customer1", "order3", "j3", "c2", "1 first name", "1 last name"), concatenate("customer1", "order3", "k3", "c3", "1 first name", "1 last name"), concatenate("customer1", "order3", "l3", "c4", "1 first name", "1 last name")), evaluate(expression, customer));
assertEquals(Collections.emptyList(), evaluate(expression, emptyCustomer));
assertEquals(Collections.emptyList(), evaluate(expression, aleph));
assertEquals(Collections.emptyList(), evaluate(expression, null));
}
use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.
the class FDBCollateQueryTest method coveringIndex.
@Test
public void coveringIndex() throws Exception {
// Note how the name field needs to be repeated in the value because it can't be recovered from an index
// entry after transformation to a collation key.
final KeyExpression collateKey = function(collateFunctionName, concat(NAME_FIELD, value("da_DK")));
final KeyExpression indexKey = keyWithValue(concat(collateKey, NAME_FIELD), 1);
final RecordMetaDataHook hook = md -> {
md.removeIndex("MySimpleRecord$str_value_indexed");
md.addIndex("MySimpleRecord", "collated_name", indexKey);
};
loadNames(hook);
final RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.keyExpression(collateKey).lessThan("B")).setRequiredResults(Arrays.asList(NAME_FIELD)).build();
final List<String> actual = queryNames(query, hook);
final List<String> expected = Arrays.asList("Ampère");
assertEquals(expected, actual);
RecordQueryPlan plan = planner.plan(query);
assertThat(plan, coveringIndexScan(indexScan("collated_name")));
}
Aggregations