aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/common/document_type_inspector.cpp
blob: 69f5d35c38279c6c4423b7fd91c178a3f5d5ab55 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "document_type_inspector.h"
#include <vespa/document/base/exceptions.h>
#include <vespa/document/base/fieldpath.h>

using document::FieldPath;
using document::FieldPathEntry;

namespace proton {

DocumentTypeInspector::DocumentTypeInspector(const document::DocumentType &oldDocType,
                                             const document::DocumentType &newDocType)
    : _oldDocType(oldDocType),
      _newDocType(newDocType)
{
}

bool
DocumentTypeInspector::hasUnchangedField(const vespalib::string &name) const
{
    FieldPath oldPath;
    FieldPath newPath;
    try {
        _oldDocType.buildFieldPath(oldPath, name);
        _newDocType.buildFieldPath(newPath, name);
    } catch (document::FieldNotFoundException &e) {
        return false;
    } catch (vespalib::IllegalArgumentException &e) {
        return false;
    }
    if (oldPath.size() != newPath.size()) {
        return false;
    }
    for (uint32_t i = 0; i < oldPath.size(); ++i) {
        const auto &oldEntry = oldPath[i];
        const auto &newEntry = newPath[i];
        if (oldEntry.getType() != newEntry.getType() ||
            oldEntry.getDataType() != newEntry.getDataType()) {
            return false;
        }
    }
    return true;
}

} // namespace proton