Search in sources :

Example 51 with KeyExpression

use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.

the class LuceneDocumentFromRecordTest method uncorrelatedMap.

@Test
void uncorrelatedMap() {
    TestRecordsTextProto.MapDocument message = TestRecordsTextProto.MapDocument.newBuilder().setDocId(5).addEntry(TestRecordsTextProto.MapDocument.Entry.newBuilder().setKey("k1").setValue("v1")).addEntry(TestRecordsTextProto.MapDocument.Entry.newBuilder().setKey("k2").setValue("v2")).build();
    FDBRecord<Message> record = unstoredRecord(message);
    KeyExpression index = field("entry", KeyExpression.FanType.FanOut).nest(concat(field("key"), function(LuceneFunctionNames.LUCENE_TEXT, field("value"))));
    assertEquals(ImmutableMap.of(Tuple.from(), ImmutableList.of(stringField("entry_key", "k1"), textField("entry_value", "v1"), stringField("entry_key", "k2"), textField("entry_value", "v2"))), LuceneDocumentFromRecord.getRecordFields(index, record));
    // Build the partial record message for suggestion
    Descriptors.Descriptor recordDescriptor = message.getDescriptorForType();
    TestRecordsTextProto.MapDocument.Builder builder = TestRecordsTextProto.MapDocument.newBuilder();
    LuceneIndexKeyValueToPartialRecordUtils.buildPartialRecord(index, recordDescriptor, builder, "entry_value", "suggestion");
    TestRecordsTextProto.MapDocument partialMsg = builder.build();
    assertEquals(1, partialMsg.getEntryCount());
    TestRecordsTextProto.MapDocument.Entry entry = partialMsg.getEntry(0);
    // The suggestion is supposed to show up in value field within repeated entry sub-message
    assertEquals("suggestion", entry.getValue());
}
Also used : TestRecordsTextProto(com.apple.foundationdb.record.TestRecordsTextProto) Message(com.google.protobuf.Message) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) GroupingKeyExpression(com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression) Descriptors(com.google.protobuf.Descriptors) Test(org.junit.jupiter.api.Test)

Example 52 with KeyExpression

use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.

the class LuceneDocumentFromRecordTest method groupedMap.

@Test
void groupedMap() {
    TestRecordsTextProto.MapDocument message = TestRecordsTextProto.MapDocument.newBuilder().setDocId(6).addEntry(TestRecordsTextProto.MapDocument.Entry.newBuilder().setKey("k1").setValue("v10")).addEntry(TestRecordsTextProto.MapDocument.Entry.newBuilder().setKey("k2").setValue("v20")).setGroup(20).build();
    FDBRecord<Message> record = unstoredRecord(message);
    KeyExpression index = function(LuceneFunctionNames.LUCENE_FIELD_NAME, concat(field("entry", KeyExpression.FanType.FanOut).nest(function(LuceneFunctionNames.LUCENE_FIELD_NAME, concat(function(LuceneFunctionNames.LUCENE_TEXT, field("value")), field("key")))), value(null))).groupBy(field("group"));
    assertEquals(ImmutableMap.of(Tuple.from(20), ImmutableList.of(textField("k1", "v10"), textField("k2", "v20"))), LuceneDocumentFromRecord.getRecordFields(index, record));
    // Build the partial record message for suggestion
    Descriptors.Descriptor recordDescriptor = message.getDescriptorForType();
    TestRecordsTextProto.MapDocument.Builder builder = TestRecordsTextProto.MapDocument.newBuilder();
    LuceneIndexKeyValueToPartialRecordUtils.buildPartialRecord(index, recordDescriptor, builder, "k1", "suggestion", Tuple.from(20));
    TestRecordsTextProto.MapDocument partialMsg = builder.build();
    assertEquals(1, partialMsg.getEntryCount());
    TestRecordsTextProto.MapDocument.Entry entry = partialMsg.getEntry(0);
    // The k1 is supposed to show up in the key field within repeated entry sub-message
    assertEquals("k1", entry.getKey());
    // The suggestion is supposed to show up in value field within repeated entry sub-message
    assertEquals("suggestion", entry.getValue());
    // The group field is supposed to be populated because it is part of grouping key
    assertEquals(20L, partialMsg.getGroup());
}
Also used : TestRecordsTextProto(com.apple.foundationdb.record.TestRecordsTextProto) Message(com.google.protobuf.Message) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) GroupingKeyExpression(com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression) Descriptors(com.google.protobuf.Descriptors) Test(org.junit.jupiter.api.Test)

