Buggy second step

This commit is contained in:
János Benjamin Antal 2023-03-22 10:42:51 +01:00
parent a6e79fc9d9
commit 85482dfaf2

View File

@ -2183,7 +2183,13 @@ class OptionalCursor : public Cursor {
EnsureOwnMultiFramesAreGood(output_multi_frame); EnsureOwnMultiFramesAreGood(output_multi_frame);
auto populated_any{false}; auto populated_any{false};
auto output_frames_populator = output_multi_frame.GetInvalidFramesPopulator();
auto output_frames_it = output_frames_populator.begin();
while (true) { while (true) {
if (output_frames_it == output_frames_populator.end()) {
return populated_any;
}
switch (state_) { switch (state_) {
case State::PullInput: { case State::PullInput: {
if (!input_cursor_->PullMultiple(*own_multi_frame_, context)) { if (!input_cursor_->PullMultiple(*own_multi_frame_, context)) {
@ -2199,18 +2205,19 @@ class OptionalCursor : public Cursor {
optional_cursor_->PushDown(*own_multi_frame_); optional_cursor_->PushDown(*own_multi_frame_);
own_frames_consumer_ = own_multi_frame_->GetValidFramesConsumer(); own_frames_consumer_ = own_multi_frame_->GetValidFramesConsumer();
own_frames_it_ = own_frames_consumer_->begin(); own_frames_it_ = own_frames_consumer_->begin();
if (!optional_frames_consumer_.has_value() || optional_frames_it_ == optional_frames_consumer_->end()) { state_ = State::PullOptional;
state_ = State::PullOptional;
} else {
state_ = State::Populate;
}
break; break;
} }
case State::PullOptional: { case State::PullOptional: {
optional_cursor_->PullMultiple(*optional_multi_frame_, context); if (!optional_cursor_->PullMultiple(*optional_multi_frame_, context)) {
optional_frames_consumer_ = optional_multi_frame_->GetValidFramesConsumer(); state_ = State::OptionalExhausted;
optional_frames_it_ = optional_frames_consumer_->begin(); optional_frames_consumer_.reset();
state_ = State::Populate; optional_frames_it_ = {};
} else {
optional_frames_consumer_ = optional_multi_frame_->GetValidFramesConsumer();
optional_frames_it_ = optional_frames_consumer_->begin();
state_ = State::Populate;
}
break; break;
} }
case State::Populate: { case State::Populate: {
@ -2218,20 +2225,26 @@ class OptionalCursor : public Cursor {
state_ = State::PullInput; state_ = State::PullInput;
continue; continue;
} }
auto output_frames_populator = output_multi_frame.GetInvalidFramesPopulator();
auto output_frames_it = output_frames_populator.begin();
while (own_frames_it_ != own_frames_consumer_->end() && output_frames_it != output_frames_populator.end()) { while (own_frames_it_ != own_frames_consumer_->end() && output_frames_it != output_frames_populator.end()) {
if (optional_frames_it_ != optional_frames_consumer_->end() && if (optional_frames_consumer_.has_value() && optional_frames_it_ != optional_frames_consumer_->end() &&
optional_frames_it_->Id() == own_frames_it_->Id()) { optional_frames_it_->Id() == own_frames_it_->Id()) {
// This might be a move, but then in we have to have special logic is EnsureOwnMultiFramesAreGood // This might be a move, but then in we have to have special logic is EnsureOwnMultiFramesAreGood
*output_frames_it = *optional_frames_it_; *output_frames_it = *optional_frames_it_;
++optional_frames_it_; ++optional_frames_it_;
++output_frames_it;
if (optional_frames_it_ == optional_frames_consumer_->end()) {
++own_frames_it_;
state_ = State::PullOptional;
populated_any = true;
break;
}
if (optional_frames_it_->Id() != own_frames_it_->Id()) { if (optional_frames_it_->Id() != own_frames_it_->Id()) {
++own_frames_it_; ++own_frames_it_;
} }
} else { } else {
// TODO(antaljanosbenjamin): Remove (or improve the message of) this assert // TODO(antaljanosbenjamin): Remove (or improve the message of) this assert
MG_ASSERT(optional_frames_it_ == optional_frames_consumer_->end() || MG_ASSERT(!optional_frames_consumer_.has_value() ||
optional_frames_it_ == optional_frames_consumer_->end() ||
optional_frames_it_->Id() > own_frames_it_->Id(), optional_frames_it_->Id() > own_frames_it_->Id(),
"This should be the case DELETE ME"); "This should be the case DELETE ME");
for (const auto &symbol : self_.optional_symbols_) { for (const auto &symbol : self_.optional_symbols_) {
@ -2242,9 +2255,26 @@ class OptionalCursor : public Cursor {
*output_frames_it = *own_frames_it_; *output_frames_it = *own_frames_it_;
++own_frames_it_; ++own_frames_it_;
} }
}
break;
}
case State::OptionalExhausted: {
while (own_frames_it_ != own_frames_consumer_->end() && output_frames_it != output_frames_populator.end()) {
MG_ASSERT(!optional_frames_consumer_.has_value(), "This should be the case DELETE ME");
for (const auto &symbol : self_.optional_symbols_) {
spdlog::error("{}", symbol.name());
(*own_frames_it_)[symbol] = TypedValue(context.evaluation_context.memory);
}
// This might be a move, but then in we have to have special logic is EnsureOwnMultiFramesAreGood
*output_frames_it = *own_frames_it_;
++own_frames_it_;
populated_any = true; populated_any = true;
++output_frames_it; ++output_frames_it;
} }
if (own_frames_it_ == own_frames_consumer_->end()) {
state_ = State::PullInput;
}
break; break;
} }
case State::Exhausted: { case State::Exhausted: {
@ -2267,7 +2297,7 @@ class OptionalCursor : public Cursor {
} }
private: private:
enum class State { PullInput, PullOptional, Populate, Exhausted }; enum class State { PullInput, PullOptional, Populate, OptionalExhausted, Exhausted };
void EnsureOwnMultiFramesAreGood(MultiFrame &output_multi_frame) { void EnsureOwnMultiFramesAreGood(MultiFrame &output_multi_frame) {
if (!own_multi_frame_.has_value()) { if (!own_multi_frame_.has_value()) {
@ -3531,7 +3561,9 @@ class DistributedExpandCursor : public Cursor {
result_rows_.clear(); result_rows_.clear();
own_frames_it_ = ValidFramesConsumer::Iterator{}; own_frames_it_ = ValidFramesConsumer::Iterator{};
own_frames_consumer_.reset(); own_frames_consumer_.reset();
own_multi_frame_->MakeAllFramesInvalid(); if (own_multi_frame_.has_value()) {
own_multi_frame_->MakeAllFramesInvalid();
}
state_ = State::PullInputAndEdges; state_ = State::PullInputAndEdges;
current_in_edges_.clear(); current_in_edges_.clear();