<commit_before>//===----------------------------------------------------------------------===//
//
//                         Peloton
//
// hybrid_scan_executor.cpp
//
// Identification: src/executor/hybrid_scan_executor.cpp
//
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include <memory>
#include <utility>
#include <vector>
#include <string>
#include <unordered_map>
#include <chrono>
#include <iostream>
#include <ctime>
#include <cassert>
#include <thread>

#include "common/timer.h"
#include "common/types.h"
#include "executor/logical_tile.h"
#include "executor/logical_tile_factory.h"
#include "executor/executor_context.h"
#include "expression/abstract_expression.h"
#include "expression/container_tuple.h"
#include "planner/hybrid_scan_plan.h"
#include "executor/hybrid_scan_executor.h"
#include "storage/data_table.h"
#include "storage/tile_group_header.h"
#include "storage/tile.h"
#include "concurrency/transaction_manager_factory.h"
#include "common/logger.h"

namespace peloton {
namespace executor {

HybridScanExecutor::HybridScanExecutor(const planner::AbstractPlan *node,
                                       ExecutorContext *executor_context)
    : AbstractScanExecutor(node, executor_context),
      indexed_tile_offset_(START_OID) {}

bool HybridScanExecutor::DInit() {
  auto status = AbstractScanExecutor::DInit();

  if (!status) return false;

  const planner::HybridScanPlan &node = GetPlanNode<planner::HybridScanPlan>();

  table_ = node.GetTable();
  index_ = node.GetDataIndex();
  type_ = node.GetHybridType();

  if (type_ == planner::SEQ) {
    current_tile_group_offset_ = START_OID;
    if (table_ != nullptr) {
      table_tile_group_count_ = table_->GetTileGroupCount();
      if (column_ids_.empty()) {
        column_ids_.resize(table_->GetSchema()->GetColumnCount());
        std::iota(column_ids_.begin(), column_ids_.end(), 0);
      }
    }

  } else if (type_ == planner::INDEX) {
    result_itr_ = START_OID;
    index_done_ = false;

    column_ids_ = node.GetColumnIds();
    std::vector<oid_t> key_column_ids_ = node.GetKeyColumnIds();
    std::vector<ExpressionType> expr_types_ = node.GetExprTypes();
    values_ = node.GetValues();
    std::vector<expression::AbstractExpression *> runtime_keys_ = node.GetRunTimeKeys();
    predicate_ = node.GetPredicate();

    if (runtime_keys_.size() != 0) {
      assert(runtime_keys_.size() == values_.size());

      if (!key_ready_) {
        values_.clear();

        for (auto expr : runtime_keys_) {
          auto value = expr->Evaluate(nullptr, nullptr, executor_context_);
          LOG_INFO("Evaluated runtime scan key: %s", value.GetInfo().c_str());
          values_.push_back(value);
        }

        key_ready_ = true;
      }
    }

    if (table_ != nullptr) {
      full_column_ids_.resize(table_->GetSchema()->GetColumnCount());
      std::iota(full_column_ids_.begin(), full_column_ids_.end(), 0);
    }
  } else {  // Hybrid type.
    table_tile_group_count_ = table_->GetTileGroupCount();
    int offset = index_->GetIndexedTileGroupOff();
    indexed_tile_offset_ = (offset == -1) ? INVALID_OID : (oid_t)offset;

    if (indexed_tile_offset_ == INVALID_OID) {
      current_tile_group_offset_ = START_OID;
    } else {
      current_tile_group_offset_ = indexed_tile_offset_ + 1;
      std::shared_ptr<storage::TileGroup> tile_group;
      if (current_tile_group_offset_ < table_tile_group_count_) {
        tile_group = table_->GetTileGroup(current_tile_group_offset_);
      } else {
        tile_group = table_->GetTileGroup(table_tile_group_count_ - 1);
      }

      oid_t tuple_id = 0;
      ItemPointer location(tile_group->GetTileGroupId(), tuple_id);
      block_threshold = location.block;
    }

    result_itr_ = START_OID;
    index_done_ = false;

    column_ids_ = node.GetColumnIds();
    std::vector<oid_t> key_column_ids_ = node.GetKeyColumnIds();
    std::vector<ExpressionType> expr_types_ = node.GetExprTypes();
    values_ = node.GetValues();
    std::vector<expression::AbstractExpression>runtime_keys_ = node.GetRunTimeKeys();
    predicate_ = node.GetPredicate();

    if (runtime_keys_.size() != 0) {
      assert(runtime_keys_.size() == values_.size());

      if (!key_ready_) {
        values_.clear();

        for (auto expr : runtime_keys_) {
          auto value = expr->Evaluate(nullptr, nullptr, executor_context_);
          LOG_INFO("Evaluated runtime scan key: %s", value.GetInfo().c_str());
          values_.push_back(value);
        }

        key_ready_ = true;
      }
    }

    if (table_ != nullptr) {
      full_column_ids_.resize(table_->GetSchema()->GetColumnCount());<commit_msg>Fixed mistake<commit_after>//===----------------------------------------------------------------------===//
//
//                         Peloton
//
// hybrid_scan_executor.cpp
//
// Identification: src/executor/hybrid_scan_executor.cpp
//
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include <memory>
#include <utility>
#include <vector>
#include <string>
#include <unordered_map>
#include <chrono>
#include <iostream>
#include <ctime>
#include <cassert>
#include <thread>

#include "common/timer.h"
#include "common/types.h"
#include "executor/logical_tile.h"
#include "executor/logical_tile_factory.h"
#include "executor/executor_context.h"
#include "expression/abstract_expression.h"
#include "expression/container_tuple.h"
#include "planner/hybrid_scan_plan.h"
#include "executor/hybrid_scan_executor.h"
#include "storage/data_table.h"
#include "storage/tile_group_header.h"
#include "storage/tile.h"
#include "concurrency/transaction_manager_factory.h"
#include "common/logger.h"

namespace peloton {
namespace executor {

HybridScanExecutor::HybridScanExecutor(const planner::AbstractPlan *node,
                                       ExecutorContext *executor_context)
    : AbstractScanExecutor(node, executor_context),
      indexed_tile_offset_(START_OID) {}

bool HybridScanExecutor::DInit() {
  auto status = AbstractScanExecutor::DInit();

  if (!status) return false;

  const planner::HybridScanPlan &node = GetPlanNode<planner::HybridScanPlan>();

  table_ = node.GetTable();
  index_ = node.GetDataIndex();
  type_ = node.GetHybridType();

  if (type_ == planner::SEQ) {
    current_tile_group_offset_ = START_OID;
    if (table_ != nullptr) {
      table_tile_group_count_ = table_->GetTileGroupCount();
      if (column_ids_.empty()) {
        column_ids_.resize(table_->GetSchema()->GetColumnCount());
        std::iota(column_ids_.begin(), column_ids_.end(), 0);
      }
    }

  } else if (type_ == planner::INDEX) {
    result_itr_ = START_OID;
    index_done_ = false;

    column_ids_ = node.GetColumnIds();
    std::vector<oid_t> key_column_ids_ = node.GetKeyColumnIds();
    std::vector<ExpressionType> expr_types_ = node.GetExprTypes();
    values_ = node.GetValues();
    std::vector<expression::AbstractExpression *> runtime_keys_ = node.GetRunTimeKeys();
    predicate_ = node.GetPredicate();

    if (runtime_keys_.size() != 0) {
      assert(runtime_keys_.size() == values_.size());

      if (!key_ready_) {
        values_.clear();

        for (auto expr : runtime_keys_) {
          auto value = expr->Evaluate(nullptr, nullptr, executor_context_);
          LOG_INFO("Evaluated runtime scan key: %s", value.GetInfo().c_str());
          values_.push_back(value);
        }

        key_ready_ = true;
      }
    }

    if (table_ != nullptr) {
      full_column_ids_.resize(table_->GetSchema()->GetColumnCount());
      std::iota(full_column_ids_.begin(), full_column_ids_.end(), 0);
    }
  } else {  // Hybrid type.
    table_tile_group_count_ = table_->GetTileGroupCount();
    int offset = index_->GetIndexedTileGroupOff();
    indexed_tile_offset_ = (offset == -1) ? INVALID_OID : (oid_t)offset;

    if (indexed_tile_offset_ == INVALID_OID) {
      current_tile_group_offset_ = START_OID;
    } else {
      current_tile_group_offset_ = indexed_tile_offset_ + 1;
      std::shared_ptr<storage::TileGroup> tile_group;
      if (current_tile_group_offset_ < table_tile_group_count_) {
        tile_group = table_->GetTileGroup(current_tile_group_offset_);
      } else {
        tile_group = table_->GetTileGroup(table_tile_group_count_ - 1);
      }

      oid_t tuple_id = 0;
      ItemPointer location(tile_group->GetTileGroupId(), tuple_id);
      block_threshold = location.block;
    }

    result_itr_ = START_OID;
    index_done_ = false;

    column_ids_ = node.GetColumnIds();
    std::vector<oid_t> key_column_ids_ = node.GetKeyColumnIds();
    std::vector<ExpressionType> expr_types_ = node.GetExprTypes();
    values_ = node.GetValues();
    std::vector<expression::AbstractExpression *> runtime_keys_ = node.GetRunTimeKeys();
    predicate_ = node.GetPredicate();

    if (runtime_keys_.size() != 0) {
      assert(runtime_keys_.size() == values_.size());

      if (!key_ready_) {
        values_.clear();

        for (auto expr : runtime_keys_) {
          auto value = expr->Evaluate(nullptr, nullptr, executor_context_);
          LOG_INFO("Evaluated runtime scan key: %s", value.GetInfo().c_str());
          values_.push_back(value);
        }

        key_ready_ = true;
      }
    }

    if (table_ != nullptr) {
      full_column_ids_.resize(table_->GetSchema()->GetColumnCount());
{'fraction_non_alphanumeric': 0.1602732527588019, 'fraction_numerical': 0.0029427220178665264, 'mean_word_length': 3.1736842105263157, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5379890', 'n_tokens_mistral': 3041, 'n_tokens_neox': 2924, 'n_words': 507}