Skip to content

Commit

Permalink
clang-format (#319)
Browse files Browse the repository at this point in the history
### What problem were solved in this pull request?

Issue Number: ref #260 

clang-format
  • Loading branch information
hnwyllmm authored Nov 15, 2023
1 parent edc55d1 commit a8f5fd9
Show file tree
Hide file tree
Showing 22 changed files with 302 additions and 371 deletions.
19 changes: 4 additions & 15 deletions src/observer/event/session_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,10 @@ See the Mulan PSL v2 for more details. */
#include "session_event.h"
#include "net/communicator.h"

SessionEvent::SessionEvent(Communicator *comm)
: communicator_(comm),
sql_result_(communicator_->session())
{}
SessionEvent::SessionEvent(Communicator *comm) : communicator_(comm), sql_result_(communicator_->session()) {}

SessionEvent::~SessionEvent()
{
}
SessionEvent::~SessionEvent() {}

Communicator *SessionEvent::get_communicator() const
{
return communicator_;
}
Communicator *SessionEvent::get_communicator() const { return communicator_; }

Session *SessionEvent::session() const
{
return communicator_->session();
}
Session *SessionEvent::session() const { return communicator_->session(); }
15 changes: 6 additions & 9 deletions src/observer/event/session_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,33 @@ See the Mulan PSL v2 for more details. */

#pragma once

#include <string.h>
#include <string>

#include "common/seda/stage_event.h"
#include "sql/executor/sql_result.h"
#include "event/sql_debug.h"
#include "sql/executor/sql_result.h"

class Session;
class Communicator;

/**
* @brief 表示一个SQL请求
*
*
*/
class SessionEvent : public common::StageEvent
class SessionEvent : public common::StageEvent
{
public:
SessionEvent(Communicator *client);
virtual ~SessionEvent();

Communicator *get_communicator() const;
Session *session() const;
Session *session() const;

void set_query(const std::string &query) { query_ = query; }

const std::string &query() const { return query_; }

SqlResult *sql_result() { return &sql_result_; }

SqlDebug &sql_debug() { return sql_debug_; }
SqlResult *sql_result() { return &sql_result_; }
SqlDebug &sql_debug() { return sql_debug_; }

private:
Communicator *communicator_ = nullptr; ///< 与客户端通讯的对象
Expand Down
23 changes: 7 additions & 16 deletions src/observer/event/sql_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,34 @@ See the Mulan PSL v2 for more details. */

#include <stdarg.h>

#include "event/session_event.h"
#include "event/sql_debug.h"
#include "session/session.h"
#include "event/session_event.h"

using namespace std;

void SqlDebug::add_debug_info(const std::string &debug_info)
{
debug_infos_.push_back(debug_info);
}
void SqlDebug::add_debug_info(const string &debug_info) { debug_infos_.push_back(debug_info); }

void SqlDebug::clear_debug_info()
{
debug_infos_.clear();
}
void SqlDebug::clear_debug_info() { debug_infos_.clear(); }

const list<string> &SqlDebug::get_debug_infos() const
{
return debug_infos_;
}
const list<string> &SqlDebug::get_debug_infos() const { return debug_infos_; }

void sql_debug(const char *fmt, ...)
{
Session *session = Session::current_session();
Session *session = Session::current_session();
if (nullptr == session) {
return;
}

SessionEvent *request = session->current_request();
if (nullptr == request) {
return ;
return;
}

SqlDebug &sql_debug = request->sql_debug();

const int buffer_size = 4096;
char *str = new char[buffer_size];
char *str = new char[buffer_size];

va_list ap;
va_start(ap, fmt);
Expand Down
4 changes: 2 additions & 2 deletions src/observer/event/sql_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ See the Mulan PSL v2 for more details. */

/**
* @brief SQL调试信息
* @details
* @details
* 希望在运行SQL时,可以直接输出一些调试信息到客户端。
* 当前把调试信息都放在了session上,可以随着SQL语句输出。
* 但是现在还不支持与输出调试信息与行数据同步输出。
*/
class SqlDebug
{
public:
SqlDebug() = default;
SqlDebug() = default;
virtual ~SqlDebug() = default;

void add_debug_info(const std::string &debug_info);
Expand Down
6 changes: 1 addition & 5 deletions src/observer/event/sql_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ See the Mulan PSL v2 for more details. */

#include "event/sql_event.h"

#include <cstddef>

#include "event/session_event.h"
#include "sql/parser/parse_defs.h"
#include "sql/stmt/stmt.h"

SQLStageEvent::SQLStageEvent(SessionEvent *event, const std::string &sql) : session_event_(event), sql_(sql)
{}
SQLStageEvent::SQLStageEvent(SessionEvent *event, const std::string &sql) : session_event_(event), sql_(sql) {}

SQLStageEvent::~SQLStageEvent() noexcept
{
Expand Down
64 changes: 17 additions & 47 deletions src/observer/event/sql_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ See the Mulan PSL v2 for more details. */

#pragma once

#include <string>
#include <memory>
#include "common/seda/stage_event.h"
#include "sql/operator/physical_operator.h"
#include <memory>
#include <string>

class SessionEvent;
class Stmt;
Expand All @@ -32,53 +32,23 @@ class SQLStageEvent : public common::StageEvent
SQLStageEvent(SessionEvent *event, const std::string &sql);
virtual ~SQLStageEvent() noexcept;

SessionEvent *session_event() const
{
return session_event_;
}
SessionEvent *session_event() const { return session_event_; }

const std::string &sql() const
{
return sql_;
}
const std::unique_ptr<ParsedSqlNode> &sql_node() const
{
return sql_node_;
}
Stmt *stmt() const
{
return stmt_;
}
std::unique_ptr<PhysicalOperator> &physical_operator()
{
return operator_;
}
const std::unique_ptr<PhysicalOperator> &physical_operator() const
{
return operator_;
}
const std::string &sql() const { return sql_; }
const std::unique_ptr<ParsedSqlNode> &sql_node() const { return sql_node_; }
Stmt *stmt() const { return stmt_; }
std::unique_ptr<PhysicalOperator> &physical_operator() { return operator_; }
const std::unique_ptr<PhysicalOperator> &physical_operator() const { return operator_; }

void set_sql(const char *sql)
{
sql_ = sql;
}
void set_sql_node(std::unique_ptr<ParsedSqlNode> sql_node)
{
sql_node_ = std::move(sql_node);
}
void set_stmt(Stmt *stmt)
{
stmt_ = stmt;
}
void set_operator(std::unique_ptr<PhysicalOperator> oper)
{
operator_ = std::move(oper);
}
void set_sql(const char *sql) { sql_ = sql; }
void set_sql_node(std::unique_ptr<ParsedSqlNode> sql_node) { sql_node_ = std::move(sql_node); }
void set_stmt(Stmt *stmt) { stmt_ = stmt; }
void set_operator(std::unique_ptr<PhysicalOperator> oper) { operator_ = std::move(oper); }

private:
SessionEvent *session_event_ = nullptr;
std::string sql_; ///< 处理的SQL语句
std::unique_ptr<ParsedSqlNode> sql_node_; ///< 语法解析后的SQL命令
Stmt *stmt_ = nullptr; ///< Resolver之后生成的数据结构
std::unique_ptr<PhysicalOperator> operator_; ///< 生成的执行计划,也可能没有
SessionEvent *session_event_ = nullptr;
std::string sql_; ///< 处理的SQL语句
std::unique_ptr<ParsedSqlNode> sql_node_; ///< 语法解析后的SQL命令
Stmt *stmt_ = nullptr; ///< Resolver之后生成的数据结构
std::unique_ptr<PhysicalOperator> operator_; ///< 生成的执行计划,也可能没有
};
11 changes: 4 additions & 7 deletions src/observer/event/storage_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ See the Mulan PSL v2 for more details. */

class SQLStageEvent;

class StorageEvent : public common::StageEvent {
class StorageEvent : public common::StageEvent
{
public:
StorageEvent(SQLStageEvent *sql_event) : sql_event_(sql_event)
{}
StorageEvent(SQLStageEvent *sql_event) : sql_event_(sql_event) {}

virtual ~StorageEvent();

SQLStageEvent *sql_event() const
{
return sql_event_;
}
SQLStageEvent *sql_event() const { return sql_event_; }

private:
SQLStageEvent *sql_event_;
Expand Down
23 changes: 9 additions & 14 deletions src/observer/net/buffered_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,19 @@ See the Mulan PSL v2 for more details. */
// Created by Wangyunlai on 2023/06/16.
//

#include <algorithm>
#include <sys/errno.h>
#include <unistd.h>
#include <algorithm>

#include "net/buffered_writer.h"

using namespace std;

BufferedWriter::BufferedWriter(int fd)
: fd_(fd), buffer_()
{}
BufferedWriter::BufferedWriter(int fd) : fd_(fd), buffer_() {}

BufferedWriter::BufferedWriter(int fd, int32_t size)
: fd_(fd), buffer_(size)
{}
BufferedWriter::BufferedWriter(int fd, int32_t size) : fd_(fd), buffer_(size) {}

BufferedWriter::~BufferedWriter()
{
close();
}
BufferedWriter::~BufferedWriter() { close(); }

RC BufferedWriter::close()
{
Expand Down Expand Up @@ -74,6 +67,7 @@ RC BufferedWriter::writen(const char *data, int32_t size)
int32_t write_size = 0;
while (write_size < size) {
int32_t tmp_write_size = 0;

RC rc = write(data + write_size, size - write_size, tmp_write_size);
if (OB_FAIL(rc)) {
return rc;
Expand Down Expand Up @@ -105,11 +99,12 @@ RC BufferedWriter::flush_internal(int32_t size)
}

RC rc = RC::SUCCESS;

int32_t write_size = 0;
while (OB_SUCC(rc) && buffer_.size() > 0 && size > write_size) {
const char *buf = nullptr;
int32_t read_size = 0;
rc = buffer_.buffer(buf, read_size);
const char *buf = nullptr;
int32_t read_size = 0;
rc = buffer_.buffer(buf, read_size);
if (OB_FAIL(rc)) {
return rc;
}
Expand Down
4 changes: 2 additions & 2 deletions src/observer/net/buffered_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BufferedWriter
* @brief 写数据到文件/socket
* @details 缓存满会自动刷新缓存
* @param data 要写入的数据
* @param size 要写入的数据大小
* @param size 要写入的数据大小
* @param write_size 实际写入的数据大小
*/
RC write(const char *data, int32_t size, int32_t &write_size);
Expand Down Expand Up @@ -67,6 +67,6 @@ class BufferedWriter
RC flush_internal(int32_t size);

private:
int fd_ = -1;
int fd_ = -1;
RingBuffer buffer_;
};
Loading

0 comments on commit a8f5fd9

Please sign in to comment.