Search in sources :

Example 31 with AddDocumentRequest

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());
    }
}
Also used : ArrayList(java.util.ArrayList) AddDocumentRequest(com.yelp.nrtsearch.server.grpc.AddDocumentRequest) IOException(java.io.IOException) Test(org.junit.Test)

Example 32 with AddDocumentRequest

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());
    }
}
Also used : ArrayList(java.util.ArrayList) AddDocumentRequest(com.yelp.nrtsearch.server.grpc.AddDocumentRequest) Test(org.junit.Test)

Example 33 with AddDocumentRequest

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();
}
Also used : ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) IOException(java.io.IOException) AddDocumentRequest(com.yelp.nrtsearch.server.grpc.AddDocumentRequest) ProtocolStringList(com.google.protobuf.ProtocolStringList) Map(java.util.Map)

Aggregations

AddDocumentRequest (com.yelp.nrtsearch.server.grpc.AddDocumentRequest)33 ArrayList (java.util.ArrayList)21 IndexWriter (org.apache.lucene.index.IndexWriter)14 IOException (java.io.IOException)6 Test (org.junit.Test)6 MultiValuedField (com.yelp.nrtsearch.server.grpc.AddDocumentRequest.MultiValuedField)3 Path (java.nio.file.Path)3 AddDocumentResponse (com.yelp.nrtsearch.server.grpc.AddDocumentResponse)2 LuceneServerClientBuilder (com.yelp.nrtsearch.server.grpc.LuceneServerClientBuilder)2 StreamObserver (io.grpc.stub.StreamObserver)2 Reader (java.io.Reader)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 CSVParser (org.apache.commons.csv.CSVParser)2 Gson (com.google.gson.Gson)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ProtocolStringList (com.google.protobuf.ProtocolStringList)1 FieldDefRequest (com.yelp.nrtsearch.server.grpc.FieldDefRequest)1 GrpcServer (com.yelp.nrtsearch.server.grpc.GrpcServer)1 LuceneServerClient (com.yelp.nrtsearch.server.grpc.LuceneServerClient)1 LuceneServerGrpc (com.yelp.nrtsearch.server.grpc.LuceneServerGrpc)1