use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.
the class KeyExpressionTest method testCharFunction.
@Test
public void testCharFunction() throws Exception {
final KeyExpression expression = function("chars", field("field"));
expression.validate(TestScalarFieldAccess.getDescriptor());
assertEquals(ImmutableList.of(scalar("n"), scalar("u"), scalar("m"), scalar("b"), scalar("e"), scalar("r"), scalar("s")), evaluate(expression, numbers));
}
use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.
the class KeyExpressionTest method testFunctionWrongColumnCount.
@Test
public void testFunctionWrongColumnCount() throws Exception {
// two_min_three_max declares that it will return only one column, but it really returns the result of
// the expression that is its argument, in this case, will return three columns.
assertThrows(KeyExpression.InvalidResultException.class, () -> {
final KeyExpression expression = function("two_min_three_max", concat(field("field"), value(1), 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 testNestedThenRepeats.
@Test
public void testNestedThenRepeats() throws Exception {
final KeyExpression expression = field("nesty").nest("repeated_field", FanType.FanOut);
expression.validate(NestedField.getDescriptor());
assertTrue(expression.createsDuplicates());
assertEquals(Arrays.asList(scalar("lily"), scalar("rose")), evaluate(expression, matryoshkaDolls));
assertEquals(Collections.emptyList(), evaluate(expression, emptyNested));
assertEquals(Collections.emptyList(), evaluate(expression, lonelyDoll));
assertEquals(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 testDoubleNestedWithExtraConcats.
@Test
public void testDoubleNestedWithExtraConcats() throws Exception {
final KeyExpression expressionWithConcats = concat(field("id"), field("order", FanType.FanOut).nest(concat(field("id"), field("item", FanType.FanOut).nest(concat(field("id"), field("name"))))), field("first_name"), field("last_name"));
final KeyExpression expressionWithoutConcats = 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"));
expressionWithConcats.validate(Customer.getDescriptor());
assertTrue(expressionWithConcats.createsDuplicates());
expressionWithoutConcats.validate(Customer.getDescriptor());
assertTrue(expressionWithoutConcats.createsDuplicates());
assertEquals(evaluate(expressionWithoutConcats, customer), evaluate(expressionWithConcats, customer));
assertEquals(evaluate(expressionWithoutConcats, emptyCustomer), evaluate(expressionWithConcats, emptyCustomer));
assertEquals(evaluate(expressionWithoutConcats, aleph), evaluate(expressionWithConcats, aleph));
assertEquals(Collections.emptyList(), evaluate(expressionWithoutConcats, null));
assertEquals(evaluate(expressionWithoutConcats, null), evaluate(expressionWithConcats, null));
}
use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.
the class KeyExpressionTest method testSubstrFunctionDynamicFanout.
@Test
public void testSubstrFunctionDynamicFanout() throws Exception {
final KeyExpression expression = function("substr", field("substrings", FanType.FanOut).nest(concatenateFields("content", "start", "end")));
expression.validate(SubStrings.getDescriptor());
List<Key.Evaluated> results = evaluate(expression, subString);
assertEquals(4, results.size(), "Wrong number of results");
assertEquals(ImmutableList.of(Key.Evaluated.scalar("co"), Key.Evaluated.scalar("ke"), Key.Evaluated.scalar("j"), Key.Evaluated.scalar("tos")), results);
}
Aggregations