Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create UnitLoader (facebookincubator#9259)
Summary: Pull Request resolved: facebookincubator#9259 Add capability to add prefetch policies to readers through UnitLoaders. ## Usage and responsibilities ``` class LoadStripe : public LoadUnit{/* ... */}; class MyLoadPolicy : public IUnitLoader{/* ... */}; class MyLoadPolicyFactory : IUnitLoaderFactory { public: virtual std::unique_ptr<IUnitLoader> create( std::vector<std::unique_ptr<LoadUnit>> readPlan) { return std::make_unique<MyLoadPolicy>(readPlan); } }; class Reader { public: Reader(IUnitLoaderFactory& factory) { // Read footer and figure out stripe metrics // auto readPlan = ... unitLoader_ = factory.create(readPlan); } bool read(Batch& batch) { if (currentRowInStripe_ > rowsInStripe(currentStripe_)) { if (++currentStripe_ > stripeCount_) { return false; } currentRowInStripe_ = 0; // Ask for loaded units auto loadUnit = unitLoader_->loadUnit(currentStripe_); auto loadedStripe = dynamic_cast<LoadStripe&>(*loadUnit); data_ = loadedStripe->getMyData(); } uint64_t rowCountToRead = // ... // Report progress unitLoader_->onRead(currentStripe_, currentRowInStripe_, rowCountToRead); return data_->read(batch); } private: std::unique_ptr<IUnitLoader> unitLoader_; uint64_t currentStripe_; uint64_t currentRowInStripe_; }; Reviewed By: helfman Differential Revision: D54837547 fbshipit-source-id: b02542214a412f441a5fde55404d5bfda84fc294
- Loading branch information