Search in sources :

Example 31 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class VespaXMLFeedReader method read.

/* (non-Javadoc)
     * @see com.yahoo.vespaxmlparser.FeedReader#read(com.yahoo.vespaxmlparser.VespaXMLFeedReader.Operation)
     */
@Override
public void read(Operation operation) throws Exception {
    String startTag = null;
    operation.setInvalid();
    try {
        while (reader.hasNext()) {
            int type = reader.next();
            if (type == XMLStreamReader.START_ELEMENT) {
                startTag = reader.getName().toString();
                if ("document".equals(startTag)) {
                    VespaXMLDocumentReader documentReader = new VespaXMLDocumentReader(reader, docTypeManager);
                    Document document = new Document(documentReader);
                    operation.setDocument(document);
                    operation.setCondition(TestAndSetCondition.fromConditionString(documentReader.getCondition()));
                    return;
                } else if ("update".equals(startTag)) {
                    VespaXMLUpdateReader updateReader = new VespaXMLUpdateReader(reader, docTypeManager);
                    DocumentUpdate update = new DocumentUpdate(updateReader);
                    operation.setDocumentUpdate(update);
                    operation.setCondition(TestAndSetCondition.fromConditionString(updateReader.getCondition()));
                    return;
                } else if ("remove".equals(startTag)) {
                    boolean documentIdFound = false;
                    Optional<String> condition = Optional.empty();
                    for (int i = 0; i < reader.getAttributeCount(); i++) {
                        final String attributeName = reader.getAttributeName(i).toString();
                        if ("documentid".equals(attributeName) || "id".equals(attributeName)) {
                            operation.setRemove(new DocumentId(reader.getAttributeValue(i)));
                            documentIdFound = true;
                        } else if ("condition".equals(attributeName)) {
                            condition = Optional.of(reader.getAttributeValue(i));
                        }
                    }
                    if (!documentIdFound) {
                        throw newDeserializeException("Missing \"documentid\" attribute for remove operation");
                    }
                    operation.setCondition(TestAndSetCondition.fromConditionString(condition));
                    return;
                } else {
                    throw newDeserializeException("Element \"" + startTag + "\" not allowed in this context");
                }
            }
        }
    } catch (XMLStreamException e) {
        throw (e);
    // Skip to end of current tag with other exceptions.
    } catch (Exception e) {
        try {
            if (startTag != null) {
                skipToEnd(startTag);
            }
        } catch (Exception ignore) {
        }
        throw (e);
    }
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) XMLStreamException(javax.xml.stream.XMLStreamException) DocumentId(com.yahoo.document.DocumentId) Document(com.yahoo.document.Document) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 32 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class BucketIdFactoryTestCase method testBidContainsDocId.

public void testBidContainsDocId() {
    DocumentId docId = new DocumentId("userdoc:recovery:18:99999");
    BucketIdFactory factory = new BucketIdFactory(32, 26, 6);
    BucketId bid = new BucketId(16, 0x12L);
    assert (bid.contains(docId, factory));
    // split on '0'
    bid = new BucketId(17, 0x12L);
    assert (bid.contains(docId, factory));
    // split on '1'
    bid = new BucketId(17, (1L << 16) + 0x12L);
    assert (!bid.contains(docId, factory));
}
Also used : DocumentId(com.yahoo.document.DocumentId) BucketId(com.yahoo.document.BucketId) BucketIdFactory(com.yahoo.document.BucketIdFactory)

Example 33 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class BucketIdFactoryTestCase method testBucketGeneration.

