-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[realppl 2] Minimalistic ppl offline evaluation #14827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: wuandy/RealPpl_1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2025 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "Firestore/core/src/api/realtime_pipeline.h" | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include "Firestore/core/src/remote/serializer.h" | ||
|
||
namespace firebase { | ||
namespace firestore { | ||
namespace api { | ||
|
||
RealtimePipeline::RealtimePipeline( | ||
std::vector<std::shared_ptr<EvaluableStage>> stages, | ||
remote::Serializer serializer) | ||
: stages_(std::move(stages)), serializer_(serializer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can also move the serializer. |
||
} | ||
|
||
RealtimePipeline RealtimePipeline::AddingStage( | ||
std::shared_ptr<EvaluableStage> stage) { | ||
auto copy = std::vector<std::shared_ptr<EvaluableStage>>(this->stages_); | ||
copy.push_back(stage); | ||
|
||
return {copy, serializer_}; | ||
} | ||
|
||
const std::vector<std::shared_ptr<EvaluableStage>>& RealtimePipeline::stages() | ||
const { | ||
return this->stages_; | ||
} | ||
|
||
EvaluateContext RealtimePipeline::evaluate_context() { | ||
return EvaluateContext(&serializer_); | ||
} | ||
|
||
} // namespace api | ||
} // namespace firestore | ||
} // namespace firebase |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2025 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
#ifndef FIRESTORE_CORE_SRC_API_REALTIME_PIPELINE_H_ | ||
#define FIRESTORE_CORE_SRC_API_REALTIME_PIPELINE_H_ | ||
|
||
#include <memory> | ||
#include <utility> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it doesn't look like we need |
||
#include <vector> | ||
|
||
#include "Firestore/core/src/api/firestore.h" | ||
#include "Firestore/core/src/api/pipeline_snapshot.h" | ||
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like you need firestore.h nor pipeline_snapshot.h here. |
||
#include "Firestore/core/src/api/stages.h" | ||
#include "Firestore/core/src/remote/serializer.h" | ||
|
||
namespace firebase { | ||
namespace firestore { | ||
namespace api { | ||
|
||
class RealtimePipeline { | ||
public: | ||
RealtimePipeline(std::vector<std::shared_ptr<EvaluableStage>> stages, | ||
remote::Serializer serializer); | ||
|
||
RealtimePipeline AddingStage(std::shared_ptr<EvaluableStage> stage); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be |
||
|
||
const std::vector<std::shared_ptr<EvaluableStage>>& stages() const; | ||
|
||
EvaluateContext evaluate_context(); | ||
|
||
private: | ||
std::vector<std::shared_ptr<EvaluableStage>> stages_; | ||
remote::Serializer serializer_; | ||
}; | ||
|
||
} // namespace api | ||
} // namespace firestore | ||
} // namespace firebase | ||
|
||
#endif // FIRESTORE_CORE_SRC_API_REALTIME_PIPELINE_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,26 @@ | |
|
||
#include "Firestore/core/src/api/stages.h" | ||
|
||
#include <algorithm> | ||
#include <memory> | ||
#include <stdexcept> | ||
#include <unordered_map> | ||
#include <unordered_set> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "Firestore/Protos/nanopb/google/firestore/v1/document.nanopb.h" | ||
#include "Firestore/core/src/api/pipeline.h" | ||
#include "Firestore/core/src/core/expressions_eval.h" | ||
#include "Firestore/core/src/model/document.h" | ||
#include "Firestore/core/src/model/document_key.h" | ||
#include "Firestore/core/src/model/mutable_document.h" | ||
#include "Firestore/core/src/model/resource_path.h" | ||
#include "Firestore/core/src/model/value_util.h" | ||
#include "Firestore/core/src/nanopb/message.h" | ||
#include "Firestore/core/src/nanopb/nanopb_util.h" | ||
#include "Firestore/core/src/util/comparison.h" | ||
#include "Firestore/core/src/util/hard_assert.h" | ||
|
||
namespace firebase { | ||
namespace firestore { | ||
|
@@ -461,6 +474,62 @@ google_firestore_v1_Pipeline_Stage RawStage::to_proto() const { | |
return result; | ||
} | ||
|
||
model::PipelineInputOutputVector CollectionSource::Evaluate( | ||
const EvaluateContext& /*context*/, | ||
const model::PipelineInputOutputVector& inputs) const { | ||
model::PipelineInputOutputVector results; | ||
std::copy_if(inputs.begin(), inputs.end(), std::back_inserter(results), | ||
[this](const model::MutableDocument& doc) { | ||
return doc.is_found_document() && | ||
doc.key().path().PopLast().CanonicalString() == path_; | ||
}); | ||
return results; | ||
} | ||
|
||
model::PipelineInputOutputVector DatabaseSource::Evaluate( | ||
const EvaluateContext& /*context*/, | ||
const model::PipelineInputOutputVector& inputs) const { | ||
model::PipelineInputOutputVector results; | ||
std::copy_if(inputs.begin(), inputs.end(), std::back_inserter(results), | ||
[](const model::MutableDocument& doc) { | ||
return doc.is_found_document(); | ||
}); | ||
return results; | ||
} | ||
|
||
model::PipelineInputOutputVector Where::Evaluate( | ||
const EvaluateContext& context, | ||
const model::PipelineInputOutputVector& inputs) const { | ||
model::PipelineInputOutputVector results; | ||
const auto evaluable_expr = expr_->ToEvaluable(); | ||
const auto true_value = model::TrueValue(); | ||
|
||
for (const auto& doc : inputs) { | ||
auto result = evaluable_expr->Evaluate(context, doc); | ||
if (!result.IsErrorOrUnset() && | ||
model::Equals(*result.value(), true_value)) { | ||
results.push_back(doc); | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
|
||
model::PipelineInputOutputVector LimitStage::Evaluate( | ||
const EvaluateContext& /*context*/, | ||
const model::PipelineInputOutputVector& inputs) const { | ||
if (limit_ < 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this can be |
||
// Or handle as error? Assuming non-negative limit. | ||
return {}; | ||
} | ||
size_t count = static_cast<size_t>(limit_); | ||
if (count > inputs.size()) { | ||
count = inputs.size(); | ||
} | ||
return model::PipelineInputOutputVector(inputs.begin(), | ||
inputs.begin() + count); | ||
} | ||
|
||
} // namespace api | ||
} // namespace firestore | ||
} // namespace firebase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use
virtual ~Selectable() override = default;
the rule of thumb is: if a class has at least one virtual function, it should have a virtual destructor