project_physical_operator.cpp 1.8 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by WangYunlai on 2022/07/01.
//

#include "common/log/log.h"
羽飞's avatar
羽飞 已提交
16
#include "sql/operator/project_physical_operator.h"
羽飞's avatar
羽飞 已提交
17
#include "storage/record/record.h"
羽飞's avatar
羽飞 已提交
18 19
#include "storage/common/table.h"

羽飞's avatar
羽飞 已提交
20
RC ProjectPhysicalOperator::open()
羽飞's avatar
羽飞 已提交
21
{
羽飞's avatar
羽飞 已提交
22 23
  if (children_.empty()) {
    return RC::SUCCESS;
羽飞's avatar
羽飞 已提交
24 25
  }

羽飞's avatar
羽飞 已提交
26
  PhysicalOperator *child = children_[0].get();
羽飞's avatar
羽飞 已提交
27 28 29 30 31 32 33 34 35
  RC rc = child->open();
  if (rc != RC::SUCCESS) {
    LOG_WARN("failed to open child operator: %s", strrc(rc));
    return rc;
  }

  return RC::SUCCESS;
}

羽飞's avatar
羽飞 已提交
36
RC ProjectPhysicalOperator::next()
羽飞's avatar
羽飞 已提交
37
{
羽飞's avatar
羽飞 已提交
38 39 40
  if (children_.empty()) {
    return RC::RECORD_EOF;
  }
羽飞's avatar
羽飞 已提交
41 42 43
  return children_[0]->next();
}

羽飞's avatar
羽飞 已提交
44
RC ProjectPhysicalOperator::close()
羽飞's avatar
羽飞 已提交
45
{
羽飞's avatar
羽飞 已提交
46 47 48
  if (!children_.empty()) {
    children_[0]->close();
  }
羽飞's avatar
羽飞 已提交
49 50
  return RC::SUCCESS;
}
羽飞's avatar
羽飞 已提交
51
Tuple *ProjectPhysicalOperator::current_tuple()
羽飞's avatar
羽飞 已提交
52 53 54 55 56
{
  tuple_.set_tuple(children_[0]->current_tuple());
  return &tuple_;
}

羽飞's avatar
羽飞 已提交
57
void ProjectPhysicalOperator::add_projection(const Table *table, const FieldMeta *field_meta)
羽飞's avatar
羽飞 已提交
58
{
羽飞's avatar
羽飞 已提交
59 60
  // 对单表来说,展示的(alias) 字段总是字段名称,
  // 对多表查询来说,展示的alias 需要带表名字
羽飞's avatar
羽飞 已提交
61
  TupleCellSpec *spec = new TupleCellSpec(table->name(), field_meta->name(), field_meta->name());
羽飞's avatar
羽飞 已提交
62 63
  tuple_.add_cell_spec(spec);
}