public void testBucketGeneration() {
    BucketIdFactory factory = new BucketIdFactory(32, 26, 6);
    DocumentId doc1 = new DocumentId(new DocIdString("ns", "spec"));
    DocumentId doc2 = new DocumentId(new DocIdString("ns2", "spec"));
    DocumentId doc3 = new DocumentId(new DocIdString("ns", "spec2"));
    DocumentId userDoc1 = new DocumentId(new UserDocIdString("ns", 0x12, "spec"));
    DocumentId userDoc2 = new DocumentId(new UserDocIdString("ns2", 0x12, "spec2"));
    DocumentId userDoc3 = new DocumentId(new UserDocIdString("ns", 0x13, "spec"));
    DocumentId groupDoc1 = new DocumentId(new GroupDocIdString("ns", "yahoo.com", "spec"));
    DocumentId groupDoc2 = new DocumentId(new GroupDocIdString("ns2", "yahoo.com", "spec2"));
    DocumentId groupDoc3 = new DocumentId(new GroupDocIdString("ns", "yahoo", "spec"));
    DocumentId orderDoc1 = new DocumentId(new OrderDocIdString("ns", "13", 31, 19, 1268182861, "foo"));
    DocumentId orderDoc2 = new DocumentId(new OrderDocIdString("ns", "13", 31, 19, 1205110861, "foo"));
    DocumentId orderDoc3 = new DocumentId(new OrderDocIdString("ns", "13", 31, 19, 1205715661, "foo"));
    DocumentId orderDoc4 = new DocumentId(new OrderDocIdString("ns", "13", 4, 0, 2, "foo"));
    DocumentId orderDoc5 = new DocumentId(new OrderDocIdString("ns", "13", 4, 0, 4, "foo"));
    DocumentId orderDoc6 = new DocumentId(new OrderDocIdString("ns", "13", 4, 0, 11, "foo"));
    BucketId docBucket1 = factory.getBucketId(doc1);
    BucketId docBucket2 = factory.getBucketId(doc2);
    BucketId docBucket3 = factory.getBucketId(doc3);
    BucketId userDocBucket1 = factory.getBucketId(userDoc1);
    BucketId userDocBucket2 = factory.getBucketId(userDoc2);
    BucketId userDocBucket3 = factory.getBucketId(userDoc3);
    BucketId groupDocBucket1 = factory.getBucketId(groupDoc1);
    BucketId groupDocBucket2 = factory.getBucketId(groupDoc2);
    BucketId groupDocBucket3 = factory.getBucketId(groupDoc3);
    BucketId orderDocBucket1 = factory.getBucketId(orderDoc1);
    BucketId orderDocBucket2 = factory.getBucketId(orderDoc2);
    BucketId orderDocBucket3 = factory.getBucketId(orderDoc3);
    BucketId orderDocBucket4 = factory.getBucketId(orderDoc4);
    BucketId orderDocBucket5 = factory.getBucketId(orderDoc5);
    BucketId orderDocBucket6 = factory.getBucketId(orderDoc6);
    assertEquals(new Hex(0xe99703f200000012l), new Hex(userDocBucket1.getRawId()));
    assertEquals(new Hex(0xebfa518a00000012l), new Hex(userDocBucket2.getRawId()));
    assertEquals(new Hex(0xeac1850800000013l), new Hex(userDocBucket3.getRawId()));
    assertEquals(new Hex(0xe90ce4b09a1acd50l), new Hex(groupDocBucket1.getRawId()));
    assertEquals(new Hex(0xe9cedaa49a1acd50l), new Hex(groupDocBucket2.getRawId()));
    assertEquals(new Hex(0xe8cdb18bafe81f24l), new Hex(groupDocBucket3.getRawId()));
    assertEquals(new Hex(0xe980c9abd5fd8d11l), new Hex(docBucket1.getRawId()));
    assertEquals(new Hex(0xeafe870c5f9c37b9l), new Hex(docBucket2.getRawId()));
    assertEquals(new Hex(0xeaebe9473ecbcd69l), new Hex(docBucket3.getRawId()));
    assertEquals(new Hex(0xeae764e90000000dl), new Hex(orderDocBucket1.getRawId()));
    assertEquals(new Hex(0xeacb85f10000000dl), new Hex(orderDocBucket2.getRawId()));
    assertEquals(new Hex(0xea68ddf10000000dl), new Hex(orderDocBucket3.getRawId()));
    assertEquals(new Hex(0xe87526540000000dl), new Hex(orderDocBucket4.getRawId()));
    assertEquals(new Hex(0xea59f8f20000000dl), new Hex(orderDocBucket5.getRawId()));
    assertEquals(new Hex(0xe9eb703d0000000dl), new Hex(orderDocBucket6.getRawId()));
}
Also used : DocumentId(com.yahoo.document.DocumentId) BucketId(com.yahoo.document.BucketId) BucketIdFactory(com.yahoo.document.BucketIdFactory)