Example 53 with KeyExpression

use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.

the class LuceneDocumentFromRecordTest method biGroup.

@Test
void biGroup() {
    TestRecordsTextProto.ComplexDocument message = TestRecordsTextProto.ComplexDocument.newBuilder().setHeader(TestRecordsTextProto.ComplexDocument.Header.newBuilder().setHeaderId(4)).setGroup(10).setText("first text").addTag("tag1").addTag("tag2").setText2("second text").setScore(100).build();
    FDBRecord<Message> record = unstoredRecord(message);
    KeyExpression index = concat(function(LuceneFunctionNames.LUCENE_TEXT, field("text")), function(LuceneFunctionNames.LUCENE_TEXT, field("text2")), field("score")).groupBy(concat(field("group"), field("tag", KeyExpression.FanType.FanOut)));
    assertEquals(ImmutableMap.of(Tuple.from(10, "tag1"), ImmutableList.of(textField("text", "first text"), textField("text2", "second text"), intField("score", 100)), Tuple.from(10, "tag2"), ImmutableList.of(textField("text", "first text"), textField("text2", "second text"), intField("score", 100))), LuceneDocumentFromRecord.getRecordFields(index, record));
    // Build the partial record message for suggestion
    Descriptors.Descriptor recordDescriptor = message.getDescriptorForType();
    TestRecordsTextProto.ComplexDocument.Builder builder = TestRecordsTextProto.ComplexDocument.newBuilder();
    LuceneIndexKeyValueToPartialRecordUtils.buildPartialRecord(index, recordDescriptor, builder, "text", "suggestion", Tuple.from(10, "tag1"));
    TestRecordsTextProto.ComplexDocument partialMsg = builder.build();
    // The suggestion is supposed to show up in text field
    assertEquals("suggestion", partialMsg.getText());
    // The group field is supposed to be populated because it is part of grouping key
    assertEquals(10L, partialMsg.getGroup());
    // The tag field is supposed to be populated because it is part of grouping key
    assertEquals(1, partialMsg.getTagCount());
    assertEquals("tag1", partialMsg.getTag(0));
}
Also used : TestRecordsTextProto(com.apple.foundationdb.record.TestRecordsTextProto) Message(com.google.protobuf.Message) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) GroupingKeyExpression(com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression) Descriptors(com.google.protobuf.Descriptors) Test(org.junit.jupiter.api.Test)

Example 54 with KeyExpression

use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.

the class LuceneDocumentFromRecordTest method groupingMap.

@Test
void groupingMap() {
    TestRecordsTextProto.MapDocument message = TestRecordsTextProto.MapDocument.newBuilder().setDocId(7).addEntry(TestRecordsTextProto.MapDocument.Entry.newBuilder().setKey("r1").setValue("val").setSecondValue("2val").setThirdValue("3val")).addEntry(TestRecordsTextProto.MapDocument.Entry.newBuilder().setKey("r2").setValue("nval").setSecondValue("2nval").setThirdValue("3nval")).setGroup(30).build();
    FDBRecord<Message> record = unstoredRecord(message);
    KeyExpression index = new GroupingKeyExpression(concat(field("group"), field("entry", KeyExpression.FanType.FanOut).nest(concat(field("key"), function(LuceneFunctionNames.LUCENE_TEXT, field("value")), function(LuceneFunctionNames.LUCENE_TEXT, field("second_value")), function(LuceneFunctionNames.LUCENE_TEXT, field("third_value"))))), 3);
    assertEquals(ImmutableMap.of(Tuple.from(30, "r1"), ImmutableList.of(textField("entry_value", "val"), textField("entry_second_value", "2val"), textField("entry_third_value", "3val")), Tuple.from(30, "r2"), ImmutableList.of(textField("entry_value", "nval"), textField("entry_second_value", "2nval"), textField("entry_third_value", "3nval"))), LuceneDocumentFromRecord.getRecordFields(index, record));
    // Build the partial record message for suggestion
    Descriptors.Descriptor recordDescriptor = message.getDescriptorForType();
    TestRecordsTextProto.MapDocument.Builder builder = TestRecordsTextProto.MapDocument.newBuilder();
    LuceneIndexKeyValueToPartialRecordUtils.buildPartialRecord(index, recordDescriptor, builder, "entry_value", "suggestion", Tuple.from(30, "r1"));
    TestRecordsTextProto.MapDocument partialMsg = builder.build();
    assertEquals(1, partialMsg.getEntryCount());
    TestRecordsTextProto.MapDocument.Entry entry = partialMsg.getEntry(0);
    // The suggestion is supposed to show up in value field within repeated entry sub-message
    assertEquals("suggestion", entry.getValue());
    // The second_value field is not supposed to be populated
    assertFalse(entry.hasSecondValue());
    // The key field within repeated entry sub-message is supposed to be populated because it is part of grouping key
    assertEquals("r1", entry.getKey());
    // The group field is supposed to be populated because it is part of grouping key
    assertEquals(30L, partialMsg.getGroup());
}
Also used : TestRecordsTextProto(com.apple.foundationdb.record.TestRecordsTextProto) Message(com.google.protobuf.Message) GroupingKeyExpression(com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) GroupingKeyExpression(com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression) Descriptors(com.google.protobuf.Descriptors) Test(org.junit.jupiter.api.Test)

