sql_event.h 2.0 KB
Newer Older
羽飞's avatar
羽飞 已提交
1
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
羽飞's avatar
羽飞 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14
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 Longda on 2021/4/14.
//

羽飞's avatar
羽飞 已提交
15
#pragma once
羽飞's avatar
羽飞 已提交
16 17

#include <string>
羽飞's avatar
羽飞 已提交
18
#include <memory>
W
wangyunlai.wyl 已提交
19
#include "common/seda/stage_event.h"
羽飞's avatar
羽飞 已提交
20
#include "sql/operator/physical_operator.h"
羽飞's avatar
羽飞 已提交
21 22

class SessionEvent;
W
wangyunlai.wyl 已提交
23
class Stmt;
24
class Command;
羽飞's avatar
羽飞 已提交
25

羽飞's avatar
羽飞 已提交
26 27 28
/**
 * @brief 与SessionEvent类似,也是处理SQL请求的事件,只是用在SQL的不同阶段
 */
29 30
class SQLStageEvent : public common::StageEvent
{
羽飞's avatar
羽飞 已提交
31
public:
W
wangyunlai.wyl 已提交
32
  SQLStageEvent(SessionEvent *event, const std::string &sql);
羽飞's avatar
羽飞 已提交
33 34
  virtual ~SQLStageEvent() noexcept;

35 36
  SessionEvent *session_event() const
  {
羽飞's avatar
羽飞 已提交
37 38
    return session_event_;
  }
39

L
Longda Feng 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
  const std::string &sql() const
  {
    return sql_;
  }
  const std::unique_ptr<Command> &command() const
  {
    return command_;
  }
  Stmt *stmt() const
  {
    return stmt_;
  }
  std::unique_ptr<PhysicalOperator> &physical_operator()
  {
    return operator_;
  }
  const std::unique_ptr<PhysicalOperator> &physical_operator() const
  {
    return operator_;
  }
W
wangyunlai.wyl 已提交
60

L
Longda Feng 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
  void set_sql(const char *sql)
  {
    sql_ = sql;
  }
  void set_command(std::unique_ptr<Command> cmd)
  {
    command_ = std::move(cmd);
  }
  void set_stmt(Stmt *stmt)
  {
    stmt_ = stmt;
  }
  void set_operator(std::unique_ptr<PhysicalOperator> oper)
  {
    operator_ = std::move(oper);
  }
W
wangyunlai.wyl 已提交
77

羽飞's avatar
羽飞 已提交
78
private:
W
wangyunlai.wyl 已提交
79
  SessionEvent *session_event_ = nullptr;
羽飞's avatar
羽飞 已提交
80 81 82 83
  std::string sql_;  ///< 处理的SQL语句
  std::unique_ptr<Command> command_;  ///< 语法解析后的SQL命令
  Stmt *stmt_ = nullptr;  ///< Resolver之后生成的数据结构
  std::unique_ptr<PhysicalOperator> operator_; ///< 生成的执行计划,也可能没有
羽飞's avatar
羽飞 已提交
84
};