1
0
Fork 0

Removed TRI_json_t from VocBase/document-collection. YaY

This commit is contained in:
Michael Hackstein 2016-01-13 15:55:46 +01:00
parent 95424f16ca
commit 9f24c7ad2f
2 changed files with 170 additions and 203 deletions

View File

@ -57,6 +57,10 @@
#include "Wal/Marker.h" #include "Wal/Marker.h"
#include "Wal/Slots.h" #include "Wal/Slots.h"
#include <velocypack/Iterator.h>
#include <velocypack/Value.h>
#include <velocypack/velocypack-aliases.h>
using namespace triagens::arango; using namespace triagens::arango;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -613,25 +617,29 @@ int TRI_AddOperationTransaction(TRI_transaction_t*,
static int FillIndex(triagens::arango::Transaction*, TRI_document_collection_t*, static int FillIndex(triagens::arango::Transaction*, TRI_document_collection_t*,
triagens::arango::Index*); triagens::arango::Index*);
static int CapConstraintFromJson(triagens::arango::Transaction*, static int CapConstraintFromVelocyPack(triagens::arango::Transaction*,
TRI_document_collection_t*, TRI_json_t const*, TRI_document_collection_t*,
TRI_idx_iid_t, triagens::arango::Index**); VPackSlice const&, TRI_idx_iid_t,
triagens::arango::Index**);
static int GeoIndexFromJson(triagens::arango::Transaction*, static int GeoIndexFromVelocyPack(triagens::arango::Transaction*,
TRI_document_collection_t*, TRI_json_t const*, TRI_document_collection_t*, VPackSlice const&,
TRI_idx_iid_t, triagens::arango::Index**); TRI_idx_iid_t, triagens::arango::Index**);
static int HashIndexFromJson(triagens::arango::Transaction*, static int HashIndexFromVelocyPack(triagens::arango::Transaction*,
TRI_document_collection_t*, TRI_json_t const*, TRI_document_collection_t*,
TRI_idx_iid_t, triagens::arango::Index**); VPackSlice const&, TRI_idx_iid_t,
triagens::arango::Index**);
static int SkiplistIndexFromJson(triagens::arango::Transaction*, static int SkiplistIndexFromVelocyPack(triagens::arango::Transaction*,
TRI_document_collection_t*, TRI_json_t const*, TRI_document_collection_t*,
TRI_idx_iid_t, triagens::arango::Index**); VPackSlice const&, TRI_idx_iid_t,
triagens::arango::Index**);
static int FulltextIndexFromJson(triagens::arango::Transaction*, static int FulltextIndexFromVelocyPack(triagens::arango::Transaction*,
TRI_document_collection_t*, TRI_json_t const*, TRI_document_collection_t*,
TRI_idx_iid_t, triagens::arango::Index**); VPackSlice const&, TRI_idx_iid_t,
triagens::arango::Index**);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief hashes a datafile identifier /// @brief hashes a datafile identifier
@ -2052,8 +2060,8 @@ static bool OpenIndexIterator(char const* filename, void* data) {
triagens::arango::Transaction* trx = ctx->trx; triagens::arango::Transaction* trx = ctx->trx;
TRI_document_collection_t* collection = ctx->collection; TRI_document_collection_t* collection = ctx->collection;
int res = int res = TRI_FromVelocyPackIndexDocumentCollection(trx, collection,
TRI_FromVelocyPackIndexDocumentCollection(trx, collection, description, nullptr); description, nullptr);
if (res != TRI_ERROR_NO_ERROR) { if (res != TRI_ERROR_NO_ERROR) {
// error was already printed if we get here // error was already printed if we get here
@ -2654,43 +2662,29 @@ size_t TRI_DocumentIteratorDocumentCollection(
int TRI_FromVelocyPackIndexDocumentCollection( int TRI_FromVelocyPackIndexDocumentCollection(
triagens::arango::Transaction* trx, TRI_document_collection_t* document, triagens::arango::Transaction* trx, TRI_document_collection_t* document,
VPackSlice const& slice, triagens::arango::Index** idx) { VPackSlice const& slice, triagens::arango::Index** idx) {
std::unique_ptr<TRI_json_t> json( TRI_ASSERT(slice.isObject());
triagens::basics::VelocyPackHelper::velocyPackToJson(slice));
return TRI_FromJsonIndexDocumentCollection(trx, document, json.get(), idx);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief create an index, based on a JSON description
////////////////////////////////////////////////////////////////////////////////
int TRI_FromJsonIndexDocumentCollection(triagens::arango::Transaction* trx,
TRI_document_collection_t* document,
TRI_json_t const* json,
triagens::arango::Index** idx) {
TRI_ASSERT(TRI_IsObjectJson(json));
if (idx != nullptr) { if (idx != nullptr) {
*idx = nullptr; *idx = nullptr;
} }
// extract the type // extract the type
TRI_json_t const* type = TRI_LookupObjectJson(json, "type"); VPackSlice type = slice.get("type");
if (!TRI_IsStringJson(type)) { if (!type.isString()) {
return TRI_ERROR_INTERNAL; return TRI_ERROR_INTERNAL;
} }
std::string typeStr = type.copyString();
char const* typeStr = type->_value._string.data;
// extract the index identifier // extract the index identifier
TRI_json_t const* iis = TRI_LookupObjectJson(json, "id"); VPackSlice iis = slice.get("id");
TRI_idx_iid_t iid; TRI_idx_iid_t iid;
if (TRI_IsNumberJson(iis)) { if (iis.isNumber()) {
iid = static_cast<TRI_idx_iid_t>(iis->_value._number); iid = iis.getNumericValue<TRI_idx_iid_t>();
} else if (TRI_IsStringJson(iis)) { } else if (iis.isString()) {
iid = (TRI_idx_iid_t)TRI_UInt64String2(iis->_value._string.data, std::string tmp = iis.copyString();
iis->_value._string.length - 1); iid = static_cast<TRI_idx_iid_t>(TRI_UInt64String(tmp.c_str()));
} else { } else {
LOG_ERROR("ignoring index, index identifier could not be located"); LOG_ERROR("ignoring index, index identifier could not be located");
@ -2702,49 +2696,42 @@ int TRI_FromJsonIndexDocumentCollection(triagens::arango::Transaction* trx,
// ........................................................................... // ...........................................................................
// CAP CONSTRAINT // CAP CONSTRAINT
// ........................................................................... // ...........................................................................
if (typeStr == "cap") {
if (TRI_EqualString(typeStr, "cap")) { return CapConstraintFromVelocyPack(trx, document, slice, iid, idx);
return CapConstraintFromJson(trx, document, json, iid, idx);
} }
// ........................................................................... // ...........................................................................
// GEO INDEX (list or attribute) // GEO INDEX (list or attribute)
// ........................................................................... // ...........................................................................
if (typeStr == "geo1" || typeStr == "geo2") {
else if (TRI_EqualString(typeStr, "geo1") || return GeoIndexFromVelocyPack(trx, document, slice, iid, idx);
TRI_EqualString(typeStr, "geo2")) {
return GeoIndexFromJson(trx, document, json, iid, idx);
} }
// ........................................................................... // ...........................................................................
// HASH INDEX // HASH INDEX
// ........................................................................... // ...........................................................................
if (typeStr == "hash") {
else if (TRI_EqualString(typeStr, "hash")) { return HashIndexFromVelocyPack(trx, document, slice, iid, idx);
return HashIndexFromJson(trx, document, json, iid, idx);
} }
// ........................................................................... // ...........................................................................
// SKIPLIST INDEX // SKIPLIST INDEX
// ........................................................................... // ...........................................................................
if (typeStr == "skiplist") {
else if (TRI_EqualString(typeStr, "skiplist")) { return SkiplistIndexFromVelocyPack(trx, document, slice, iid, idx);
return SkiplistIndexFromJson(trx, document, json, iid, idx);
} }
// ........................................................................... // ...........................................................................
// FULLTEXT INDEX // FULLTEXT INDEX
// ........................................................................... // ...........................................................................
if (typeStr == "fulltext") {
else if (TRI_EqualString(typeStr, "fulltext")) { return FulltextIndexFromVelocyPack(trx, document, slice, iid, idx);
return FulltextIndexFromJson(trx, document, json, iid, idx);
} }
// ........................................................................... // ...........................................................................
// EDGES INDEX // EDGES INDEX
// ........................................................................... // ...........................................................................
if (typeStr == "edge") {
else if (TRI_EqualString(typeStr, "edge")) {
// we should never get here, as users cannot create their own edge indexes // we should never get here, as users cannot create their own edge indexes
LOG_ERROR( LOG_ERROR(
"logic error. there should never be a JSON file describing an edges " "logic error. there should never be a JSON file describing an edges "
@ -2752,10 +2739,12 @@ int TRI_FromJsonIndexDocumentCollection(triagens::arango::Transaction* trx,
return TRI_ERROR_INTERNAL; return TRI_ERROR_INTERNAL;
} }
// default:
LOG_WARNING( LOG_WARNING(
"index type '%s' is not supported in this version of ArangoDB and is " "index type '%s' is not supported in this version of ArangoDB and is "
"ignored", "ignored",
typeStr); typeStr.c_str());
return TRI_ERROR_NO_ERROR; return TRI_ERROR_NO_ERROR;
} }
@ -3077,7 +3066,6 @@ TRI_document_collection_t* TRI_OpenDocumentCollection(TRI_vocbase_t* vocbase,
// check if we can generate the key generator // check if we can generate the key generator
std::shared_ptr<arangodb::velocypack::Buffer<uint8_t> const> buffer = std::shared_ptr<arangodb::velocypack::Buffer<uint8_t> const> buffer =
collection->_info.keyOptions(); collection->_info.keyOptions();
std::unique_ptr<TRI_json_t> json;
VPackSlice slice; VPackSlice slice;
if (buffer.get() != nullptr) { if (buffer.get() != nullptr) {
@ -3180,37 +3168,27 @@ typedef struct pid_name_s {
} pid_name_t; } pid_name_t;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief converts extracts a field list from a json object /// @brief converts extracts a field list from a VelocyPack object
/// Does not copy any data, caller has to make sure that data
/// in slice stays valid until this return value is destroyed.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static TRI_json_t* ExtractFields(TRI_json_t const* json, size_t* fieldCount, static VPackSlice ExtractFields(VPackSlice const& slice, TRI_idx_iid_t iid) {
TRI_idx_iid_t iid) { VPackSlice fld = slice.get("fields");
TRI_json_t* fld = TRI_LookupObjectJson(json, "fields"); if (!fld.isArray()) {
if (!TRI_IsArrayJson(fld)) {
LOG_ERROR("ignoring index %llu, 'fields' must be an array", LOG_ERROR("ignoring index %llu, 'fields' must be an array",
(unsigned long long)iid); (unsigned long long)iid);
THROW_ARANGO_EXCEPTION(TRI_ERROR_BAD_PARAMETER);
TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
return nullptr;
} }
*fieldCount = TRI_LengthArrayJson(fld); for (auto const& sub : VPackArrayIterator(fld)) {
if (!sub.isString()) {
for (size_t j = 0; j < *fieldCount; ++j) {
TRI_json_t* sub =
static_cast<TRI_json_t*>(TRI_AtVector(&fld->_value._objects, j));
if (!TRI_IsStringJson(sub)) {
LOG_ERROR( LOG_ERROR(
"ignoring index %llu, 'fields' must be an array of attribute paths", "ignoring index %llu, 'fields' must be an array of attribute paths",
(unsigned long long)iid); (unsigned long long)iid);
THROW_ARANGO_EXCEPTION(TRI_ERROR_BAD_PARAMETER);
TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
return nullptr;
} }
} }
return fld; return fld;
} }
@ -3513,9 +3491,9 @@ static triagens::arango::Index* LookupPathIndexDocumentCollection(
/// @brief restores a path based index (template) /// @brief restores a path based index (template)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static int PathBasedIndexFromJson( static int PathBasedIndexFromVelocyPack(
triagens::arango::Transaction* trx, TRI_document_collection_t* document, triagens::arango::Transaction* trx, TRI_document_collection_t* document,
TRI_json_t const* definition, TRI_idx_iid_t iid, VPackSlice const& definition, TRI_idx_iid_t iid,
triagens::arango::Index* (*creator)(triagens::arango::Transaction*, triagens::arango::Index* (*creator)(triagens::arango::Transaction*,
TRI_document_collection_t*, TRI_document_collection_t*,
std::vector<std::string> const&, std::vector<std::string> const&,
@ -3526,12 +3504,13 @@ static int PathBasedIndexFromJson(
} }
// extract fields // extract fields
size_t fieldCount; VPackSlice fld;
TRI_json_t const* fld = ExtractFields(definition, &fieldCount, iid); try {
fld = ExtractFields(definition, iid);
if (fld == nullptr) { } catch (triagens::basics::Exception const& e) {
return TRI_errno(); return TRI_set_errno(e.code());
} }
VPackValueLength fieldCount = fld.length();
// extract the list of fields // extract the list of fields
if (fieldCount < 1) { if (fieldCount < 1) {
@ -3542,32 +3521,32 @@ static int PathBasedIndexFromJson(
} }
// determine if the index is unique or non-unique // determine if the index is unique or non-unique
TRI_json_t const* bv = TRI_LookupObjectJson(definition, "unique"); VPackSlice bv = definition.get("unique");
if (!TRI_IsBooleanJson(bv)) { if (!bv.isBoolean()) {
LOG_ERROR( LOG_ERROR(
"ignoring index %llu, could not determine if unique or non-unique", "ignoring index %llu, could not determine if unique or non-unique",
(unsigned long long)iid); (unsigned long long)iid);
return TRI_set_errno(TRI_ERROR_BAD_PARAMETER); return TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
} }
bool unique = bv->_value._boolean; bool unique = bv.getBoolean();
// determine sparsity // determine sparsity
bool sparse = false; bool sparse = false;
bv = TRI_LookupObjectJson(definition, "sparse"); bv = definition.get("sparse");
if (TRI_IsBooleanJson(bv)) { if (bv.isBoolean()) {
sparse = bv->_value._boolean; sparse = bv.getBoolean();
} else { } else {
// no sparsity information given for index // no sparsity information given for index
// now use pre-2.5 defaults: unique hash indexes were sparse, all other // now use pre-2.5 defaults: unique hash indexes were sparse, all other
// indexes were non-sparse // indexes were non-sparse
bool isHashIndex = false; bool isHashIndex = false;
TRI_json_t const* typeJson = TRI_LookupObjectJson(definition, "type"); VPackSlice typeSlice = definition.get("type");
if (TRI_IsStringJson(typeJson)) { if (typeSlice.isString()) {
isHashIndex = (strcmp(typeJson->_value._string.data, "hash") == 0); isHashIndex = typeSlice.copyString() == "hash";
} }
if (isHashIndex && unique) { if (isHashIndex && unique) {
@ -3581,13 +3560,8 @@ static int PathBasedIndexFromJson(
attributes.reserve(fieldCount); attributes.reserve(fieldCount);
// find fields // find fields
for (size_t j = 0; j < fieldCount; ++j) { for (auto const& fieldStr : VPackArrayIterator(fld)) {
auto fieldStr = attributes.emplace_back(fieldStr.copyString());
static_cast<TRI_json_t const*>(TRI_AtVector(&fld->_value._objects, j));
attributes.emplace_back(std::string(fieldStr->_value._string.data,
fieldStr->_value._string.length - 1));
;
} }
// create the index // create the index
@ -3934,19 +3908,19 @@ static triagens::arango::Index* CreateCapConstraintDocumentCollection(
/// @brief restores an index /// @brief restores an index
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static int CapConstraintFromJson(triagens::arango::Transaction* trx, static int CapConstraintFromVelocyPack(triagens::arango::Transaction* trx,
TRI_document_collection_t* document, TRI_document_collection_t* document,
TRI_json_t const* definition, VPackSlice const& definition,
TRI_idx_iid_t iid, TRI_idx_iid_t iid,
triagens::arango::Index** dst) { triagens::arango::Index** dst) {
if (dst != nullptr) { if (dst != nullptr) {
*dst = nullptr; *dst = nullptr;
} }
TRI_json_t const* val1 = TRI_LookupObjectJson(definition, "size"); VPackSlice val1 = definition.get("size");
TRI_json_t const* val2 = TRI_LookupObjectJson(definition, "byteSize"); VPackSlice val2 = definition.get("byteSize");
if (!TRI_IsNumberJson(val1) && !TRI_IsNumberJson(val2)) { if (!val1.isNumber() && !val2.isNumber()) {
LOG_ERROR("ignoring cap constraint %llu, 'size' and 'byteSize' missing", LOG_ERROR("ignoring cap constraint %llu, 'size' and 'byteSize' missing",
(unsigned long long)iid); (unsigned long long)iid);
@ -3954,15 +3928,30 @@ static int CapConstraintFromJson(triagens::arango::Transaction* trx,
} }
size_t count = 0; size_t count = 0;
if (TRI_IsNumberJson(val1) && val1->_value._number > 0.0) { if (val1.isNumber()) {
count = static_cast<size_t>(val1->_value._number); if (val1.isDouble()) {
double tmp = val1.getDouble();
if (tmp > 0.0) {
count = static_cast<size_t>(tmp);
}
} else {
count = val1.getNumericValue<size_t>();
}
} }
int64_t size = 0; int64_t size = 0;
if (TRI_IsNumberJson(val2) && if (val2.isNumber()) {
val2->_value._number > if (val2.isDouble()) {
static_cast<double>(triagens::arango::CapConstraint::MinSize)) { double tmp = val2.getDouble();
size = static_cast<int64_t>(val2->_value._number); if (tmp > triagens::arango::CapConstraint::MinSize) {
size = static_cast<int64_t>(tmp);
}
} else {
int64_t tmp = val2.getNumericValue<int64_t>();
if (tmp > triagens::arango::CapConstraint::MinSize) {
size = static_cast<int64_t>(tmp);
}
}
} }
if (count == 0 && size == 0) { if (count == 0 && size == 0) {
@ -4151,52 +4140,48 @@ static triagens::arango::Index* CreateGeoIndexDocumentCollection(
/// @brief restores an index /// @brief restores an index
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static int GeoIndexFromJson(triagens::arango::Transaction* trx, static int GeoIndexFromVelocyPack(triagens::arango::Transaction* trx,
TRI_document_collection_t* document, TRI_document_collection_t* document,
TRI_json_t const* definition, TRI_idx_iid_t iid, VPackSlice const& definition,
triagens::arango::Index** dst) { TRI_idx_iid_t iid,
triagens::arango::Index** dst) {
if (dst != nullptr) { if (dst != nullptr) {
*dst = nullptr; *dst = nullptr;
} }
TRI_json_t const* type = TRI_LookupObjectJson(definition, "type"); VPackSlice const type = definition.get("type");
if (!TRI_IsStringJson(type)) { if (!type.isString()) {
return TRI_ERROR_INTERNAL; return TRI_ERROR_INTERNAL;
} }
char const* typeStr = type->_value._string.data; std::string typeStr = type.copyString();
// extract fields // extract fields
size_t fieldCount; VPackSlice fld;
TRI_json_t* fld = ExtractFields(definition, &fieldCount, iid); try {
fld = ExtractFields(definition, iid);
if (fld == nullptr) { } catch (triagens::basics::Exception const& e) {
return TRI_errno(); return TRI_set_errno(e.code());
} }
VPackValueLength fieldCount = fld.length();
triagens::arango::Index* idx = nullptr; triagens::arango::Index* idx = nullptr;
// list style // list style
if (TRI_EqualString(typeStr, "geo1")) { if (typeStr == "geo1") {
// extract geo json // extract geo json
bool geoJson = false; bool geoJson = triagens::basics::VelocyPackHelper::getBooleanValue(
TRI_json_t const* bv = TRI_LookupObjectJson(definition, "geoJson"); definition, "geoJson", false);
if (TRI_IsBooleanJson(bv)) {
geoJson = bv->_value._boolean;
}
// need just one field // need just one field
if (fieldCount == 1) { if (fieldCount == 1) {
auto loc = static_cast<TRI_json_t const*>( VPackSlice loc = fld.at(0);
TRI_AtVector(&fld->_value._objects, 0));
bool created; bool created;
idx = CreateGeoIndexDocumentCollection( idx = CreateGeoIndexDocumentCollection(trx, document, loc.copyString(),
trx, document, std::string(), std::string(),
std::string(loc->_value._string.data, loc->_value._string.length - 1), geoJson, iid, created);
std::string(), std::string(), geoJson, iid, created);
if (dst != nullptr) { if (dst != nullptr) {
*dst = idx; *dst = idx;
@ -4206,26 +4191,23 @@ static int GeoIndexFromJson(triagens::arango::Transaction* trx,
} else { } else {
LOG_ERROR( LOG_ERROR(
"ignoring %s-index %llu, 'fields' must be a list with 1 entries", "ignoring %s-index %llu, 'fields' must be a list with 1 entries",
typeStr, (unsigned long long)iid); typeStr.c_str(), (unsigned long long)iid);
return TRI_set_errno(TRI_ERROR_BAD_PARAMETER); return TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
} }
} }
// attribute style // attribute style
else if (TRI_EqualString(typeStr, "geo2")) { else if (typeStr == "geo2") {
if (fieldCount == 2) { if (fieldCount == 2) {
auto lat = static_cast<TRI_json_t const*>( VPackSlice lat = fld.at(0);
TRI_AtVector(&fld->_value._objects, 0)); VPackSlice lon = fld.at(1);
auto lon = static_cast<TRI_json_t const*>(
TRI_AtVector(&fld->_value._objects, 1));
bool created; bool created;
idx = CreateGeoIndexDocumentCollection( idx = CreateGeoIndexDocumentCollection(trx, document, std::string(),
trx, document, std::string(), lat.copyString(), lon.copyString(),
std::string(lat->_value._string.data, lat->_value._string.length - 1), false, iid, created);
std::string(lon->_value._string.data, lon->_value._string.length - 1),
false, iid, created);
if (dst != nullptr) { if (dst != nullptr) {
*dst = idx; *dst = idx;
@ -4235,13 +4217,11 @@ static int GeoIndexFromJson(triagens::arango::Transaction* trx,
} else { } else {
LOG_ERROR( LOG_ERROR(
"ignoring %s-index %llu, 'fields' must be a list with 2 entries", "ignoring %s-index %llu, 'fields' must be a list with 2 entries",
typeStr, (unsigned long long)iid); typeStr.c_str(), (unsigned long long)iid);
return TRI_set_errno(TRI_ERROR_BAD_PARAMETER); return TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
} }
} } else {
else {
TRI_ASSERT(false); TRI_ASSERT(false);
} }
@ -4444,12 +4424,13 @@ static triagens::arango::Index* CreateHashIndexDocumentCollection(
/// @brief restores an index /// @brief restores an index
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static int HashIndexFromJson(triagens::arango::Transaction* trx, static int HashIndexFromVelocyPack(triagens::arango::Transaction* trx,
TRI_document_collection_t* document, TRI_document_collection_t* document,
TRI_json_t const* definition, TRI_idx_iid_t iid, VPackSlice const& definition,
triagens::arango::Index** dst) { TRI_idx_iid_t iid,
return PathBasedIndexFromJson(trx, document, definition, iid, triagens::arango::Index** dst) {
CreateHashIndexDocumentCollection, dst); return PathBasedIndexFromVelocyPack(trx, document, definition, iid,
CreateHashIndexDocumentCollection, dst);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -4583,13 +4564,14 @@ static triagens::arango::Index* CreateSkiplistIndexDocumentCollection(
/// @brief restores an index /// @brief restores an index
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static int SkiplistIndexFromJson(triagens::arango::Transaction* trx, static int SkiplistIndexFromVelocyPack(triagens::arango::Transaction* trx,
TRI_document_collection_t* document, TRI_document_collection_t* document,
TRI_json_t const* definition, VPackSlice const& definition,
TRI_idx_iid_t iid, TRI_idx_iid_t iid,
triagens::arango::Index** dst) { triagens::arango::Index** dst) {
return PathBasedIndexFromJson(trx, document, definition, iid, return PathBasedIndexFromVelocyPack(trx, document, definition, iid,
CreateSkiplistIndexDocumentCollection, dst); CreateSkiplistIndexDocumentCollection,
dst);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -4726,22 +4708,23 @@ static triagens::arango::Index* CreateFulltextIndexDocumentCollection(
/// @brief restores an index /// @brief restores an index
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static int FulltextIndexFromJson(triagens::arango::Transaction* trx, static int FulltextIndexFromVelocyPack(triagens::arango::Transaction* trx,
TRI_document_collection_t* document, TRI_document_collection_t* document,
TRI_json_t const* definition, VPackSlice const& definition,
TRI_idx_iid_t iid, TRI_idx_iid_t iid,
triagens::arango::Index** dst) { triagens::arango::Index** dst) {
if (dst != nullptr) { if (dst != nullptr) {
*dst = nullptr; *dst = nullptr;
} }
// extract fields // extract fields
size_t fieldCount; VPackSlice fld;
TRI_json_t* fld = ExtractFields(definition, &fieldCount, iid); try {
fld = ExtractFields(definition, iid);
if (fld == nullptr) { } catch (triagens::basics::Exception const& e) {
return TRI_errno(); return TRI_set_errno(e.code());
} }
VPackValueLength fieldCount = fld.length();
// extract the list of fields // extract the list of fields
if (fieldCount != 1) { if (fieldCount != 1) {
@ -4751,26 +4734,20 @@ static int FulltextIndexFromJson(triagens::arango::Transaction* trx,
return TRI_set_errno(TRI_ERROR_BAD_PARAMETER); return TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
} }
auto value = VPackSlice value = fld.at(0);
static_cast<TRI_json_t const*>(TRI_AtVector(&fld->_value._objects, 0));
if (!TRI_IsStringJson(value)) { if (!value.isString()) {
return TRI_set_errno(TRI_ERROR_BAD_PARAMETER); return TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
} }
std::string const attribute(value->_value._string.data, std::string const attribute = value.copyString();
value->_value._string.length - 1);
// 2013-01-17: deactivated substring indexing // 2013-01-17: deactivated substring indexing
// indexSubstrings = TRI_LookupObjectJson(definition, "indexSubstrings"); // indexSubstrings = TRI_LookupObjectJson(definition, "indexSubstrings");
int minWordLengthValue = TRI_FULLTEXT_MIN_WORD_LENGTH_DEFAULT; int minWordLengthValue =
TRI_json_t const* minWordLength = triagens::basics::VelocyPackHelper::getNumericValue<int>(
TRI_LookupObjectJson(definition, "minLength"); definition, "minLength", TRI_FULLTEXT_MIN_WORD_LENGTH_DEFAULT);
if (minWordLength != nullptr && minWordLength->_type == TRI_JSON_NUMBER) {
minWordLengthValue = (int)minWordLength->_value._number;
}
// create the index // create the index
auto idx = LookupFulltextIndexDocumentCollection(document, attribute, auto idx = LookupFulltextIndexDocumentCollection(document, attribute,

View File

@ -44,7 +44,6 @@
struct TRI_cap_constraint_s; struct TRI_cap_constraint_s;
struct TRI_document_edge_s; struct TRI_document_edge_s;
struct TRI_json_t;
class TRI_headers_t; class TRI_headers_t;
class VocShaper; class VocShaper;
@ -780,15 +779,6 @@ int TRI_FromVelocyPackIndexDocumentCollection(triagens::arango::Transaction*,
VPackSlice const&, VPackSlice const&,
triagens::arango::Index**); triagens::arango::Index**);
////////////////////////////////////////////////////////////////////////////////
/// @brief create an index, based on a JSON description
////////////////////////////////////////////////////////////////////////////////
int TRI_FromJsonIndexDocumentCollection(triagens::arango::Transaction*,
TRI_document_collection_t*,
struct TRI_json_t const*,
triagens::arango::Index**);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief rolls back a document operation /// @brief rolls back a document operation
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////