Skip to content

Commit

Permalink
实现了假的text
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick16262 committed Jun 13, 2024
1 parent ea0f192 commit dc1c9fd
Show file tree
Hide file tree
Showing 15 changed files with 985 additions and 861 deletions.
1 change: 1 addition & 0 deletions src/observer/common/rc.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ See the Mulan PSL v2 for more details. */
DEFINE_RC(SUBQUERY_MORE_THAN_ONE_ROW) \
DEFINE_RC(SUBQUERY_MORE_THAN_ONE_COL) \
DEFINE_RC(ALIAS_NOT_EXIST) \
DEFINE_RC(INSERT_VALUE_TOOLONG) \
DEFINE_RC(IOERR_READ) \
DEFINE_RC(IOERR_WRITE) \
DEFINE_RC(IOERR_ACCESS) \
Expand Down
15 changes: 15 additions & 0 deletions src/observer/mock/in_memory_text_storage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


#include "in_memory_text_storage.h"

int InMemoryTextStorage::put(const std::string &text)
{
storage_[next_key] = text;
return next_key++;
}

const std::string &InMemoryTextStorage::get(int key) { return storage_[key]; }

void InMemoryTextStorage::remove(int key) { storage_.erase(key); }

InMemoryTextStorage g_mem_text;
31 changes: 31 additions & 0 deletions src/observer/mock/in_memory_text_storage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <string>
#include <unordered_map>

/**
* @brief 用于存放超长数据
*
*/

class InMemoryTextStorage
{
public:
/**
* @brief 用于存储超长数据
*
* @param text 要存储的text
* @return int 返回的键
*/
int put(const std::string& text);

const std::string &get(int key);

void remove(int key);

private:
int next_key = 0;
std::unordered_map<int, std::string> storage_;
};

extern InMemoryTextStorage g_mem_text;
2 changes: 1 addition & 1 deletion src/observer/sql/expr/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ inline std::string get_month_numeric(int month) { return std::to_string(month -
inline std::string get_day_of_month_with_english_suffix(int day)
{
static const std::string suffixes[] = {"th", "st", "nd", "th", "th", "th", "th", "th", "th", "th"};
return std::to_string(day) + suffixes[day % 10];
return std::to_string(day) + (day == 3 ? "rd" : suffixes[day % 10]);
}

//%d Day of the month, numeric (00..31)
Expand Down
11 changes: 10 additions & 1 deletion src/observer/sql/expr/tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ See the Mulan PSL v2 for more details. */
#include <cassert>
#include <cfloat>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <json/value.h>
#include <memory>
Expand All @@ -26,6 +27,7 @@ See the Mulan PSL v2 for more details. */

#include "common/lang/bitmap.h"
#include "common/log/log.h"
#include "mock/in_memory_text_storage.h"
#include "sql/expr/expr_type.h"
#include "sql/expr/expression.h"
#include "sql/expr/tuple_cell.h"
Expand Down Expand Up @@ -170,6 +172,13 @@ class RowTuple : public Tuple

FieldExpr *field_expr = fields_[index];
const FieldMeta *field_meta = field_expr->field().meta();
if (field_meta->type() == TEXTS) {
assert(strlen(this->record_->data() + field_meta->offset()) <= 3);
int key = atoi(this->record_->data() + field_meta->offset());
cell.set_string(g_mem_text.get(key).c_str());
return RC::SUCCESS;
}

cell.set_type(field_meta->type());
cell.set_data(this->record_->data() + field_meta->offset(), field_meta->len());
return RC::SUCCESS;
Expand Down Expand Up @@ -422,7 +431,7 @@ class AggregateTuple : public Tuple
float sum;
sscanf(value.get_string().c_str(), "count: %d, sum: %f", &count, &sum);
cell.set_float(sum / count);
}else {
} else {
cell = value;
}

Expand Down
1 change: 1 addition & 0 deletions src/observer/sql/parser/defs/sql_command_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct CreateIndexSqlNode
std::string index_name; ///< Index name
std::string relation_name; ///< Relation name
std::vector<std::string> attribute_names; ///< Attribute name
bool unique = false; ///< 是否唯一索引
};

/**
Expand Down
Loading

0 comments on commit dc1c9fd

Please sign in to comment.