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());
}
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());
}
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));
}
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());
}
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());
}
Aggregations