aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/test/attribute_utils.cpp
blob: 9dde79b342ab8efb2fc8d338b8b98cfd6fa7882f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "attribute_utils.h"
#include <vespa/vespalib/util/hdr_abort.h>
#include <vespa/searchcommon/attribute/config.h>
#include <vespa/searchlib/attribute/integerbase.h>

using search::attribute::Config;
using search::attribute::BasicType;
using search::attribute::CollectionType;

namespace proton::test {

void
AttributeUtils::fillAttribute(search::AttributeVector & attr, uint32_t numDocs, int64_t value, uint64_t lastSyncToken) {
    search::IntegerAttribute &ia = static_cast<search::IntegerAttribute &>(attr);
    ia.addDocs(numDocs);
    for (uint32_t i = 1; i < ia.getNumDocs(); ++i) {
        ia.update(i, value);
    }
    ia.commit(search::CommitParam(lastSyncToken));
}

void
AttributeUtils::fillAttribute(search::AttributeVector & attr, uint32_t from, uint32_t to, int64_t value, uint64_t lastSyncToken) {
    search::IntegerAttribute &ia = static_cast<search::IntegerAttribute &>(attr);
    while (ia.getNumDocs() < to) {
        uint32_t docId;
        if (!ia.addDoc(docId)) { HDR_ABORT("should not be reached"); }
    }
    for (uint32_t i = from; i < to; ++i) {
        ia.update(i, value);
    }
    ia.commit(search::CommitParam(lastSyncToken));
}

const Config &
AttributeUtils::getInt32Config() {
    static Config cfg(BasicType::INT32);
    return cfg;
}

const Config &
AttributeUtils::getInt32ArrayConfig() {
    static Config cfg(BasicType::INT32, CollectionType::ARRAY);
    return cfg;
}

const Config &
AttributeUtils::getStringConfig() {
    static Config cfg(BasicType::STRING);
    return cfg;
}

const Config &
AttributeUtils::getPredicateConfig() {
    static Config cfg(BasicType::PREDICATE);
    return cfg;
}

namespace {

Config tensorConfig() {
    return Config(BasicType::TENSOR).setTensorType(vespalib::eval::ValueType::from_spec("tensor(x{},y{})"));
}

}

const Config &
AttributeUtils::getTensorConfig() {
    static Config cfg = tensorConfig();
    return cfg;
}

}