5 #ifndef JODA_JSONCONTAINER_H
6 #define JODA_JSONCONTAINER_H
16 #include <unordered_set>
27 #include <unordered_set>
28 #include "../../../../document/src/DocumentCostHandler.h"
76 unsigned long size()
const;
106 void insertDoc(std::unique_ptr<RJDocument> &&doc,
107 std::unique_ptr<IOrigin> &&origin,
size_t baseIndex = 0);
132 template <
class retType>
134 std::vector<retType> &vec);
144 for (
auto &&doc : docs) {
160 for (
auto &&doc : docs) {
180 for (
size_t i = 0; i < docs.size(); ++i) {
181 if (!ids[i])
continue;
197 template <
class F,
class R>
199 auto ret = std::vector<R>();
200 ret.reserve(ids.size());
205 for (
size_t i = 0; i < docs.size(); ++i) {
212 ret.emplace_back(f(doc,i));
231 const std::vector<std::unique_ptr<joda::query::IProjector>> &proj,
233 const std::vector<std::unique_ptr<joda::query::ISetProjector>> &setProj);
247 const std::vector<std::unique_ptr<joda::query::IProjector>> &proj,
248 const std::vector<std::unique_ptr<joda::query::ISetProjector>> &setProj);
252 const std::vector<std::unique_ptr<joda::query::IProjector>> &proj,
253 const std::vector<std::unique_ptr<joda::query::ISetProjector>> &setProj);
257 const std::vector<std::unique_ptr<joda::query::IProjector>> &proj,
258 const std::vector<std::unique_ptr<joda::query::ISetProjector>> &setProj);
296 void reparseSubset(
unsigned long start = 0,
unsigned long end = ULONG_MAX);
330 std::vector<std::string>
stringify(
unsigned long start = 0,
331 unsigned long end = ULONG_MAX);
339 std::vector<std::unique_ptr<RJDocument>>
getRaw(
340 unsigned long start = 0,
unsigned long end = ULONG_MAX);
346 std::vector<std::unique_ptr<RJDocument>>
getRaw(
const DocIndex &ids);
347 std::vector<std::unique_ptr<RJDocument>>
getRaw(
const DocIndex &ids,
350 template <
class Handler>
352 unsigned long end = ULONG_MAX) {
353 std::vector<bool> ret;
354 if (docs.empty())
return ret;
357 end = std::min(end, docs.size() - 1);
358 if (start > end)
return ret;
359 for (
unsigned long i = start; i <= end; ++i) {
363 auto &view = doc.getView();
364 ret.push_back(view->Accept(handler));
366 ret.push_back(doc.getJson()->Accept(handler));
369 ret.push_back(
false);
379 void writeFile(
const std::string &file,
bool append);
388 const std::unique_ptr<QueryCache> &
getCache()
const;
393 std::unique_ptr<const DocIndex>
getAllIDs()
const;
432 : engaged_(true), cont_(cont) {
433 cont_->useCont(parsed);
455 size_t lastParsedSize = 0;
459 std::atomic<unsigned int> usage{0};
461 inline void useCont(
bool parse =
true) {
462 if (
isView()) baseContainer->useCont(parse);
463 auto prev = usage.fetch_add(1);
468 inline void unUseCont() {
469 if (
isView()) baseContainer->unUseCont();
470 auto prev = usage.fetch_sub(1);
475 DOC_ID minID = std::numeric_limits<DOC_ID>::max();
478 bool bloomCalculated =
false;
479 bool viewsComputed =
false;
480 std::unique_ptr<QueryCache> cache;
482 void calculateBloom();
483 void recursiveBloomAttrSearch(
const RJValue &obj,
484 const std::string &attr =
"");
486 bool serializeMissing();
492 std::vector<std::string> materializedAttributes;
494 std::vector<JSONContainer *> subContainers;
495 std::unique_ptr<ViewStructure> viewStruc;
505 void insertViewDoc(std::unique_ptr<RJDocument> &&doc,
size_t baseIndex);
509 size_t theoreticalSize = 0;
513 unsigned long lastUsed = 0;
514 bool deleted =
false;
524 std::vector<RapidJsonDocument> docs;
525 std::vector<size_t> baseIds;
530 template <
class retType>
532 std::vector<retType> &vec) {
534 for (
auto &&doc : docs) {
536 vec.push_back(std::move(func(doc)));
unsigned long FILEID
Definition: FileNameRepo.h:12
std::vector< bool > DocIndex
Definition: JSONContainer.h:31
rapidjson::MemoryPoolAllocator< RJBaseAlloc > RJMemoryPoolAlloc
Definition: RJFwd.h:26
rapidjson::GenericValue< RJChar, RJMemoryPoolAlloc > RJValue
Definition: RJFwd.h:29
std::unique_ptr< RJMemoryPoolAlloc > RJMemoryPoolPointer
Definition: RapidJsonDocument.h:143
unsigned long DOC_ID
Definition: RapidJsonDocument.h:16
Definition: DocumentCostHandler.h:14
Definition: JSONContainer.h:429
~ScopedRef()
Definition: JSONContainer.h:436
ScopedRef(JSONContainer *cont, bool parsed=true)
Definition: JSONContainer.h:431
void release()
Definition: JSONContainer.h:442
Definition: JSONContainer.h:37
JSONContainer(JSONContainer &other)=delete
JSONContainer()
Definition: JSONContainer.cpp:23
void forAll(std::function< retType(RapidJsonDocument &)> &func, std::vector< retType > &vec)
Definition: JSONContainer.h:531
bool hasSpace(size_t size) const
Definition: JSONContainer.cpp:44
void materializeView()
Definition: JSONContainer.cpp:1096
bool probContainsAttr(const std::string &attr) const
Definition: JSONContainer.cpp:147
size_t getMaxSize() const
Definition: JSONContainer.cpp:920
void materializeAttributes(const std::vector< std::string > &atts)
Definition: JSONContainer.cpp:1045
virtual ~JSONContainer()
Definition: JSONContainer.cpp:981
std::unique_ptr< const DocIndex > checkDocuments(std::function< bool(RapidJsonDocument &, size_t)> &func)
Definition: JSONContainer.cpp:86
size_t estimatedSize() const
Definition: JSONContainer.cpp:770
size_t parsedSize() const
Definition: JSONContainer.cpp:1227
bool isBaseContainer(const JSONContainer *cont) const
Definition: JSONContainer.cpp:1223
void reparse()
Definition: JSONContainer.cpp:186
const std::unique_ptr< QueryCache > & getCache() const
Definition: JSONContainer.cpp:392
DocumentCostHandler createTempViewDocs(const DocIndex &ids, const std::vector< std::unique_ptr< joda::query::IProjector >> &proj, const std::vector< std::unique_ptr< joda::query::ISetProjector >> &setProj)
Definition: JSONContainer.cpp:444
void forAll(F f, const DocIndex &ids)
Definition: JSONContainer.h:176
void forAll(F &f)
Definition: JSONContainer.h:142
void reparseSubset(unsigned long start=0, unsigned long end=ULONG_MAX)
Definition: JSONContainer.cpp:252
void removeViews()
Definition: JSONContainer.cpp:1163
bool useViewBasedOnSample(const DocIndex &ids, const std::vector< std::unique_ptr< joda::query::IProjector >> &proj, const std::vector< std::unique_ptr< joda::query::ISetProjector >> &setProj)
Definition: JSONContainer.cpp:1179
void preparePurge()
Definition: JSONContainer.cpp:991
void insertDoc(std::unique_ptr< RJDocument > &&doc, std::unique_ptr< IOrigin > &&origin, size_t baseIndex=0)
Definition: JSONContainer.cpp:931
RJMemoryPoolAlloc * getAlloc()
Definition: JSONContainer.cpp:51
void setViews()
Definition: JSONContainer.cpp:1129
bool isView() const
Definition: JSONContainer.cpp:1092
void materializeAttributesIfRequired(const std::vector< std::string > &atts)
Definition: JSONContainer.cpp:996
unsigned long getLastUsed() const
Definition: JSONContainer.cpp:1094
void forAll(F f)
Definition: JSONContainer.h:158
bool hasMetaSpace(size_t size)
Definition: JSONContainer.cpp:922
void finalize()
Definition: JSONContainer.cpp:70
std::unique_ptr< JSONContainer > createViewFromContainer(const DocIndex &ids, const std::vector< std::unique_ptr< joda::query::IProjector >> &proj, const std::vector< std::unique_ptr< joda::query::ISetProjector >> &setProj)
Definition: JSONContainer.cpp:606
std::vector< bool > AcceptDocuments(Handler &handler, unsigned long start=0, unsigned long end=ULONG_MAX)
Definition: JSONContainer.h:351
auto useContInScope(bool parse=true)
Definition: JSONContainer.h:452
void metaFinalize()
Definition: JSONContainer.cpp:79
bool isReparsable()
Definition: JSONContainer.cpp:160
std::unique_ptr< const DocIndex > getAllIDs() const
Definition: JSONContainer.cpp:824
std::vector< std::unique_ptr< RJDocument > > getRaw(unsigned long start=0, unsigned long end=ULONG_MAX)
Definition: JSONContainer.cpp:828
void removeDocuments()
Definition: JSONContainer.cpp:169
std::vector< std::unique_ptr< RJDocument > > projectDocuments(const DocIndex &ids, const std::vector< std::unique_ptr< joda::query::IProjector >> &proj, RJMemoryPoolAlloc &alloc, const std::vector< std::unique_ptr< joda::query::ISetProjector >> &setProj)
Definition: JSONContainer.cpp:396
std::vector< std::string > stringify(unsigned long start=0, unsigned long end=ULONG_MAX)
Definition: JSONContainer.cpp:781
std::vector< R > forAllRet(F f, const DocIndex &ids)
Definition: JSONContainer.h:198
void writeFile(const std::string &file, bool append)
Definition: JSONContainer.cpp:817
unsigned long size() const
Definition: JSONContainer.cpp:68
Definition: RapidJsonDocument.h:22
const std::unique_ptr< const IOrigin > & getOrigin() const
Definition: RapidJsonDocument.cpp:25
Definition: bloom_filter.hpp:155
static bool storeJson
Definition: config.h:32