提交 55b614bb 编写于 作者: 羽飞's avatar 羽飞

refactor

上级 b938f168
......@@ -55,7 +55,6 @@ public:
}
private:
// TODO table and field cannot describe all scenerio, should be expression
const char *alias_ = nullptr;
Expression *expression_ = nullptr;
};
......
......@@ -18,8 +18,7 @@ See the Mulan PSL v2 for more details. */
#include "sql/operator/operator.h"
#include "rc.h"
class JoinPredicate;
// TODO fixme
class JoinOperator : public Operator
{
public:
......@@ -35,6 +34,5 @@ public:
private:
Operator *left_ = nullptr;
Operator *right_ = nullptr;
JoinPredicate *predicate_ = nullptr;
bool round_done_ = true;
};
/* 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 Longda on 2021/4/13.
//
#ifndef __OBSERVER_SQL_PARSE_STAGE_H__
#define __OBSERVER_SQL_PARSE_STAGE_H__
#include "common/seda/stage.h"
class ParseStage : public common::Stage {
public:
~ParseStage();
static Stage *make_stage(const std::string &tag);
protected:
// common function
ParseStage(const char *tag);
bool set_properties();
bool initialize();
void cleanup();
void handle_event(common::StageEvent *event);
void callback_event(common::StageEvent *event, common::CallbackContext *context);
protected:
common::StageEvent *handle_request(common::StageEvent *event);
private:
Stage *resolve_stage_ = nullptr;
};
#endif //__OBSERVER_SQL_PARSE_STAGE_H__
......@@ -21,45 +21,6 @@ UpdateStmt::UpdateStmt(Table *table, Value *values, int value_amount)
RC UpdateStmt::create(Db *db, const Updates &update, Stmt *&stmt)
{
// TODO
#if 0
const char *table_name = update.relation_name;
if (nullptr == db || nullptr == table_name || update.value_num <= 0) {
LOG_WARN("invalid argument. db=%p, table_name=%p, value_num=%d",
db, table_name, inserts.value_num);
return RC::INVALID_ARGUMENT;
}
// check whether the table exists
Table *table = db->find_table(table_name);
if (nullptr == table) {
LOG_WARN("no such table. db=%s, table_name=%s", db->name(), table_name);
return RC::SCHEMA_TABLE_NOT_EXIST;
}
// check the fields number
const Value *values = inserts.values;
const int value_num = inserts.value_num;
const TableMeta &table_meta = table->table_meta();
const int field_num = table_meta.field_num() - table_meta.sys_field_num();
if (field_num != value_num) {
LOG_WARN("schema mismatch. value num=%d, field num in schema=%d", value_num, field_num);
return RC::SCHEMA_FIELD_MISSING;
}
// check fields type
for (int i = table_meta.sys_field_num(); i < table_meta.field_num(); i++) {
const FieldMeta *field_meta = table_meta.field(i);
const AttrType field_type = field_meta->type();
const AttrType value_type = values[i].type;
if (field_type != value_type) { // TODO try to convert the value type to field type
LOG_WARN("field type mismatch. table=%s, field=%s, field type=%d, value_type=%d",
table_name, field_meta->name(), field_type, value_type);
return RC::SCHEMA_FIELD_TYPE_MISMATCH;
}
}
// everything alright
stmt = new InsertStmt(table, values, value_num);
#endif
stmt = nullptr;
return RC::INTERNAL;
}
......@@ -392,8 +392,9 @@ static RC scan_record_reader_adapter(Record *record, void *context)
return RC::SUCCESS;
}
RC Table::scan_record(
Trx *trx, ConditionFilter *filter, int limit, void *context, void (*record_reader)(const char *data, void *context))
RC Table::scan_record(Trx *trx, ConditionFilter *filter,
int limit, void *context,
void (*record_reader)(const char *data, void *context))
{
RecordReaderScanAdapter adapter(record_reader, context);
return scan_record(trx, filter, limit, (void *)&adapter, scan_record_reader_adapter);
......@@ -448,7 +449,8 @@ RC Table::scan_record(Trx *trx, ConditionFilter *filter, int limit, void *contex
return rc;
}
RC Table::scan_record_by_index(Trx *trx, IndexScanner *scanner, ConditionFilter *filter, int limit, void *context,
RC Table::scan_record_by_index(Trx *trx, IndexScanner *scanner, ConditionFilter *filter,
int limit, void *context,
RC (*record_reader)(Record *, void *))
{
RC rc = RC::SUCCESS;
......@@ -515,9 +517,7 @@ RC Table::create_index(Trx *trx, const char *index_name, const char *attribute_n
}
if (table_meta_.index(index_name) != nullptr || table_meta_.find_index_by_field((attribute_name))) {
LOG_INFO("Invalid input arguments, table name is %s, index %s exist or attribute %s exist index",
name(),
index_name,
attribute_name);
name(), index_name, attribute_name);
return RC::SCHEMA_INDEX_EXIST;
}
......@@ -530,7 +530,8 @@ RC Table::create_index(Trx *trx, const char *index_name, const char *attribute_n
IndexMeta new_index_meta;
RC rc = new_index_meta.init(index_name, *field_meta);
if (rc != RC::SUCCESS) {
LOG_INFO("Failed to init IndexMeta in table:%s, index_name:%s, field_name:%s", name(), index_name, attribute_name);
LOG_INFO("Failed to init IndexMeta in table:%s, index_name:%s, field_name:%s",
name(), index_name, attribute_name);
return rc;
}
......@@ -654,10 +655,7 @@ RC Table::delete_record(Trx *trx, Record *record)
rc = delete_entry_of_indexes(record->data(), record->rid(), false); // 重复代码 refer to commit_delete
if (rc != RC::SUCCESS) {
LOG_ERROR("Failed to delete indexes of record (rid=%d.%d). rc=%d:%s",
record->rid().page_num,
record->rid().slot_num,
rc,
strrc(rc));
record->rid().page_num, record->rid().slot_num, rc, strrc(rc));
} else {
rc = record_handler_->delete_record(&record->rid());
}
......@@ -676,10 +674,7 @@ RC Table::commit_delete(Trx *trx, const RID &rid)
rc = delete_entry_of_indexes(record.data(), record.rid(), false);
if (rc != RC::SUCCESS) {
LOG_ERROR("Failed to delete indexes of record(rid=%d.%d). rc=%d:%s",
rid.page_num,
rid.slot_num,
rc,
strrc(rc)); // panic?
rid.page_num, rid.slot_num, rc, strrc(rc)); // panic?
}
rc = record_handler_->delete_record(&rid);
......@@ -854,10 +849,7 @@ RC Table::sync()
rc = index->sync();
if (rc != RC::SUCCESS) {
LOG_ERROR("Failed to flush index's pages. table=%s, index=%s, rc=%d:%s",
name(),
index->index_meta().name(),
rc,
strrc(rc));
name(), index->index_meta().name(), rc, strrc(rc));
return rc;
}
}
......
/* 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/5/3.
//
#ifndef __OBSERVER_STORAGE_ROW_ROW_H_
#define __OBSERVER_STORAGE_ROW_ROW_H_
#include <stddef.h>
#include <vector>
#include "rc.h"
#include "storage/common/index_meta.h"
#include "storage/common/field_meta.h"
#include "storage/common/record_manager.h"
class Row {
public:
Row() = default;
~Row() = default;
RC init(const FieldMeta *fields_, int num);
RC set_projector();
private:
std::vector<FieldMeta *> fields_;
std::vector<int> projector_;
char *data_;
};
#endif // __OBSERVER_STORAGE_ROW_ROW_H_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册