Example 34 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class ComparisonNode method compare.

private BucketSet compare(BucketIdFactory factory, IdNode id, LiteralNode literal, String operator) {
    String field = id.getField();
    Object value = literal.getValue();
    if (field == null) {
        if (value instanceof String) {
            String name = (String) value;
            if ((operator.equals("=") && name.contains("*")) || (operator.equals("=~") && ((name.contains("*") || name.contains("?"))))) {
                // no idea
                return null;
            }
            return new BucketSet(factory.getBucketId(new DocumentId(name)));
        }
    } else if (field.equalsIgnoreCase("user")) {
        if (value instanceof Long) {
            return new BucketSet(new BucketId(factory.getLocationBitCount(), (Long) value));
        }
    } else if (field.equalsIgnoreCase("group")) {
        if (value instanceof String) {
            String name = (String) value;
            if ((operator.equals("=") && name.contains("*")) || (operator.equals("=~") && ((name.contains("*") || name.contains("?"))))) {
                // no idea
                return null;
            }
            return new BucketSet(new BucketId(factory.getLocationBitCount(), new GroupDocIdString("", name, "").getLocation()));
        }
    } else if (field.equalsIgnoreCase("bucket")) {
        if (value instanceof Long) {
            return new BucketSet(new BucketId((Long) value));
        }
    }
    return null;
}
Also used : DocumentId(com.yahoo.document.DocumentId) GroupDocIdString(com.yahoo.document.idstring.GroupDocIdString) GroupDocIdString(com.yahoo.document.idstring.GroupDocIdString) BucketId(com.yahoo.document.BucketId)

Example 35 with DocumentId

use of com.yahoo.document.DocumentId in project vespa by vespa-engine.

the class VespaDocumentDeserializerHead method read.

@Override
public void read(DocumentUpdate update) {
    update.setId(new DocumentId(this));
    update.setDocumentType(readDocumentType());
    int size = getInt(null);
    for (int i = 0; i < size; i++) {
        // TODO: Should use checked method, but doesn't work according to test now.
        update.addFieldUpdateNoCheck(new FieldUpdate(this, update.getDocumentType(), 8));
    }
    int sizeAndFlags = getInt(null);
    update.setCreateIfNonExistent(DocumentUpdateFlags.extractFlags(sizeAndFlags).getCreateIfNonExistent());
    size = DocumentUpdateFlags.extractValue(sizeAndFlags);
    for (int i = 0; i < size; i++) {
        int type = getByte(null);
        update.addFieldPathUpdate(FieldPathUpdate.create(FieldPathUpdate.Type.valueOf(type), update.getDocumentType(), this));
    }
}
Also used : DocumentId(com.yahoo.document.DocumentId) FieldUpdate(com.yahoo.document.update.FieldUpdate)

Aggregations

DocumentId (com.yahoo.document.DocumentId)61 Test (org.junit.Test)28 DocumentType (com.yahoo.document.DocumentType)20 Document (com.yahoo.document.Document)16 DocumentPut (com.yahoo.document.DocumentPut)12 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)9 BucketId (com.yahoo.document.BucketId)7 DocumentRemove (com.yahoo.document.DocumentRemove)5 DocumentUpdate (com.yahoo.document.DocumentUpdate)5 BucketIdFactory (com.yahoo.document.BucketIdFactory)4 FieldUpdate (com.yahoo.document.update.FieldUpdate)4 DocumentOperation (com.yahoo.document.DocumentOperation)3 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 Hit (com.yahoo.search.result.Hit)3 HashMap (java.util.HashMap)3 TestDocumentProcessor1 (com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1)2 Field (com.yahoo.document.Field)2 GlobalId (com.yahoo.document.GlobalId)2 StructDataType (com.yahoo.document.StructDataType)2 Struct (com.yahoo.document.datatypes.Struct)2