use of com.yelp.nrtsearch.server.grpc.AddDocumentRequest in project nrtsearch by Yelp.
the class DateTimeFieldDefTest method testIndexInvalidEpochMillisDateTime.
@Test
public void testIndexInvalidEpochMillisDateTime() throws Exception {
String dateTimeField = "timestamp_epoch_millis";
String dateTimeValue = "definitely not a long";
String dateTimeFormat = "epoch_millis";
List<AddDocumentRequest> docs = new ArrayList<>();
AddDocumentRequest docWithTimestamp = AddDocumentRequest.newBuilder().setIndexName(DEFAULT_TEST_INDEX).putFields("doc_id", MultiValuedField.newBuilder().addValue("1").build()).putFields(dateTimeField, MultiValuedField.newBuilder().addValue(dateTimeValue).build()).build();
docs.add(docWithTimestamp);
try {
addDocuments(docs.stream());
} catch (Exception e) {
assertEquals(formatAddDocumentsExceptionMessage(dateTimeField, dateTimeValue, dateTimeFormat), e.getMessage());
}
}
use of com.yelp.nrtsearch.server.grpc.AddDocumentRequest in project nrtsearch by Yelp.
the class DateTimeFieldDefTest method testIndexInvalidStringDateTime.
@Test
public void testIndexInvalidStringDateTime() throws Exception {
String dateTimeField = "timestamp_string_format";
String dateTimeValue = "1610742000";
String dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
List<AddDocumentRequest> docs = new ArrayList<>();
AddDocumentRequest docWithTimestamp = AddDocumentRequest.newBuilder().setIndexName(DEFAULT_TEST_INDEX).putFields("doc_id", MultiValuedField.newBuilder().addValue("1").build()).putFields(dateTimeField, MultiValuedField.newBuilder().addValue(dateTimeValue).build()).build();
docs.add(docWithTimestamp);
try {
addDocuments(docs.stream());
} catch (RuntimeException e) {
assertEquals(formatAddDocumentsExceptionMessage(dateTimeField, dateTimeValue, dateTimeFormat), e.getMessage());
}
}
use of com.yelp.nrtsearch.server.grpc.AddDocumentRequest in project nrtsearch by Yelp.
the class DeleteDocumentsHandler method handle.
@Override
public AddDocumentResponse handle(IndexState indexState, AddDocumentRequest addDocumentRequest) throws DeleteDocumentsHandlerException {
final ShardState shardState = indexState.getShard(0);
indexState.verifyStarted();
Map<String, AddDocumentRequest.MultiValuedField> fields = addDocumentRequest.getFieldsMap();
List<Term> terms = new ArrayList<>();
for (Map.Entry<String, AddDocumentRequest.MultiValuedField> entry : fields.entrySet()) {
String fieldName = entry.getKey();
AddDocumentRequest.MultiValuedField multiValuedField = entry.getValue();
ProtocolStringList fieldValues = multiValuedField.getValueList();
for (String fieldValue : fieldValues) {
// TODO: how to allow arbitrary binary keys? how to
// pass binary data via json...? byte array?
terms.add(new Term(fieldName, fieldValue));
}
}
try {
shardState.writer.deleteDocuments(terms.stream().toArray(Term[]::new));
} catch (IOException e) {
logger.warn("ThreadId: {}, writer.deleteDocuments failed", Thread.currentThread().getName() + Thread.currentThread().getId());
throw new DeleteDocumentsHandlerException(e);
}
long genId = shardState.writer.getMaxCompletedSequenceNumber();
return AddDocumentResponse.newBuilder().setGenId(String.valueOf(genId)).setPrimaryId(indexState.globalState.getEphemeralId()).build();
}
Aggregations