未验证 提交 5c3be1d5 编写于 作者: 羽飞's avatar 羽飞 提交者: GitHub

parser中的一些变量重命名 (#225)

### What problem were solved in this pull request?
Problem:
parse_defs中的一些变量命名不是很清晰

### What is changed and how it works?
重命名,增加SqlNode后缀,希望看起来更清晰,知道这些变量的意图
另外,增加了一个visual studio code的生成parser的任务
上级 1e733d5e
......@@ -22,6 +22,11 @@
"label": "build_release",
"type": "shell",
"command": "bash build.sh release"
},
{
"label": "gen_parser",
"type": "shell",
"command": "cd ${workspaceFolder}/src/observer/sql/parser && bash gen_parser.sh"
}
]
}
......@@ -21,7 +21,7 @@ See the Mulan PSL v2 for more details. */
class SessionEvent;
class Stmt;
class Command;
class ParsedSqlNode;
/**
* @brief 与SessionEvent类似,也是处理SQL请求的事件,只是用在SQL的不同阶段
......@@ -41,9 +41,9 @@ public:
{
return sql_;
}
const std::unique_ptr<Command> &command() const
const std::unique_ptr<ParsedSqlNode> &sql_node() const
{
return command_;
return sql_node_;
}
Stmt *stmt() const
{
......@@ -62,9 +62,9 @@ public:
{
sql_ = sql;
}
void set_command(std::unique_ptr<Command> cmd)
void set_sql_node(std::unique_ptr<ParsedSqlNode> sql_node)
{
command_ = std::move(cmd);
sql_node_ = std::move(sql_node);
}
void set_stmt(Stmt *stmt)
{
......@@ -78,7 +78,7 @@ public:
private:
SessionEvent *session_event_ = nullptr;
std::string sql_; ///< 处理的SQL语句
std::unique_ptr<Command> command_; ///< 语法解析后的SQL命令
std::unique_ptr<ParsedSqlNode> sql_node_; ///< 语法解析后的SQL命令
Stmt *stmt_ = nullptr; ///< Resolver之后生成的数据结构
std::unique_ptr<PhysicalOperator> operator_; ///< 生成的执行计划,也可能没有
};
#line 2 "lex_sql.cpp"
#line 2 "lex_sql.l"
// 这里的代码会被复制到lex_sql.cpp的最开始位置
// 定义yy_size_t的原因是因为flex生成的代码,会使用yy_size_t与其他类型的数字
// 做比较,导致编译报警
#define YY_TYPEDEF_YY_SIZE_T
typedef int yy_size_t;
#line 4 "lex_sql.cpp"
#line 12 "lex_sql.cpp"
#define YY_INT_ALIGNED short int
......@@ -588,7 +596,8 @@ static yyconst flex_int16_t yy_chk[490] =
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
#line 1 "lex_sql.l"
#line 2 "lex_sql.l"
#line 10 "lex_sql.l"
#include<string.h>
#include<stdio.h>
......@@ -601,6 +610,7 @@ static yyconst flex_int16_t yy_chk[490] =
struct ParserContext;
#include "sql/parser/parse_defs.h"
#include "common/log/log.h"
#include "yacc_sql.hpp"
#ifndef register
......@@ -610,13 +620,7 @@ struct ParserContext;
extern int atoi();
extern double atof();
#if YYDEBUG > 0
#define debug_printf printf
#else
#define debug_printf(...)
#endif // YYDEBUG
#define RETURN_TOKEN(token) debug_printf("%s\n",#token);return token
#define RETURN_TOKEN(token) LOG_DEBUG("%s", #token);return token
/* Prevent the need for linking with -lfl */
#define YY_NO_INPUT 1
/* 不区分大小写 */
......@@ -625,7 +629,7 @@ extern double atof();
/* 1. 匹配的规则长的优先 */
/* 2. 写在最前面的优先 */
/* yylval 就可以认为是 yacc 中 %union 定义的结构体(union 结构) */
#line 629 "lex_sql.cpp"
#line 633 "lex_sql.cpp"
#define INITIAL 0
#define STR 1
......@@ -865,10 +869,10 @@ YY_DECL
register int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
#line 55 "lex_sql.l"
#line 58 "lex_sql.l"
#line 872 "lex_sql.cpp"
#line 876 "lex_sql.cpp"
yylval = yylval_param;
......@@ -957,273 +961,273 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
#line 57 "lex_sql.l"
#line 60 "lex_sql.l"
// ignore whitespace
YY_BREAK
case 2:
/* rule 2 can match eol */
YY_RULE_SETUP
#line 58 "lex_sql.l"
#line 61 "lex_sql.l"
;
YY_BREAK
case 3:
YY_RULE_SETUP
#line 60 "lex_sql.l"
#line 63 "lex_sql.l"
yylval->number=atoi(yytext); RETURN_TOKEN(NUMBER);
YY_BREAK
case 4:
YY_RULE_SETUP
#line 61 "lex_sql.l"
#line 64 "lex_sql.l"
yylval->floats=(float)(atof(yytext)); RETURN_TOKEN(FLOAT);
YY_BREAK
case 5:
YY_RULE_SETUP
#line 63 "lex_sql.l"
#line 66 "lex_sql.l"
RETURN_TOKEN(SEMICOLON);
YY_BREAK
case 6:
YY_RULE_SETUP
#line 64 "lex_sql.l"
#line 67 "lex_sql.l"
RETURN_TOKEN(DOT);
YY_BREAK
case 7:
YY_RULE_SETUP
#line 65 "lex_sql.l"
#line 68 "lex_sql.l"
RETURN_TOKEN(STAR);
YY_BREAK
case 8:
YY_RULE_SETUP
#line 66 "lex_sql.l"
#line 69 "lex_sql.l"
RETURN_TOKEN(EXIT);
YY_BREAK
case 9:
YY_RULE_SETUP
#line 67 "lex_sql.l"
#line 70 "lex_sql.l"
RETURN_TOKEN(HELP);
YY_BREAK
case 10:
YY_RULE_SETUP
#line 68 "lex_sql.l"
#line 71 "lex_sql.l"
RETURN_TOKEN(DESC);
YY_BREAK
case 11:
YY_RULE_SETUP
#line 69 "lex_sql.l"
#line 72 "lex_sql.l"
RETURN_TOKEN(CREATE);
YY_BREAK
case 12:
YY_RULE_SETUP
#line 70 "lex_sql.l"
#line 73 "lex_sql.l"
RETURN_TOKEN(DROP);
YY_BREAK
case 13:
YY_RULE_SETUP
#line 71 "lex_sql.l"
#line 74 "lex_sql.l"
RETURN_TOKEN(TABLE);
YY_BREAK
case 14:
YY_RULE_SETUP
#line 72 "lex_sql.l"
#line 75 "lex_sql.l"
RETURN_TOKEN(TABLES);
YY_BREAK
case 15:
YY_RULE_SETUP
#line 73 "lex_sql.l"
#line 76 "lex_sql.l"
RETURN_TOKEN(INDEX);
YY_BREAK
case 16:
YY_RULE_SETUP
#line 74 "lex_sql.l"
#line 77 "lex_sql.l"
RETURN_TOKEN(ON);
YY_BREAK
case 17:
YY_RULE_SETUP
#line 75 "lex_sql.l"
#line 78 "lex_sql.l"
RETURN_TOKEN(SHOW);
YY_BREAK
case 18:
YY_RULE_SETUP
#line 76 "lex_sql.l"
#line 79 "lex_sql.l"
RETURN_TOKEN(SYNC);
YY_BREAK
case 19:
YY_RULE_SETUP
#line 77 "lex_sql.l"
#line 80 "lex_sql.l"
RETURN_TOKEN(SELECT);
YY_BREAK
case 20:
YY_RULE_SETUP
#line 78 "lex_sql.l"
#line 81 "lex_sql.l"
RETURN_TOKEN(FROM);
YY_BREAK
case 21:
YY_RULE_SETUP
#line 79 "lex_sql.l"
#line 82 "lex_sql.l"
RETURN_TOKEN(WHERE);
YY_BREAK
case 22:
YY_RULE_SETUP
#line 80 "lex_sql.l"
#line 83 "lex_sql.l"
RETURN_TOKEN(AND);
YY_BREAK
case 23:
YY_RULE_SETUP
#line 81 "lex_sql.l"
#line 84 "lex_sql.l"
RETURN_TOKEN(INSERT);
YY_BREAK
case 24:
YY_RULE_SETUP
#line 82 "lex_sql.l"
#line 85 "lex_sql.l"
RETURN_TOKEN(INTO);
YY_BREAK
case 25:
YY_RULE_SETUP
#line 83 "lex_sql.l"
#line 86 "lex_sql.l"
RETURN_TOKEN(VALUES);
YY_BREAK
case 26:
YY_RULE_SETUP
#line 84 "lex_sql.l"
#line 87 "lex_sql.l"
RETURN_TOKEN(DELETE);
YY_BREAK
case 27:
YY_RULE_SETUP
#line 85 "lex_sql.l"
#line 88 "lex_sql.l"
RETURN_TOKEN(UPDATE);
YY_BREAK
case 28:
YY_RULE_SETUP
#line 86 "lex_sql.l"
#line 89 "lex_sql.l"
RETURN_TOKEN(SET);
YY_BREAK
case 29:
YY_RULE_SETUP
#line 87 "lex_sql.l"
#line 90 "lex_sql.l"
RETURN_TOKEN(TRX_BEGIN);
YY_BREAK
case 30:
YY_RULE_SETUP
#line 88 "lex_sql.l"
#line 91 "lex_sql.l"
RETURN_TOKEN(TRX_COMMIT);
YY_BREAK
case 31:
YY_RULE_SETUP
#line 89 "lex_sql.l"
#line 92 "lex_sql.l"
RETURN_TOKEN(TRX_ROLLBACK);
YY_BREAK
case 32:
YY_RULE_SETUP
#line 90 "lex_sql.l"
#line 93 "lex_sql.l"
RETURN_TOKEN(INT_T);
YY_BREAK
case 33:
YY_RULE_SETUP
#line 91 "lex_sql.l"
#line 94 "lex_sql.l"
RETURN_TOKEN(STRING_T);
YY_BREAK
case 34:
YY_RULE_SETUP
#line 92 "lex_sql.l"
#line 95 "lex_sql.l"
RETURN_TOKEN(FLOAT_T);
YY_BREAK
case 35:
YY_RULE_SETUP
#line 93 "lex_sql.l"
#line 96 "lex_sql.l"
RETURN_TOKEN(LOAD);
YY_BREAK
case 36:
YY_RULE_SETUP
#line 94 "lex_sql.l"
#line 97 "lex_sql.l"
RETURN_TOKEN(DATA);
YY_BREAK
case 37:
YY_RULE_SETUP
#line 95 "lex_sql.l"
#line 98 "lex_sql.l"
RETURN_TOKEN(INFILE);
YY_BREAK
case 38:
YY_RULE_SETUP
#line 96 "lex_sql.l"
#line 99 "lex_sql.l"
RETURN_TOKEN(EXPLAIN);
YY_BREAK
case 39:
YY_RULE_SETUP
#line 97 "lex_sql.l"
#line 100 "lex_sql.l"
yylval->string=strdup(yytext); RETURN_TOKEN(ID);
YY_BREAK
case 40:
YY_RULE_SETUP
#line 98 "lex_sql.l"
#line 101 "lex_sql.l"
RETURN_TOKEN(LBRACE);
YY_BREAK
case 41:
YY_RULE_SETUP
#line 99 "lex_sql.l"
#line 102 "lex_sql.l"
RETURN_TOKEN(RBRACE);
YY_BREAK
case 42:
YY_RULE_SETUP
#line 101 "lex_sql.l"
#line 104 "lex_sql.l"
RETURN_TOKEN(COMMA);
YY_BREAK
case 43:
YY_RULE_SETUP
#line 102 "lex_sql.l"
#line 105 "lex_sql.l"
RETURN_TOKEN(EQ);
YY_BREAK
case 44:
YY_RULE_SETUP
#line 103 "lex_sql.l"
#line 106 "lex_sql.l"
RETURN_TOKEN(LE);
YY_BREAK
case 45:
YY_RULE_SETUP
#line 104 "lex_sql.l"
#line 107 "lex_sql.l"
RETURN_TOKEN(NE);
YY_BREAK
case 46:
YY_RULE_SETUP
#line 105 "lex_sql.l"
#line 108 "lex_sql.l"
RETURN_TOKEN(NE);
YY_BREAK
case 47:
YY_RULE_SETUP
#line 106 "lex_sql.l"
#line 109 "lex_sql.l"
RETURN_TOKEN(LT);
YY_BREAK
case 48:
YY_RULE_SETUP
#line 107 "lex_sql.l"
#line 110 "lex_sql.l"
RETURN_TOKEN(GE);
YY_BREAK
case 49:
YY_RULE_SETUP
#line 108 "lex_sql.l"
#line 111 "lex_sql.l"
RETURN_TOKEN(GT);
YY_BREAK
case 50:
/* rule 50 can match eol */
YY_RULE_SETUP
#line 109 "lex_sql.l"
#line 112 "lex_sql.l"
yylval->string=strdup(yytext); RETURN_TOKEN(SSS);
YY_BREAK
case 51:
/* rule 51 can match eol */
YY_RULE_SETUP
#line 110 "lex_sql.l"
#line 113 "lex_sql.l"
yylval->string = strdup(yytext); RETURN_TOKEN(SSS);
YY_BREAK
case 52:
YY_RULE_SETUP
#line 112 "lex_sql.l"
#line 115 "lex_sql.l"
printf("Unknown character [%c]\n",yytext[0]); return yytext[0];
YY_BREAK
case 53:
YY_RULE_SETUP
#line 113 "lex_sql.l"
#line 116 "lex_sql.l"
ECHO;
YY_BREAK
#line 1227 "lex_sql.cpp"
#line 1231 "lex_sql.cpp"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(STR):
yyterminate();
......@@ -2365,7 +2369,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables"
#line 113 "lex_sql.l"
#line 116 "lex_sql.l"
......
......@@ -3,8 +3,16 @@
#define yyIN_HEADER 1
#line 6 "lex_sql.h"
#line 2 "lex_sql.l"
// 这里的代码会被复制到lex_sql.cpp的最开始位置
// 定义yy_size_t的原因是因为flex生成的代码,会使用yy_size_t与其他类型的数字
// 做比较,导致编译报警
#define YY_TYPEDEF_YY_SIZE_T
typedef int yy_size_t;
#line 8 "lex_sql.h"
#line 16 "lex_sql.h"
#define YY_INT_ALIGNED short int
......@@ -338,9 +346,9 @@ extern int yylex \
#undef YY_DECL
#endif
#line 113 "lex_sql.l"
#line 116 "lex_sql.l"
#line 345 "lex_sql.h"
#line 353 "lex_sql.h"
#undef yyIN_HEADER
#endif /* yyHEADER_H */
%top{
// 这里的代码会被复制到lex_sql.cpp的最开始位置
// 定义yy_size_t的原因是因为flex生成的代码,会使用yy_size_t与其他类型的数字
// 做比较,导致编译报警
#define YY_TYPEDEF_YY_SIZE_T
typedef int yy_size_t;
}
%{
#include<string.h>
#include<stdio.h>
......@@ -11,6 +19,7 @@
struct ParserContext;
#include "sql/parser/parse_defs.h"
#include "common/log/log.h"
#include "yacc_sql.hpp"
#ifndef register
......@@ -20,13 +29,7 @@ struct ParserContext;
extern int atoi();
extern double atof();
#if YYDEBUG > 0
#define debug_printf printf
#else
#define debug_printf(...)
#endif // YYDEBUG
#define RETURN_TOKEN(token) debug_printf("%s\n",#token);return token
#define RETURN_TOKEN(token) LOG_DEBUG("%s", #token);return token
%}
/* Prevent the need for linking with -lfl */
......
......@@ -16,17 +16,17 @@ See the Mulan PSL v2 for more details. */
#include "sql/parser/parse.h"
#include "common/log/log.h"
RC parse(char *st, Command *sqln);
RC parse(char *st, ParsedSqlNode *sqln);
Command::Command() : flag(SCF_ERROR)
ParsedSqlNode::ParsedSqlNode() : flag(SCF_ERROR)
{}
Command::Command(SqlCommandFlag _flag) : flag(_flag)
ParsedSqlNode::ParsedSqlNode(SqlCommandFlag _flag) : flag(_flag)
{}
void ParsedSqlResult::add_command(std::unique_ptr<Command> command)
void ParsedSqlResult::add_sql_node(std::unique_ptr<ParsedSqlNode> sql_node)
{
sql_commands_.emplace_back(std::move(command));
sql_nodes_.emplace_back(std::move(sql_node));
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -27,7 +27,7 @@ See the Mulan PSL v2 for more details. */
* Rel -> Relation
* Attr -> Attribute
*/
struct RelAttr
struct RelAttrSqlNode
{
std::string relation_name; ///< relation name (may be NULL) 表名
std::string attribute_name; ///< attribute name 属性名
......@@ -38,12 +38,12 @@ struct RelAttr
*/
enum CompOp
{
EQUAL_TO, //"=" 0
LESS_EQUAL, //"<=" 1
NOT_EQUAL, //"<>" 2
LESS_THAN, //"<" 3
GREAT_EQUAL, //">=" 4
GREAT_THAN, //">" 5
EQUAL_TO, ///< "="
LESS_EQUAL, ///< "<="
NOT_EQUAL, ///< "<>"
LESS_THAN, ///< "<"
GREAT_EQUAL, ///< ">="
GREAT_THAN, ///< ">"
NO_OP
};
......@@ -54,17 +54,17 @@ enum CompOp
* 左边和右边理论上都可以是任意的数据,比如是字段(属性,列),也可以是数值常量。
* 这个结构中记录的仅仅支持字段和值。
*/
struct Condition
struct ConditionSqlNode
{
int left_is_attr; /// TRUE if left-hand side is an attribute
/// 1时,操作符左边是属性名,0时,是属性值
Value left_value; /// left-hand side value if left_is_attr = FALSE
RelAttr left_attr; /// left-hand side attribute
CompOp comp; /// comparison operator
int right_is_attr; /// TRUE if right-hand side is an attribute
/// 1时,操作符右边是属性名,0时,是属性值
RelAttr right_attr; /// right-hand side attribute if right_is_attr = TRUE 右边的属性
Value right_value; /// right-hand side value if right_is_attr = FALSE
int left_is_attr; ///< TRUE if left-hand side is an attribute
///< 1时,操作符左边是属性名,0时,是属性值
Value left_value; ///< left-hand side value if left_is_attr = FALSE
RelAttrSqlNode left_attr; ///< left-hand side attribute
CompOp comp; ///< comparison operator
int right_is_attr; ///< TRUE if right-hand side is an attribute
///< 1时,操作符右边是属性名,0时,是属性值
RelAttrSqlNode right_attr; ///< right-hand side attribute if right_is_attr = TRUE 右边的属性
Value right_value; ///< right-hand side value if right_is_attr = FALSE
};
/**
......@@ -76,18 +76,18 @@ struct Condition
* where 条件 conditions,这里表示使用AND串联起来多个条件。正常的SQL语句会有OR,NOT等,
* 甚至可以包含复杂的表达式。
*/
struct Selects
struct SelectSqlNode
{
std::vector<RelAttr> attributes; ///< attributes in select clause
std::vector<RelAttrSqlNode> attributes; ///< attributes in select clause
std::vector<std::string> relations; ///< 查询的表
std::vector<Condition> conditions; ///< 查询条件,使用AND串联起来多个条件
std::vector<ConditionSqlNode> conditions; ///< 查询条件,使用AND串联起来多个条件
};
/**
* @brief 描述一个insert语句
* @details 于Selects类似,也做了很多简化
*/
struct Inserts
struct InsertSqlNode
{
std::string relation_name; ///< Relation to insert into
std::vector<Value> values; ///< 要插入的值
......@@ -96,22 +96,22 @@ struct Inserts
/**
* @brief 描述一个delete语句
*/
struct Deletes
struct DeleteSqlNode
{
std::string relation_name; // Relation to delete from
std::vector<Condition> conditions;
std::string relation_name; ///< Relation to delete from
std::vector<ConditionSqlNode> conditions;
};
/**
* @brief 描述一个update语句
*
*/
struct Updates
struct UpdateSqlNode
{
std::string relation_name; ///< Relation to update
std::string attribute_name; ///< 更新的字段,仅支持一个字段
Value value; ///< 更新的值,仅支持一个字段
std::vector<Condition> conditions;
std::vector<ConditionSqlNode> conditions;
};
/**
......@@ -120,7 +120,7 @@ struct Updates
* Rel -> Relation
* Attr -> Attribute
*/
struct AttrInfo
struct AttrInfoSqlNode
{
AttrType type; ///< Type of attribute
std::string name; ///< Attribute name
......@@ -131,19 +131,19 @@ struct AttrInfo
* @brief 描述一个create table语句
* @details 这里也做了很多简化。
*/
struct CreateTable
struct CreateTableSqlNode
{
std::string relation_name; // Relation name
std::vector<AttrInfo> attr_infos; // attributes
std::string relation_name; ///< Relation name
std::vector<AttrInfoSqlNode> attr_infos; ///< attributes
};
/**
* @brief 描述一个drop table语句
*
*/
struct DropTable
struct DropTableSqlNode
{
std::string relation_name; /// 要删除的表名
std::string relation_name; ///< 要删除的表名
};
/**
......@@ -151,18 +151,18 @@ struct DropTable
* @details 创建索引时,需要指定索引名,表名,字段名。
* 正常的SQL语句中,一个索引可能包含了多个字段,这里仅支持一个字段。
*/
struct CreateIndex
struct CreateIndexSqlNode
{
std::string index_name; /// Index name
std::string relation_name; /// Relation name
std::string attribute_name; /// Attribute name
std::string index_name; ///< Index name
std::string relation_name; ///< Relation name
std::string attribute_name; ///< Attribute name
};
/**
* @brief 描述一个drop index语句
*
*/
struct DropIndex
struct DropIndexSqlNode
{
std::string index_name; ///< Index name
std::string relation_name; ///< Relation name
......@@ -172,7 +172,7 @@ struct DropIndex
* @brief 描述一个desc table语句
* @details desc table 是查询表结构信息的语句
*/
struct DescTable
struct DescTableSqlNode
{
std::string relation_name;
};
......@@ -181,19 +181,23 @@ struct DescTable
* @brief 描述一个load data语句
* @details 从文件导入数据到表中。文件中的每一行就是一条数据,每行的数据类型、字段个数都与表保持一致
*/
struct LoadData
struct LoadDataSqlNode
{
std::string relation_name;
std::string file_name;
};
struct SetVariable
/**
* @brief 设置变量的值
* @note 当前还没有查询变量
*/
struct SetVariableSqlNode
{
std::string name;
Value value;
};
class Command;
class ParsedSqlNode;
/**
* @brief 描述一个explain语句
......@@ -201,16 +205,16 @@ class Command;
* 一个command就是一个语句,比如select语句,insert语句等。
* 可能改成SqlCommand更合适。
*/
struct Explain
struct ExplainSqlNode
{
std::unique_ptr<Command> cmd;
std::unique_ptr<ParsedSqlNode> sql_node;
};
/**
* @brief 解析SQL语句出现了错误
* @details 当前解析时并没有处理错误的行号和列号
*/
struct Error
struct ErrorSqlNode
{
std::string error_msg;
int line;
......@@ -249,42 +253,41 @@ enum SqlCommandFlag
* @brief 表示一个SQL语句
*
*/
class Command
class ParsedSqlNode
{
public:
enum SqlCommandFlag flag;
Error error;
Selects selection;
Inserts insertion;
Deletes deletion;
Updates update;
CreateTable create_table;
DropTable drop_table;
CreateIndex create_index;
DropIndex drop_index;
DescTable desc_table;
LoadData load_data;
Explain explain;
SetVariable set_variable;
ErrorSqlNode error;
SelectSqlNode selection;
InsertSqlNode insertion;
DeleteSqlNode deletion;
UpdateSqlNode update;
CreateTableSqlNode create_table;
DropTableSqlNode drop_table;
CreateIndexSqlNode create_index;
DropIndexSqlNode drop_index;
DescTableSqlNode desc_table;
LoadDataSqlNode load_data;
ExplainSqlNode explain;
SetVariableSqlNode set_variable;
public:
Command();
explicit Command(SqlCommandFlag flag);
ParsedSqlNode();
explicit ParsedSqlNode(SqlCommandFlag flag);
};
/**
* @brief 表示语法解析后的数据
* 叫ParsedSqlNode 可能会更清晰一点
*/
class ParsedSqlResult
{
public:
void add_command(std::unique_ptr<Command> command);
std::vector<std::unique_ptr<Command>> &commands()
void add_sql_node(std::unique_ptr<ParsedSqlNode> sql_node);
std::vector<std::unique_ptr<ParsedSqlNode>> &sql_nodes()
{
return sql_commands_;
return sql_nodes_;
}
private:
std::vector<std::unique_ptr<Command>> sql_commands_; ///< 这里记录SQL命令。虽然看起来支持多个,但是当前仅处理一个
std::vector<std::unique_ptr<ParsedSqlNode>> sql_nodes_; ///< 这里记录SQL命令。虽然看起来支持多个,但是当前仅处理一个
};
......@@ -37,18 +37,18 @@ RC ParseStage::handle_request(SQLStageEvent *sql_event)
ParsedSqlResult parsed_sql_result;
parse(sql.c_str(), &parsed_sql_result);
if (parsed_sql_result.commands().empty()) {
if (parsed_sql_result.sql_nodes().empty()) {
sql_result->set_return_code(RC::SUCCESS);
sql_result->set_state_string("");
return RC::INTERNAL;
}
if (parsed_sql_result.commands().size() > 1) {
if (parsed_sql_result.sql_nodes().size() > 1) {
LOG_WARN("got multi sql commands but only 1 will be handled");
}
std::unique_ptr<Command> cmd = std::move(parsed_sql_result.commands().front());
if (cmd->flag == SCF_ERROR) {
std::unique_ptr<ParsedSqlNode> sql_node = std::move(parsed_sql_result.sql_nodes().front());
if (sql_node->flag == SCF_ERROR) {
// set error information to event
rc = RC::SQL_SYNTAX;
sql_result->set_return_code(rc);
......@@ -56,7 +56,7 @@ RC ParseStage::handle_request(SQLStageEvent *sql_event)
return rc;
}
sql_event->set_command(std::move(cmd));
sql_event->set_sql_node(std::move(sql_node));
return RC::SUCCESS;
}
......@@ -43,9 +43,9 @@ RC ResolveStage::handle_request(SQLStageEvent *sql_event)
return rc;
}
Command *cmd = sql_event->command().get();
ParsedSqlNode *sql_node = sql_event->sql_node().get();
Stmt *stmt = nullptr;
rc = Stmt::create_stmt(db, *cmd, stmt);
rc = Stmt::create_stmt(db, *sql_node, stmt);
if (rc != RC::SUCCESS && rc != RC::UNIMPLENMENT) {
LOG_WARN("failed to create stmt. rc=%d:%s", rc, strrc(rc));
sql_result->set_return_code(rc);
......
......@@ -84,11 +84,11 @@
int yyerror(YYLTYPE *llocp, ParsedSqlResult *sql_result, yyscan_t scanner, const char *msg)
{
std::unique_ptr<Command> error_cmd = std::make_unique<Command>(SCF_ERROR);
error_cmd->error.error_msg = msg;
error_cmd->error.line = llocp->first_line;
error_cmd->error.column = llocp->first_column;
sql_result->add_command(std::move(error_cmd));
std::unique_ptr<ParsedSqlNode> error_sql_node = std::make_unique<ParsedSqlNode>(SCF_ERROR);
error_sql_node->error.error_msg = msg;
error_sql_node->error.line = llocp->first_line;
error_sql_node->error.column = llocp->first_column;
sql_result->add_sql_node(std::move(error_sql_node));
return 0;
}
......@@ -1645,8 +1645,8 @@ yyreduce:
case 2: /* commands: command_wrapper opt_semicolon */
#line 144 "yacc_sql.y"
{
std::unique_ptr<Command> sql_command = std::unique_ptr<Command>((yyvsp[-1].command));
sql_result->add_command(std::move(sql_command));
std::unique_ptr<ParsedSqlNode> sql_node = std::unique_ptr<ParsedSqlNode>((yyvsp[-1].sql_node));
sql_result->add_sql_node(std::move(sql_node));
}
#line 1652 "yacc_sql.cpp"
break;
......@@ -1655,7 +1655,7 @@ yyreduce:
#line 173 "yacc_sql.y"
{
(void)yynerrs; // 这么写为了消除yynerrs未使用的告警。如果你有更好的方法欢迎提PR
(yyval.command) = new Command(SCF_EXIT);
(yyval.sql_node) = new ParsedSqlNode(SCF_EXIT);
}
#line 1661 "yacc_sql.cpp"
break;
......@@ -1663,7 +1663,7 @@ yyreduce:
case 23: /* help: HELP */
#line 179 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_HELP);
(yyval.sql_node) = new ParsedSqlNode(SCF_HELP);
}
#line 1669 "yacc_sql.cpp"
break;
......@@ -1671,7 +1671,7 @@ yyreduce:
case 24: /* sync: SYNC */
#line 184 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_SYNC);
(yyval.sql_node) = new ParsedSqlNode(SCF_SYNC);
}
#line 1677 "yacc_sql.cpp"
break;
......@@ -1679,7 +1679,7 @@ yyreduce:
case 25: /* begin: TRX_BEGIN */
#line 190 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_BEGIN);
(yyval.sql_node) = new ParsedSqlNode(SCF_BEGIN);
}
#line 1685 "yacc_sql.cpp"
break;
......@@ -1687,7 +1687,7 @@ yyreduce:
case 26: /* commit: TRX_COMMIT */
#line 196 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_COMMIT);
(yyval.sql_node) = new ParsedSqlNode(SCF_COMMIT);
}
#line 1693 "yacc_sql.cpp"
break;
......@@ -1695,7 +1695,7 @@ yyreduce:
case 27: /* rollback: TRX_ROLLBACK */
#line 202 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_ROLLBACK);
(yyval.sql_node) = new ParsedSqlNode(SCF_ROLLBACK);
}
#line 1701 "yacc_sql.cpp"
break;
......@@ -1703,8 +1703,8 @@ yyreduce:
case 28: /* drop_table: DROP TABLE ID */
#line 208 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_DROP_TABLE);
(yyval.command)->drop_table.relation_name = (yyvsp[0].string);
(yyval.sql_node) = new ParsedSqlNode(SCF_DROP_TABLE);
(yyval.sql_node)->drop_table.relation_name = (yyvsp[0].string);
free((yyvsp[0].string));
}
#line 1711 "yacc_sql.cpp"
......@@ -1713,7 +1713,7 @@ yyreduce:
case 29: /* show_tables: SHOW TABLES */
#line 215 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_SHOW_TABLES);
(yyval.sql_node) = new ParsedSqlNode(SCF_SHOW_TABLES);
}
#line 1719 "yacc_sql.cpp"
break;
......@@ -1721,8 +1721,8 @@ yyreduce:
case 30: /* desc_table: DESC ID */
#line 221 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_DESC_TABLE);
(yyval.command)->desc_table.relation_name = (yyvsp[0].string);
(yyval.sql_node) = new ParsedSqlNode(SCF_DESC_TABLE);
(yyval.sql_node)->desc_table.relation_name = (yyvsp[0].string);
free((yyvsp[0].string));
}
#line 1729 "yacc_sql.cpp"
......@@ -1731,8 +1731,8 @@ yyreduce:
case 31: /* create_index: CREATE INDEX ID ON ID LBRACE ID RBRACE */
#line 230 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_CREATE_INDEX);
CreateIndex &create_index = (yyval.command)->create_index;
(yyval.sql_node) = new ParsedSqlNode(SCF_CREATE_INDEX);
CreateIndexSqlNode &create_index = (yyval.sql_node)->create_index;
create_index.index_name = (yyvsp[-5].string);
create_index.relation_name = (yyvsp[-3].string);
create_index.attribute_name = (yyvsp[-1].string);
......@@ -1746,9 +1746,9 @@ yyreduce:
case 32: /* drop_index: DROP INDEX ID ON ID */
#line 244 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_DROP_INDEX);
(yyval.command)->drop_index.index_name = (yyvsp[-2].string);
(yyval.command)->drop_index.relation_name = (yyvsp[0].string);
(yyval.sql_node) = new ParsedSqlNode(SCF_DROP_INDEX);
(yyval.sql_node)->drop_index.index_name = (yyvsp[-2].string);
(yyval.sql_node)->drop_index.relation_name = (yyvsp[0].string);
free((yyvsp[-2].string));
free((yyvsp[0].string));
}
......@@ -1758,12 +1758,12 @@ yyreduce:
case 33: /* create_table: CREATE TABLE ID LBRACE attr_def attr_def_list RBRACE */
#line 254 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_CREATE_TABLE);
CreateTable &create_table = (yyval.command)->create_table;
(yyval.sql_node) = new ParsedSqlNode(SCF_CREATE_TABLE);
CreateTableSqlNode &create_table = (yyval.sql_node)->create_table;
create_table.relation_name = (yyvsp[-4].string);
free((yyvsp[-4].string));
std::vector<AttrInfo> *src_attrs = (yyvsp[-1].attr_infos);
std::vector<AttrInfoSqlNode> *src_attrs = (yyvsp[-1].attr_infos);
if (src_attrs != nullptr) {
create_table.attr_infos.swap(*src_attrs);
......@@ -1789,7 +1789,7 @@ yyreduce:
if ((yyvsp[0].attr_infos) != nullptr) {
(yyval.attr_infos) = (yyvsp[0].attr_infos);
} else {
(yyval.attr_infos) = new std::vector<AttrInfo>;
(yyval.attr_infos) = new std::vector<AttrInfoSqlNode>;
}
(yyval.attr_infos)->emplace_back(*(yyvsp[-1].attr_info));
delete (yyvsp[-1].attr_info);
......@@ -1800,7 +1800,7 @@ yyreduce:
case 36: /* attr_def: ID type LBRACE number RBRACE */
#line 289 "yacc_sql.y"
{
(yyval.attr_info) = new AttrInfo;
(yyval.attr_info) = new AttrInfoSqlNode;
(yyval.attr_info)->type = (AttrType)(yyvsp[-3].number);
(yyval.attr_info)->name = (yyvsp[-4].string);
(yyval.attr_info)->length = (yyvsp[-1].number);
......@@ -1812,7 +1812,7 @@ yyreduce:
case 37: /* attr_def: ID type */
#line 297 "yacc_sql.y"
{
(yyval.attr_info) = new AttrInfo;
(yyval.attr_info) = new AttrInfoSqlNode;
(yyval.attr_info)->type = (AttrType)(yyvsp[0].number);
(yyval.attr_info)->name = (yyvsp[-1].string);
(yyval.attr_info)->length = 4;
......@@ -1848,13 +1848,13 @@ yyreduce:
case 42: /* insert: INSERT INTO ID VALUES LBRACE value value_list RBRACE */
#line 315 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_INSERT);
(yyval.command)->insertion.relation_name = (yyvsp[-5].string);
(yyval.sql_node) = new ParsedSqlNode(SCF_INSERT);
(yyval.sql_node)->insertion.relation_name = (yyvsp[-5].string);
if ((yyvsp[-1].value_list) != nullptr) {
(yyval.command)->insertion.values.swap(*(yyvsp[-1].value_list));
(yyval.sql_node)->insertion.values.swap(*(yyvsp[-1].value_list));
}
(yyval.command)->insertion.values.emplace_back(*(yyvsp[-2].value));
std::reverse((yyval.command)->insertion.values.begin(), (yyval.command)->insertion.values.end());
(yyval.sql_node)->insertion.values.emplace_back(*(yyvsp[-2].value));
std::reverse((yyval.sql_node)->insertion.values.begin(), (yyval.sql_node)->insertion.values.end());
delete (yyvsp[-2].value);
free((yyvsp[-5].string));
}
......@@ -1912,10 +1912,10 @@ yyreduce:
case 48: /* delete: DELETE FROM ID where */
#line 359 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_DELETE);
(yyval.command)->deletion.relation_name = (yyvsp[-1].string);
(yyval.sql_node) = new ParsedSqlNode(SCF_DELETE);
(yyval.sql_node)->deletion.relation_name = (yyvsp[-1].string);
if ((yyvsp[0].condition_list) != nullptr) {
(yyval.command)->deletion.conditions.swap(*(yyvsp[0].condition_list));
(yyval.sql_node)->deletion.conditions.swap(*(yyvsp[0].condition_list));
delete (yyvsp[0].condition_list);
}
free((yyvsp[-1].string));
......@@ -1926,12 +1926,12 @@ yyreduce:
case 49: /* update: UPDATE ID SET ID EQ value where */
#line 371 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_UPDATE);
(yyval.command)->update.relation_name = (yyvsp[-5].string);
(yyval.command)->update.attribute_name = (yyvsp[-3].string);
(yyval.command)->update.value = *(yyvsp[-1].value);
(yyval.sql_node) = new ParsedSqlNode(SCF_UPDATE);
(yyval.sql_node)->update.relation_name = (yyvsp[-5].string);
(yyval.sql_node)->update.attribute_name = (yyvsp[-3].string);
(yyval.sql_node)->update.value = *(yyvsp[-1].value);
if ((yyvsp[0].condition_list) != nullptr) {
(yyval.command)->update.conditions.swap(*(yyvsp[0].condition_list));
(yyval.sql_node)->update.conditions.swap(*(yyvsp[0].condition_list));
delete (yyvsp[0].condition_list);
}
free((yyvsp[-5].string));
......@@ -1943,20 +1943,20 @@ yyreduce:
case 50: /* select: SELECT select_attr FROM ID rel_list where */
#line 386 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_SELECT);
(yyval.sql_node) = new ParsedSqlNode(SCF_SELECT);
if ((yyvsp[-4].rel_attr_list) != nullptr) {
(yyval.command)->selection.attributes.swap(*(yyvsp[-4].rel_attr_list));
(yyval.sql_node)->selection.attributes.swap(*(yyvsp[-4].rel_attr_list));
delete (yyvsp[-4].rel_attr_list);
}
if ((yyvsp[-1].relation_list) != nullptr) {
(yyval.command)->selection.relations.swap(*(yyvsp[-1].relation_list));
(yyval.sql_node)->selection.relations.swap(*(yyvsp[-1].relation_list));
delete (yyvsp[-1].relation_list);
}
(yyval.command)->selection.relations.push_back((yyvsp[-2].string));
std::reverse((yyval.command)->selection.relations.begin(), (yyval.command)->selection.relations.end());
(yyval.sql_node)->selection.relations.push_back((yyvsp[-2].string));
std::reverse((yyval.sql_node)->selection.relations.begin(), (yyval.sql_node)->selection.relations.end());
if ((yyvsp[0].condition_list) != nullptr) {
(yyval.command)->selection.conditions.swap(*(yyvsp[0].condition_list));
(yyval.sql_node)->selection.conditions.swap(*(yyvsp[0].condition_list));
delete (yyvsp[0].condition_list);
}
free((yyvsp[-2].string));
......@@ -1967,8 +1967,8 @@ yyreduce:
case 51: /* select_attr: STAR */
#line 408 "yacc_sql.y"
{
(yyval.rel_attr_list) = new std::vector<RelAttr>;
RelAttr attr;
(yyval.rel_attr_list) = new std::vector<RelAttrSqlNode>;
RelAttrSqlNode attr;
attr.relation_name = "";
attr.attribute_name = "*";
(yyval.rel_attr_list)->emplace_back(attr);
......@@ -1982,7 +1982,7 @@ yyreduce:
if ((yyvsp[0].rel_attr_list) != nullptr) {
(yyval.rel_attr_list) = (yyvsp[0].rel_attr_list);
} else {
(yyval.rel_attr_list) = new std::vector<RelAttr>;
(yyval.rel_attr_list) = new std::vector<RelAttrSqlNode>;
}
(yyval.rel_attr_list)->emplace_back(*(yyvsp[-1].rel_attr));
delete (yyvsp[-1].rel_attr);
......@@ -1993,7 +1993,7 @@ yyreduce:
case 53: /* rel_attr: ID */
#line 427 "yacc_sql.y"
{
(yyval.rel_attr) = new RelAttr;
(yyval.rel_attr) = new RelAttrSqlNode;
(yyval.rel_attr)->attribute_name = (yyvsp[0].string);
free((yyvsp[0].string));
}
......@@ -2003,7 +2003,7 @@ yyreduce:
case 54: /* rel_attr: ID DOT ID */
#line 432 "yacc_sql.y"
{
(yyval.rel_attr) = new RelAttr;
(yyval.rel_attr) = new RelAttrSqlNode;
(yyval.rel_attr)->relation_name = (yyvsp[-2].string);
(yyval.rel_attr)->attribute_name = (yyvsp[0].string);
free((yyvsp[-2].string));
......@@ -2026,7 +2026,7 @@ yyreduce:
if ((yyvsp[0].rel_attr_list) != nullptr) {
(yyval.rel_attr_list) = (yyvsp[0].rel_attr_list);
} else {
(yyval.rel_attr_list) = new std::vector<RelAttr>;
(yyval.rel_attr_list) = new std::vector<RelAttrSqlNode>;
}
(yyval.rel_attr_list)->emplace_back(*(yyvsp[-1].rel_attr));
......@@ -2085,7 +2085,7 @@ yyreduce:
case 62: /* condition_list: condition */
#line 488 "yacc_sql.y"
{
(yyval.condition_list) = new std::vector<Condition>;
(yyval.condition_list) = new std::vector<ConditionSqlNode>;
(yyval.condition_list)->emplace_back(*(yyvsp[0].condition));
delete (yyvsp[0].condition);
}
......@@ -2105,7 +2105,7 @@ yyreduce:
case 64: /* condition: rel_attr comp_op value */
#line 501 "yacc_sql.y"
{
(yyval.condition) = new Condition;
(yyval.condition) = new ConditionSqlNode;
(yyval.condition)->left_is_attr = 1;
(yyval.condition)->left_attr = *(yyvsp[-2].rel_attr);
(yyval.condition)->right_is_attr = 0;
......@@ -2121,7 +2121,7 @@ yyreduce:
case 65: /* condition: value comp_op value */
#line 513 "yacc_sql.y"
{
(yyval.condition) = new Condition;
(yyval.condition) = new ConditionSqlNode;
(yyval.condition)->left_is_attr = 0;
(yyval.condition)->left_value = *(yyvsp[-2].value);
(yyval.condition)->right_is_attr = 0;
......@@ -2137,7 +2137,7 @@ yyreduce:
case 66: /* condition: rel_attr comp_op rel_attr */
#line 525 "yacc_sql.y"
{
(yyval.condition) = new Condition;
(yyval.condition) = new ConditionSqlNode;
(yyval.condition)->left_is_attr = 1;
(yyval.condition)->left_attr = *(yyvsp[-2].rel_attr);
(yyval.condition)->right_is_attr = 1;
......@@ -2153,7 +2153,7 @@ yyreduce:
case 67: /* condition: value comp_op rel_attr */
#line 537 "yacc_sql.y"
{
(yyval.condition) = new Condition;
(yyval.condition) = new ConditionSqlNode;
(yyval.condition)->left_is_attr = 0;
(yyval.condition)->left_value = *(yyvsp[-2].value);
(yyval.condition)->right_is_attr = 1;
......@@ -2207,9 +2207,9 @@ yyreduce:
{
char *tmp_file_name = common::substr((yyvsp[-3].string), 1, strlen((yyvsp[-3].string)) - 2);
(yyval.command) = new Command(SCF_LOAD_DATA);
(yyval.command)->load_data.relation_name = (yyvsp[0].string);
(yyval.command)->load_data.file_name = tmp_file_name;
(yyval.sql_node) = new ParsedSqlNode(SCF_LOAD_DATA);
(yyval.sql_node)->load_data.relation_name = (yyvsp[0].string);
(yyval.sql_node)->load_data.file_name = tmp_file_name;
free((yyvsp[0].string));
free(tmp_file_name);
}
......@@ -2219,8 +2219,8 @@ yyreduce:
case 75: /* explain: EXPLAIN command_wrapper */
#line 574 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_EXPLAIN);
(yyval.command)->explain.cmd = std::unique_ptr<Command>((yyvsp[0].command));
(yyval.sql_node) = new ParsedSqlNode(SCF_EXPLAIN);
(yyval.sql_node)->explain.sql_node = std::unique_ptr<ParsedSqlNode>((yyvsp[0].sql_node));
}
#line 2226 "yacc_sql.cpp"
break;
......@@ -2228,9 +2228,9 @@ yyreduce:
case 76: /* set_variable: SET ID EQ value */
#line 582 "yacc_sql.y"
{
(yyval.command) = new Command(SCF_SET_VARIABLE);
(yyval.command)->set_variable.name = (yyvsp[-2].string);
(yyval.command)->set_variable.value = *(yyvsp[0].value);
(yyval.sql_node) = new ParsedSqlNode(SCF_SET_VARIABLE);
(yyval.sql_node)->set_variable.name = (yyvsp[-2].string);
(yyval.sql_node)->set_variable.value = *(yyvsp[0].value);
free((yyvsp[-2].string));
delete (yyvsp[0].value);
}
......
......@@ -113,18 +113,18 @@ union YYSTYPE
{
#line 79 "yacc_sql.y"
Command *command;
Condition *condition;
Value *value;
ParsedSqlNode * sql_node;
ConditionSqlNode * condition;
Value * value;
enum CompOp comp;
RelAttr *rel_attr;
std::vector<AttrInfo> *attr_infos;
AttrInfo *attr_info;
std::vector<Value> *value_list;
std::vector<Condition> *condition_list;
std::vector<RelAttr> *rel_attr_list;
std::vector<std::string> *relation_list;
char *string;
RelAttrSqlNode * rel_attr;
std::vector<AttrInfoSqlNode> * attr_infos;
AttrInfoSqlNode * attr_info;
std::vector<Value> * value_list;
std::vector<ConditionSqlNode> * condition_list;
std::vector<RelAttrSqlNode> * rel_attr_list;
std::vector<std::string> * relation_list;
char * string;
int number;
float floats;
......
......@@ -15,11 +15,11 @@
int yyerror(YYLTYPE *llocp, ParsedSqlResult *sql_result, yyscan_t scanner, const char *msg)
{
std::unique_ptr<Command> error_cmd = std::make_unique<Command>(SCF_ERROR);
error_cmd->error.error_msg = msg;
error_cmd->error.line = llocp->first_line;
error_cmd->error.column = llocp->first_column;
sql_result->add_command(std::move(error_cmd));
std::unique_ptr<ParsedSqlNode> error_sql_node = std::make_unique<ParsedSqlNode>(SCF_ERROR);
error_sql_node->error.error_msg = msg;
error_sql_node->error.line = llocp->first_line;
error_sql_node->error.column = llocp->first_column;
sql_result->add_sql_node(std::move(error_sql_node));
return 0;
}
......@@ -77,18 +77,18 @@ int yyerror(YYLTYPE *llocp, ParsedSqlResult *sql_result, yyscan_t scanner, const
NE
%union {
Command *command;
Condition *condition;
Value *value;
ParsedSqlNode * sql_node;
ConditionSqlNode * condition;
Value * value;
enum CompOp comp;
RelAttr *rel_attr;
std::vector<AttrInfo> *attr_infos;
AttrInfo *attr_info;
std::vector<Value> *value_list;
std::vector<Condition> *condition_list;
std::vector<RelAttr> *rel_attr_list;
std::vector<std::string> *relation_list;
char *string;
RelAttrSqlNode * rel_attr;
std::vector<AttrInfoSqlNode> * attr_infos;
AttrInfoSqlNode * attr_info;
std::vector<Value> * value_list;
std::vector<ConditionSqlNode> * condition_list;
std::vector<RelAttrSqlNode> * rel_attr_list;
std::vector<std::string> * relation_list;
char * string;
int number;
float floats;
}
......@@ -116,34 +116,34 @@ int yyerror(YYLTYPE *llocp, ParsedSqlResult *sql_result, yyscan_t scanner, const
%type <rel_attr_list> select_attr
%type <relation_list> rel_list
%type <rel_attr_list> attr_list
%type <command> select
%type <command> insert
%type <command> update
%type <command> delete
%type <command> create_table
%type <command> drop_table
%type <command> show_tables
%type <command> desc_table
%type <command> create_index
%type <command> drop_index
%type <command> sync
%type <command> begin
%type <command> commit
%type <command> rollback
%type <command> load_data
%type <command> explain
%type <command> set_variable
%type <command> help
%type <command> exit
%type <command> command_wrapper
%type <sql_node> select
%type <sql_node> insert
%type <sql_node> update
%type <sql_node> delete
%type <sql_node> create_table
%type <sql_node> drop_table
%type <sql_node> show_tables
%type <sql_node> desc_table
%type <sql_node> create_index
%type <sql_node> drop_index
%type <sql_node> sync
%type <sql_node> begin
%type <sql_node> commit
%type <sql_node> rollback
%type <sql_node> load_data
%type <sql_node> explain
%type <sql_node> set_variable
%type <sql_node> help
%type <sql_node> exit
%type <sql_node> command_wrapper
// commands should be a list but I use a single command instead
%type <command> commands
%type <sql_node> commands
%%
commands: command_wrapper opt_semicolon //commands or sqls. parser starts here.
{
std::unique_ptr<Command> sql_command = std::unique_ptr<Command>($1);
sql_result->add_command(std::move(sql_command));
std::unique_ptr<ParsedSqlNode> sql_node = std::unique_ptr<ParsedSqlNode>($1);
sql_result->add_sql_node(std::move(sql_node));
}
;
......@@ -172,54 +172,54 @@ command_wrapper:
exit:
EXIT {
(void)yynerrs; // 这么写为了消除yynerrs未使用的告警。如果你有更好的方法欢迎提PR
$$ = new Command(SCF_EXIT);
$$ = new ParsedSqlNode(SCF_EXIT);
};
help:
HELP {
$$ = new Command(SCF_HELP);
$$ = new ParsedSqlNode(SCF_HELP);
};
sync:
SYNC {
$$ = new Command(SCF_SYNC);
$$ = new ParsedSqlNode(SCF_SYNC);
}
;
begin:
TRX_BEGIN {
$$ = new Command(SCF_BEGIN);
$$ = new ParsedSqlNode(SCF_BEGIN);
}
;
commit:
TRX_COMMIT {
$$ = new Command(SCF_COMMIT);
$$ = new ParsedSqlNode(SCF_COMMIT);
}
;
rollback:
TRX_ROLLBACK {
$$ = new Command(SCF_ROLLBACK);
$$ = new ParsedSqlNode(SCF_ROLLBACK);
}
;
drop_table: /*drop table 语句的语法解析树*/
DROP TABLE ID {
$$ = new Command(SCF_DROP_TABLE);
$$ = new ParsedSqlNode(SCF_DROP_TABLE);
$$->drop_table.relation_name = $3;
free($3);
};
show_tables:
SHOW TABLES {
$$ = new Command(SCF_SHOW_TABLES);
$$ = new ParsedSqlNode(SCF_SHOW_TABLES);
}
;
desc_table:
DESC ID {
$$ = new Command(SCF_DESC_TABLE);
$$ = new ParsedSqlNode(SCF_DESC_TABLE);
$$->desc_table.relation_name = $2;
free($2);
}
......@@ -228,8 +228,8 @@ desc_table:
create_index: /*create index 语句的语法解析树*/
CREATE INDEX ID ON ID LBRACE ID RBRACE
{
$$ = new Command(SCF_CREATE_INDEX);
CreateIndex &create_index = $$->create_index;
$$ = new ParsedSqlNode(SCF_CREATE_INDEX);
CreateIndexSqlNode &create_index = $$->create_index;
create_index.index_name = $3;
create_index.relation_name = $5;
create_index.attribute_name = $7;
......@@ -242,7 +242,7 @@ create_index: /*create index 语句的语法解析树*/
drop_index: /*drop index 语句的语法解析树*/
DROP INDEX ID ON ID
{
$$ = new Command(SCF_DROP_INDEX);
$$ = new ParsedSqlNode(SCF_DROP_INDEX);
$$->drop_index.index_name = $3;
$$->drop_index.relation_name = $5;
free($3);
......@@ -252,12 +252,12 @@ drop_index: /*drop index 语句的语法解析树*/
create_table: /*create table 语句的语法解析树*/
CREATE TABLE ID LBRACE attr_def attr_def_list RBRACE
{
$$ = new Command(SCF_CREATE_TABLE);
CreateTable &create_table = $$->create_table;
$$ = new ParsedSqlNode(SCF_CREATE_TABLE);
CreateTableSqlNode &create_table = $$->create_table;
create_table.relation_name = $3;
free($3);
std::vector<AttrInfo> *src_attrs = $6;
std::vector<AttrInfoSqlNode> *src_attrs = $6;
if (src_attrs != nullptr) {
create_table.attr_infos.swap(*src_attrs);
......@@ -277,7 +277,7 @@ attr_def_list:
if ($3 != nullptr) {
$$ = $3;
} else {
$$ = new std::vector<AttrInfo>;
$$ = new std::vector<AttrInfoSqlNode>;
}
$$->emplace_back(*$2);
delete $2;
......@@ -287,7 +287,7 @@ attr_def_list:
attr_def:
ID type LBRACE number RBRACE
{
$$ = new AttrInfo;
$$ = new AttrInfoSqlNode;
$$->type = (AttrType)$2;
$$->name = $1;
$$->length = $4;
......@@ -295,7 +295,7 @@ attr_def:
}
| ID type
{
$$ = new AttrInfo;
$$ = new AttrInfoSqlNode;
$$->type = (AttrType)$2;
$$->name = $1;
$$->length = 4;
......@@ -313,7 +313,7 @@ type:
insert: /*insert 语句的语法解析树*/
INSERT INTO ID VALUES LBRACE value value_list RBRACE
{
$$ = new Command(SCF_INSERT);
$$ = new ParsedSqlNode(SCF_INSERT);
$$->insertion.relation_name = $3;
if ($7 != nullptr) {
$$->insertion.values.swap(*$7);
......@@ -357,7 +357,7 @@ value:
delete: /* delete 语句的语法解析树*/
DELETE FROM ID where
{
$$ = new Command(SCF_DELETE);
$$ = new ParsedSqlNode(SCF_DELETE);
$$->deletion.relation_name = $3;
if ($4 != nullptr) {
$$->deletion.conditions.swap(*$4);
......@@ -369,7 +369,7 @@ delete: /* delete 语句的语法解析树*/
update: /* update 语句的语法解析树*/
UPDATE ID SET ID EQ value where
{
$$ = new Command(SCF_UPDATE);
$$ = new ParsedSqlNode(SCF_UPDATE);
$$->update.relation_name = $2;
$$->update.attribute_name = $4;
$$->update.value = *$6;
......@@ -384,7 +384,7 @@ update: /* update 语句的语法解析树*/
select: /* select 语句的语法解析树*/
SELECT select_attr FROM ID rel_list where
{
$$ = new Command(SCF_SELECT);
$$ = new ParsedSqlNode(SCF_SELECT);
if ($2 != nullptr) {
$$->selection.attributes.swap(*$2);
delete $2;
......@@ -406,8 +406,8 @@ select: /* select 语句的语法解析树*/
select_attr:
STAR {
$$ = new std::vector<RelAttr>;
RelAttr attr;
$$ = new std::vector<RelAttrSqlNode>;
RelAttrSqlNode attr;
attr.relation_name = "";
attr.attribute_name = "*";
$$->emplace_back(attr);
......@@ -416,7 +416,7 @@ select_attr:
if ($2 != nullptr) {
$$ = $2;
} else {
$$ = new std::vector<RelAttr>;
$$ = new std::vector<RelAttrSqlNode>;
}
$$->emplace_back(*$1);
delete $1;
......@@ -425,12 +425,12 @@ select_attr:
rel_attr:
ID {
$$ = new RelAttr;
$$ = new RelAttrSqlNode;
$$->attribute_name = $1;
free($1);
}
| ID DOT ID {
$$ = new RelAttr;
$$ = new RelAttrSqlNode;
$$->relation_name = $1;
$$->attribute_name = $3;
free($1);
......@@ -447,7 +447,7 @@ attr_list:
if ($3 != nullptr) {
$$ = $3;
} else {
$$ = new std::vector<RelAttr>;
$$ = new std::vector<RelAttrSqlNode>;
}
$$->emplace_back(*$2);
......@@ -486,7 +486,7 @@ condition_list:
$$ = nullptr;
}
| condition {
$$ = new std::vector<Condition>;
$$ = new std::vector<ConditionSqlNode>;
$$->emplace_back(*$1);
delete $1;
}
......@@ -499,7 +499,7 @@ condition_list:
condition:
rel_attr comp_op value
{
$$ = new Condition;
$$ = new ConditionSqlNode;
$$->left_is_attr = 1;
$$->left_attr = *$1;
$$->right_is_attr = 0;
......@@ -511,7 +511,7 @@ condition:
}
| value comp_op value
{
$$ = new Condition;
$$ = new ConditionSqlNode;
$$->left_is_attr = 0;
$$->left_value = *$1;
$$->right_is_attr = 0;
......@@ -523,7 +523,7 @@ condition:
}
| rel_attr comp_op rel_attr
{
$$ = new Condition;
$$ = new ConditionSqlNode;
$$->left_is_attr = 1;
$$->left_attr = *$1;
$$->right_is_attr = 1;
......@@ -535,7 +535,7 @@ condition:
}
| value comp_op rel_attr
{
$$ = new Condition;
$$ = new ConditionSqlNode;
$$->left_is_attr = 0;
$$->left_value = *$1;
$$->right_is_attr = 1;
......@@ -561,7 +561,7 @@ load_data:
{
char *tmp_file_name = common::substr($4, 1, strlen($4) - 2);
$$ = new Command(SCF_LOAD_DATA);
$$ = new ParsedSqlNode(SCF_LOAD_DATA);
$$->load_data.relation_name = $7;
$$->load_data.file_name = tmp_file_name;
free($7);
......@@ -572,15 +572,15 @@ load_data:
explain:
EXPLAIN command_wrapper
{
$$ = new Command(SCF_EXPLAIN);
$$->explain.cmd = std::unique_ptr<Command>($2);
$$ = new ParsedSqlNode(SCF_EXPLAIN);
$$->explain.sql_node = std::unique_ptr<ParsedSqlNode>($2);
}
;
set_variable:
SET ID EQ value
{
$$ = new Command(SCF_SET_VARIABLE);
$$ = new ParsedSqlNode(SCF_SET_VARIABLE);
$$->set_variable.name = $2;
$$->set_variable.value = *$4;
free($2);
......
......@@ -21,7 +21,7 @@ See the Mulan PSL v2 for more details. */
using namespace std;
using namespace common;
RC CreateIndexStmt::create(Db *db, const CreateIndex &create_index, Stmt *&stmt)
RC CreateIndexStmt::create(Db *db, const CreateIndexSqlNode &create_index, Stmt *&stmt)
{
stmt = nullptr;
......
......@@ -18,7 +18,7 @@ See the Mulan PSL v2 for more details. */
#include "sql/stmt/stmt.h"
struct CreateIndex;
struct CreateIndexSqlNode;
class Table;
class FieldMeta;
......@@ -44,7 +44,7 @@ public:
const std::string &index_name() const { return index_name_; }
public:
static RC create(Db *db, const CreateIndex &create_index, Stmt *&stmt);
static RC create(Db *db, const CreateIndexSqlNode &create_index, Stmt *&stmt);
private:
Table *table_ = nullptr;
......
......@@ -15,7 +15,7 @@ See the Mulan PSL v2 for more details. */
#include "sql/stmt/create_table_stmt.h"
#include "event/sql_debug.h"
RC CreateTableStmt::create(Db *db, const CreateTable &create_table, Stmt *&stmt)
RC CreateTableStmt::create(Db *db, const CreateTableSqlNode &create_table, Stmt *&stmt)
{
stmt = new CreateTableStmt(create_table.relation_name, create_table.attr_infos);
sql_debug("create table statement: table name %s", create_table.relation_name.c_str());
......
......@@ -29,7 +29,7 @@ class Db;
class CreateTableStmt : public Stmt
{
public:
CreateTableStmt(const std::string &table_name, const std::vector<AttrInfo> &attr_infos)
CreateTableStmt(const std::string &table_name, const std::vector<AttrInfoSqlNode> &attr_infos)
: table_name_(table_name),
attr_infos_(attr_infos)
{}
......@@ -38,11 +38,11 @@ public:
StmtType type() const override { return StmtType::CREATE_TABLE; }
const std::string &table_name() const { return table_name_; }
const std::vector<AttrInfo> &attr_infos() const { return attr_infos_; }
const std::vector<AttrInfoSqlNode> &attr_infos() const { return attr_infos_; }
static RC create(Db *db, const CreateTable &create_table, Stmt *&stmt);
static RC create(Db *db, const CreateTableSqlNode &create_table, Stmt *&stmt);
private:
std::string table_name_;
std::vector<AttrInfo> attr_infos_;
std::vector<AttrInfoSqlNode> attr_infos_;
};
\ No newline at end of file
......@@ -29,7 +29,7 @@ DeleteStmt::~DeleteStmt()
}
}
RC DeleteStmt::create(Db *db, const Deletes &delete_sql, Stmt *&stmt)
RC DeleteStmt::create(Db *db, const DeleteSqlNode &delete_sql, Stmt *&stmt)
{
const char *table_name = delete_sql.relation_name.c_str();
if (nullptr == db || nullptr == table_name) {
......
......@@ -45,7 +45,7 @@ public:
}
public:
static RC create(Db *db, const Deletes &delete_sql, Stmt *&stmt);
static RC create(Db *db, const DeleteSqlNode &delete_sql, Stmt *&stmt);
private:
Table *table_ = nullptr;
......
......@@ -15,7 +15,7 @@ See the Mulan PSL v2 for more details. */
#include "sql/stmt/desc_table_stmt.h"
#include "storage/db/db.h"
RC DescTableStmt::create(Db *db, const DescTable &desc_table, Stmt *&stmt)
RC DescTableStmt::create(Db *db, const DescTableSqlNode &desc_table, Stmt *&stmt)
{
if (db->find_table(desc_table.relation_name.c_str()) == nullptr) {
return RC::SCHEMA_TABLE_NOT_EXIST;
......
......@@ -38,7 +38,7 @@ public:
const std::string &table_name() const { return table_name_; }
static RC create(Db *db, const DescTable &desc_table, Stmt *&stmt);
static RC create(Db *db, const DescTableSqlNode &desc_table, Stmt *&stmt);
private:
std::string table_name_;
......
......@@ -19,10 +19,10 @@ See the Mulan PSL v2 for more details. */
ExplainStmt::ExplainStmt(std::unique_ptr<Stmt> child_stmt) : child_stmt_(std::move(child_stmt))
{}
RC ExplainStmt::create(Db *db, const Explain &explain, Stmt *&stmt)
RC ExplainStmt::create(Db *db, const ExplainSqlNode &explain, Stmt *&stmt)
{
Stmt *child_stmt = nullptr;
RC rc = Stmt::create_stmt(db, *explain.cmd, child_stmt);
RC rc = Stmt::create_stmt(db, *explain.sql_node, child_stmt);
if (rc != RC::SUCCESS) {
LOG_WARN("failed to create explain's child stmt. rc=%s", strrc(rc));
return rc;
......
......@@ -37,7 +37,7 @@ public:
return child_stmt_.get();
}
static RC create(Db *db, const Explain &query, Stmt *&stmt);
static RC create(Db *db, const ExplainSqlNode &query, Stmt *&stmt);
private:
std::unique_ptr<Stmt> child_stmt_;
......
......@@ -28,7 +28,7 @@ FilterStmt::~FilterStmt()
}
RC FilterStmt::create(Db *db, Table *default_table, std::unordered_map<std::string, Table *> *tables,
const Condition *conditions, int condition_num, FilterStmt *&stmt)
const ConditionSqlNode *conditions, int condition_num, FilterStmt *&stmt)
{
RC rc = RC::SUCCESS;
stmt = nullptr;
......@@ -50,7 +50,7 @@ RC FilterStmt::create(Db *db, Table *default_table, std::unordered_map<std::stri
}
RC get_table_and_field(Db *db, Table *default_table, std::unordered_map<std::string, Table *> *tables,
const RelAttr &attr, Table *&table, const FieldMeta *&field)
const RelAttrSqlNode &attr, Table *&table, const FieldMeta *&field)
{
if (common::is_blank(attr.relation_name.c_str())) {
table = default_table;
......@@ -78,7 +78,7 @@ RC get_table_and_field(Db *db, Table *default_table, std::unordered_map<std::str
}
RC FilterStmt::create_filter_unit(Db *db, Table *default_table, std::unordered_map<std::string, Table *> *tables,
const Condition &condition, FilterUnit *&filter_unit)
const ConditionSqlNode &condition, FilterUnit *&filter_unit)
{
RC rc = RC::SUCCESS;
......
......@@ -102,10 +102,10 @@ public:
public:
static RC create(Db *db, Table *default_table, std::unordered_map<std::string, Table *> *tables,
const Condition *conditions, int condition_num, FilterStmt *&stmt);
const ConditionSqlNode *conditions, int condition_num, FilterStmt *&stmt);
static RC create_filter_unit(Db *db, Table *default_table, std::unordered_map<std::string, Table *> *tables,
const Condition &condition, FilterUnit *&filter_unit);
const ConditionSqlNode &condition, FilterUnit *&filter_unit);
private:
std::vector<FilterUnit *> filter_units_; // 默认当前都是AND关系
......
......@@ -21,7 +21,7 @@ InsertStmt::InsertStmt(Table *table, const Value *values, int value_amount)
: table_(table), values_(values), value_amount_(value_amount)
{}
RC InsertStmt::create(Db *db, const Inserts &inserts, Stmt *&stmt)
RC InsertStmt::create(Db *db, const InsertSqlNode &inserts, Stmt *&stmt)
{
const char *table_name = inserts.relation_name.c_str();
if (nullptr == db || nullptr == table_name || inserts.values.empty()) {
......
......@@ -36,7 +36,7 @@ public:
}
public:
static RC create(Db *db, const Inserts &insert_sql, Stmt *&stmt);
static RC create(Db *db, const InsertSqlNode &insert_sql, Stmt *&stmt);
public:
Table *table() const
......
......@@ -21,7 +21,7 @@ See the Mulan PSL v2 for more details. */
using namespace common;
RC LoadDataStmt::create(Db *db, const LoadData &load_data, Stmt *&stmt)
RC LoadDataStmt::create(Db *db, const LoadDataSqlNode &load_data, Stmt *&stmt)
{
RC rc = RC::SUCCESS;
const char *table_name = load_data.relation_name.c_str();
......
......@@ -33,7 +33,7 @@ public:
Table *table() const { return table_; }
const char *filename() const { return filename_.c_str(); }
static RC create(Db *db, const LoadData &load_data, Stmt *&stmt);
static RC create(Db *db, const LoadDataSqlNode &load_data, Stmt *&stmt);
private:
Table *table_ = nullptr;
......
......@@ -36,7 +36,7 @@ static void wildcard_fields(Table *table, std::vector<Field> &field_metas)
}
}
RC SelectStmt::create(Db *db, const Selects &select_sql, Stmt *&stmt)
RC SelectStmt::create(Db *db, const SelectSqlNode &select_sql, Stmt *&stmt)
{
if (nullptr == db) {
LOG_WARN("invalid argument. db is null");
......@@ -66,7 +66,7 @@ RC SelectStmt::create(Db *db, const Selects &select_sql, Stmt *&stmt)
// collect query fields in `select` statement
std::vector<Field> query_fields;
for (int i = static_cast<int>(select_sql.attributes.size()) - 1; i >= 0; i--) {
const RelAttr &relation_attr = select_sql.attributes[i];
const RelAttrSqlNode &relation_attr = select_sql.attributes[i];
if (common::is_blank(relation_attr.relation_name.c_str()) &&
0 == strcmp(relation_attr.attribute_name.c_str(), "*")) {
......
......@@ -41,7 +41,7 @@ public:
}
public:
static RC create(Db *db, const Selects &select_sql, Stmt *&stmt);
static RC create(Db *db, const SelectSqlNode &select_sql, Stmt *&stmt);
public:
const std::vector<Table *> &tables() const
......
......@@ -26,7 +26,7 @@ See the Mulan PSL v2 for more details. */
class SetVariableStmt : public Stmt
{
public:
SetVariableStmt(const SetVariable &set_variable) : set_variable_(set_variable)
SetVariableStmt(const SetVariableSqlNode &set_variable) : set_variable_(set_variable)
{}
virtual ~SetVariableStmt() = default;
......@@ -35,7 +35,7 @@ public:
const char *var_name() const { return set_variable_.name.c_str(); }
const Value &var_value() const { return set_variable_.value; }
static RC create(const SetVariable &set_variable, Stmt *&stmt)
static RC create(const SetVariableSqlNode &set_variable, Stmt *&stmt)
{
/// 可以校验是否存在某个变量,但是这里忽略
stmt = new SetVariableStmt(set_variable);
......@@ -43,5 +43,5 @@ public:
}
private:
SetVariable set_variable_;
SetVariableSqlNode set_variable_;
};
\ No newline at end of file
......@@ -29,35 +29,35 @@ See the Mulan PSL v2 for more details. */
#include "sql/stmt/set_variable_stmt.h"
#include "sql/stmt/load_data_stmt.h"
RC Stmt::create_stmt(Db *db, const Command &cmd, Stmt *&stmt)
RC Stmt::create_stmt(Db *db, const ParsedSqlNode &sql_node, Stmt *&stmt)
{
stmt = nullptr;
switch (cmd.flag) {
switch (sql_node.flag) {
case SCF_INSERT: {
return InsertStmt::create(db, cmd.insertion, stmt);
return InsertStmt::create(db, sql_node.insertion, stmt);
}
case SCF_DELETE: {
return DeleteStmt::create(db, cmd.deletion, stmt);
return DeleteStmt::create(db, sql_node.deletion, stmt);
}
case SCF_SELECT: {
return SelectStmt::create(db, cmd.selection, stmt);
return SelectStmt::create(db, sql_node.selection, stmt);
}
case SCF_EXPLAIN: {
return ExplainStmt::create(db, cmd.explain, stmt);
return ExplainStmt::create(db, sql_node.explain, stmt);
}
case SCF_CREATE_INDEX: {
return CreateIndexStmt::create(db, cmd.create_index, stmt);
return CreateIndexStmt::create(db, sql_node.create_index, stmt);
}
case SCF_CREATE_TABLE: {
return CreateTableStmt::create(db, cmd.create_table, stmt);
return CreateTableStmt::create(db, sql_node.create_table, stmt);
}
case SCF_DESC_TABLE: {
return DescTableStmt::create(db, cmd.desc_table, stmt);
return DescTableStmt::create(db, sql_node.desc_table, stmt);
}
case SCF_HELP: {
......@@ -74,7 +74,7 @@ RC Stmt::create_stmt(Db *db, const Command &cmd, Stmt *&stmt)
case SCF_COMMIT:
case SCF_ROLLBACK: {
return TrxEndStmt::create(cmd.flag, stmt);
return TrxEndStmt::create(sql_node.flag, stmt);
}
case SCF_EXIT: {
......@@ -82,15 +82,15 @@ RC Stmt::create_stmt(Db *db, const Command &cmd, Stmt *&stmt)
}
case SCF_SET_VARIABLE: {
return SetVariableStmt::create(cmd.set_variable, stmt);
return SetVariableStmt::create(sql_node.set_variable, stmt);
}
case SCF_LOAD_DATA: {
return LoadDataStmt::create(db, cmd.load_data, stmt);
return LoadDataStmt::create(db, sql_node.load_data, stmt);
}
default: {
LOG_INFO("Command::type %d doesn't need to create statement.", cmd.flag);
LOG_INFO("Command::type %d doesn't need to create statement.", sql_node.flag);
} break;
}
return RC::UNIMPLENMENT;
......
......@@ -82,7 +82,7 @@ public:
virtual StmtType type() const = 0;
public:
static RC create_stmt(Db *db, const Command &cmd, Stmt *&stmt);
static RC create_stmt(Db *db, const ParsedSqlNode &sql_node, Stmt *&stmt);
private:
};
......@@ -18,7 +18,7 @@ UpdateStmt::UpdateStmt(Table *table, Value *values, int value_amount)
: table_(table), values_(values), value_amount_(value_amount)
{}
RC UpdateStmt::create(Db *db, const Updates &update, Stmt *&stmt)
RC UpdateStmt::create(Db *db, const UpdateSqlNode &update, Stmt *&stmt)
{
// TODO
stmt = nullptr;
......
......@@ -30,7 +30,7 @@ public:
UpdateStmt(Table *table, Value *values, int value_amount);
public:
static RC create(Db *db, const Updates &update_sql, Stmt *&stmt);
static RC create(Db *db, const UpdateSqlNode &update_sql, Stmt *&stmt);
public:
Table *table() const
......
......@@ -57,7 +57,7 @@ RC DefaultConditionFilter::init(const ConDesc &left, const ConDesc &right, AttrT
return RC::SUCCESS;
}
RC DefaultConditionFilter::init(Table &table, const Condition &condition)
RC DefaultConditionFilter::init(Table &table, const ConditionSqlNode &condition)
{
const TableMeta &table_meta = table.table_meta();
ConDesc left;
......@@ -182,7 +182,7 @@ RC CompositeConditionFilter::init(const ConditionFilter *filters[], int filter_n
return init(filters, filter_num, false);
}
RC CompositeConditionFilter::init(Table &table, const Condition *conditions, int condition_num)
RC CompositeConditionFilter::init(Table &table, const ConditionSqlNode *conditions, int condition_num)
{
if (condition_num == 0) {
return RC::SUCCESS;
......
......@@ -47,7 +47,7 @@ public:
virtual ~DefaultConditionFilter();
RC init(const ConDesc &left, const ConDesc &right, AttrType attr_type, CompOp comp_op);
RC init(Table &table, const Condition &condition);
RC init(Table &table, const ConditionSqlNode &condition);
virtual bool filter(const Record &rec) const;
......@@ -86,7 +86,7 @@ public:
virtual ~CompositeConditionFilter();
RC init(const ConditionFilter *filters[], int filter_num);
RC init(Table &table, const Condition *conditions, int condition_num);
RC init(Table &table, const ConditionSqlNode *conditions, int condition_num);
virtual bool filter(const Record &rec) const;
public:
......
......@@ -76,7 +76,7 @@ RC Db::init(const char *name, const char *dbpath)
return rc;
}
RC Db::create_table(const char *table_name, int attribute_count, const AttrInfo *attributes)
RC Db::create_table(const char *table_name, int attribute_count, const AttrInfoSqlNode *attributes)
{
RC rc = RC::SUCCESS;
// check table_name
......
......@@ -45,7 +45,7 @@ public:
*/
RC init(const char *name, const char *dbpath);
RC create_table(const char *table_name, int attribute_count, const AttrInfo *attributes);
RC create_table(const char *table_name, int attribute_count, const AttrInfoSqlNode *attributes);
Table *find_table(const char *table_name) const;
Table *find_table(int32_t table_id) const;
......
......@@ -159,7 +159,7 @@ RC DefaultHandler::execute(const char *sql)
}
RC DefaultHandler::create_table(
const char *dbname, const char *relation_name, int attribute_count, const AttrInfo *attributes)
const char *dbname, const char *relation_name, int attribute_count, const AttrInfoSqlNode *attributes)
{
Db *db = find_db(dbname);
if (db == nullptr) {
......
......@@ -80,7 +80,7 @@ public:
* @param attributes
* @return
*/
RC create_table(const char *dbname, const char *relation_name, int attribute_count, const AttrInfo *attributes);
RC create_table(const char *dbname, const char *relation_name, int attribute_count, const AttrInfoSqlNode *attributes);
/**
* 销毁名为relName的表以及在该表上建立的所有索引
......
......@@ -55,7 +55,7 @@ RC Table::create(int32_t table_id,
const char *name,
const char *base_dir,
int attribute_count,
const AttrInfo attributes[])
const AttrInfoSqlNode attributes[])
{
if (common::is_blank(name)) {
......
......@@ -52,7 +52,7 @@ public:
const char *name,
const char *base_dir,
int attribute_count,
const AttrInfo attributes[]);
const AttrInfoSqlNode attributes[]);
/**
* 打开一个表
......
......@@ -39,7 +39,7 @@ void TableMeta::swap(TableMeta &other) noexcept
std::swap(record_size_, other.record_size_);
}
RC TableMeta::init(int32_t table_id, const char *name, int field_num, const AttrInfo attributes[])
RC TableMeta::init(int32_t table_id, const char *name, int field_num, const AttrInfoSqlNode attributes[])
{
if (common::is_blank(name)) {
LOG_ERROR("Name cannot be empty");
......@@ -71,7 +71,7 @@ RC TableMeta::init(int32_t table_id, const char *name, int field_num, const Attr
}
for (int i = 0; i < field_num; i++) {
const AttrInfo &attr_info = attributes[i];
const AttrInfoSqlNode &attr_info = attributes[i];
rc = fields_[i + trx_field_num].init(attr_info.name.c_str(),
attr_info.type, field_offset, attr_info.length, true/*visible*/);
if (rc != RC::SUCCESS) {
......
......@@ -36,7 +36,7 @@ public:
void swap(TableMeta &other) noexcept;
RC init(int32_t table_id, const char *name, int field_num, const AttrInfo attributes[]);
RC init(int32_t table_id, const char *name, int field_num, const AttrInfoSqlNode attributes[]);
RC add_index(const IndexMeta &index);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册