mirror of https://gitee.com/bigwinds/arangodb
139 lines
3.9 KiB
C++
139 lines
3.9 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
/// DISCLAIMER
|
|
///
|
|
/// Copyright 2018 ArangoDB GmbH, Cologne, Germany
|
|
///
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
/// you may not use this file except in compliance with the License.
|
|
/// You may obtain a copy of the License at
|
|
///
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
///
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
/// See the License for the specific language governing permissions and
|
|
/// limitations under the License.
|
|
///
|
|
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
|
///
|
|
/// @author Andrey Abramov
|
|
/// @author Vasiliy Nabatchikov
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "IResearchLinkHelper.h"
|
|
#include "IResearchCommon.h"
|
|
#include "IResearchLinkMeta.h"
|
|
#include "IResearchFeature.h"
|
|
|
|
namespace {
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief the string representing the link type
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
static const std::string& LINK_TYPE =
|
|
arangodb::iresearch::DATA_SOURCE_TYPE.name();
|
|
|
|
}
|
|
|
|
namespace arangodb {
|
|
namespace iresearch {
|
|
|
|
/*static*/ VPackSlice const& IResearchLinkHelper::emptyIndexSlice() {
|
|
static const struct EmptySlice {
|
|
VPackBuilder _builder;
|
|
VPackSlice _slice;
|
|
EmptySlice() {
|
|
VPackBuilder fieldsBuilder;
|
|
|
|
fieldsBuilder.openArray();
|
|
fieldsBuilder.close(); // empty array
|
|
_builder.openObject();
|
|
_builder.add("fields", fieldsBuilder.slice()); // empty array
|
|
arangodb::iresearch::IResearchLinkHelper::setType(_builder); // the index type required by Index
|
|
_builder.close(); // object with just one field required by the Index constructor
|
|
_slice = _builder.slice();
|
|
}
|
|
} emptySlice;
|
|
|
|
return emptySlice._slice;
|
|
}
|
|
|
|
/*static*/ arangodb::Result IResearchLinkHelper::normalize(
|
|
arangodb::velocypack::Builder& normalized,
|
|
velocypack::Slice definition,
|
|
bool // isCreation
|
|
) {
|
|
if (!normalized.isOpenObject()) {
|
|
return arangodb::Result(
|
|
TRI_ERROR_BAD_PARAMETER,
|
|
std::string("invalid output buffer provided for IResearch link normalized definition generation")
|
|
);
|
|
}
|
|
|
|
std::string error;
|
|
IResearchLinkMeta meta;
|
|
|
|
if (!meta.init(definition, error)) {
|
|
return arangodb::Result(
|
|
TRI_ERROR_BAD_PARAMETER,
|
|
std::string("error parsing IResearch link parameters from json: ") + error
|
|
);
|
|
}
|
|
|
|
IResearchLinkHelper::setType(normalized);
|
|
|
|
// copy over IResearch View identifier
|
|
if (definition.hasKey(StaticStrings::ViewIdField)) {
|
|
normalized.add(StaticStrings::ViewIdField, definition.get(StaticStrings::ViewIdField));
|
|
}
|
|
|
|
return meta.json(normalized)
|
|
? arangodb::Result()
|
|
: arangodb::Result(
|
|
TRI_ERROR_BAD_PARAMETER,
|
|
std::string("error generating IResearch link normalized definition")
|
|
)
|
|
;
|
|
}
|
|
|
|
/*static*/ bool IResearchLinkHelper::setType(velocypack::Builder& builder) {
|
|
if (!builder.isOpenObject()) {
|
|
return false;
|
|
}
|
|
|
|
builder.add(StaticStrings::LinkTypeField, velocypack::Value(LINK_TYPE));
|
|
|
|
return true;
|
|
}
|
|
|
|
/*static*/ bool IResearchLinkHelper::setView(
|
|
velocypack::Builder& builder,
|
|
TRI_voc_cid_t value
|
|
) {
|
|
if (!builder.isOpenObject()) {
|
|
return false;
|
|
}
|
|
|
|
builder.add(StaticStrings::ViewIdField, velocypack::Value(value));
|
|
|
|
return true;
|
|
}
|
|
|
|
/*static*/ velocypack::Slice IResearchLinkHelper::getView(
|
|
velocypack::Slice definition
|
|
) noexcept {
|
|
try {
|
|
return definition.get(StaticStrings::ViewIdField);
|
|
} catch (...) {
|
|
return VPackSlice::noneSlice();
|
|
}
|
|
}
|
|
|
|
/*static*/ std::string const& IResearchLinkHelper::type() noexcept {
|
|
return LINK_TYPE;
|
|
}
|
|
|
|
} // iresearch
|
|
} // arangodb
|