Example 55 with KeyExpression

use of com.apple.foundationdb.record.metadata.expressions.KeyExpression in project fdb-record-layer by FoundationDB.

the class LuceneDocumentFromRecordTest method map.

@Test
void map() {
    TestRecordsTextProto.MapDocument message = TestRecordsTextProto.MapDocument.newBuilder().setDocId(5).addEntry(TestRecordsTextProto.MapDocument.Entry.newBuilder().setKey("k1").setValue("v1")).addEntry(TestRecordsTextProto.MapDocument.Entry.newBuilder().setKey("k2").setValue("v2")).build();
    FDBRecord<Message> record = unstoredRecord(message);
    KeyExpression index = function(LuceneFunctionNames.LUCENE_FIELD_NAME, concat(field("entry", KeyExpression.FanType.FanOut).nest(function(LuceneFunctionNames.LUCENE_FIELD_NAME, concat(function(LuceneFunctionNames.LUCENE_TEXT, field("value")), field("key")))), value(null)));
    assertEquals(ImmutableMap.of(Tuple.from(), ImmutableList.of(textField("k1", "v1"), textField("k2", "v2"))), LuceneDocumentFromRecord.getRecordFields(index, record));
    // Build the partial record message for suggestion
    Descriptors.Descriptor recordDescriptor = message.getDescriptorForType();
    TestRecordsTextProto.MapDocument.Builder builder = TestRecordsTextProto.MapDocument.newBuilder();
    LuceneIndexKeyValueToPartialRecordUtils.buildPartialRecord(index, recordDescriptor, builder, "k1", "suggestion");
    TestRecordsTextProto.MapDocument partialMsg = builder.build();
    assertEquals(1, partialMsg.getEntryCount());
    TestRecordsTextProto.MapDocument.Entry entry = partialMsg.getEntry(0);
    // The k1 is supposed to show up in the key field within repeated entry sub-message
    assertEquals("k1", entry.getKey());
    // The suggestion is supposed to show up in value field within repeated entry sub-message
    assertEquals("suggestion", entry.getValue());
}
Also used : TestRecordsTextProto(com.apple.foundationdb.record.TestRecordsTextProto) Message(com.google.protobuf.Message) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) GroupingKeyExpression(com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression) Descriptors(com.google.protobuf.Descriptors) Test(org.junit.jupiter.api.Test)

Aggregations

KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)152 GroupingKeyExpression (com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression)85 Test (org.junit.jupiter.api.Test)63 FieldKeyExpression (com.apple.foundationdb.record.metadata.expressions.FieldKeyExpression)60 EmptyKeyExpression (com.apple.foundationdb.record.metadata.expressions.EmptyKeyExpression)56 NestingKeyExpression (com.apple.foundationdb.record.metadata.expressions.NestingKeyExpression)56 ThenKeyExpression (com.apple.foundationdb.record.metadata.expressions.ThenKeyExpression)52 Nonnull (javax.annotation.Nonnull)52 Index (com.apple.foundationdb.record.metadata.Index)37 List (java.util.List)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)35 Nullable (javax.annotation.Nullable)33 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)30 FunctionKeyExpression (com.apple.foundationdb.record.metadata.expressions.FunctionKeyExpression)28 Message (com.google.protobuf.Message)26 ArrayList (java.util.ArrayList)26 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)25 QueryableKeyExpression (com.apple.foundationdb.record.metadata.expressions.QueryableKeyExpression)25 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)24 ListKeyExpression (com.apple.foundationdb.record.metadata.expressions.ListKeyExpression)23