[FEAT MERGE] implement values statement

Co-authored-by: wangt1xiuyi <13547954130@163.com>
This commit is contained in:
jingtaoye35
2023-08-30 10:44:18 +00:00
committed by ob-robot
parent 5a62e3cee9
commit 8015a958d0
59 changed files with 3135 additions and 536 deletions

View File

@ -68,10 +68,102 @@ public:
int64_t &no_param_sql_len,
ParamList *&param_list,
int64_t &param_num,
ObQuestionMarkCtx &ctx,
ObFastParserResult &fp_result,
int64_t &values_token_pos);
};
static const char INVALID_CHAR = -1;
struct ObRawSql {
explicit ObRawSql() :
raw_sql_(nullptr), raw_sql_len_(0),
cur_pos_(0), search_end_(false) {}
inline void init(const char *raw_sql, const int64_t len)
{
cur_pos_ = 0;
raw_sql_ = raw_sql;
raw_sql_len_ = len;
}
inline bool is_search_end()
{
return search_end_ || cur_pos_ > raw_sql_len_ - 1;
}
inline char peek()
{
if (cur_pos_ >= raw_sql_len_ - 1) {
return INVALID_CHAR;
}
return raw_sql_[cur_pos_ + 1];
}
inline char scan(const int64_t offset)
{
if (cur_pos_ + offset >= raw_sql_len_) {
search_end_ = true;
cur_pos_ = raw_sql_len_;
return INVALID_CHAR;
}
cur_pos_ += offset;
return raw_sql_[cur_pos_];
}
inline char scan() { return scan(1); }
inline char reverse_scan()
{
if (cur_pos_ <= 0 || cur_pos_ >= raw_sql_len_ + 1) {
search_end_ = true;
return INVALID_CHAR;
}
return raw_sql_[--cur_pos_];
}
inline char char_at(int64_t idx)
{
if (idx < 0 || idx >= raw_sql_len_) {
return INVALID_CHAR;
}
return raw_sql_[idx];
}
inline const char *ptr(const int64_t pos)
{
if (pos < 0 || pos >= raw_sql_len_) {
return nullptr;
}
return &(raw_sql_[pos]);
}
inline int64_t strncasecmp(int64_t pos, const char *str, const int64_t size)
{
// It is not necessary to check if str is nullptr
char ch = char_at(pos);
for (int64_t i = 0; i < size; i++) {
if (ch >= 'A' && ch <= 'Z') {
ch += 32;
}
if (ch != str[i]) {
return -1;
}
ch = char_at(++pos);
}
return 0;
}
inline int64_t strncasecmp(const char *str, const int64_t size)
{
return strncasecmp(cur_pos_, str, size);
}
// Access a character (no bounds check)
// char operator[] (const int64_t idx) const { return raw_sql_[idx]; }
// For debug
common::ObString to_string() const
{
if (OB_UNLIKELY(nullptr == raw_sql_ || 0 == raw_sql_len_)) {
return common::ObString(0, nullptr);
}
return common::ObString(raw_sql_len_, raw_sql_);
}
const char *raw_sql_;
int64_t raw_sql_len_;
int64_t cur_pos_;
bool search_end_;
};
class ObFastParserBase
{
public:
@ -145,87 +237,9 @@ protected:
// There are too many such branches, making our code look very ugly. therefore, we use a special
// value of -1. when the allowed length is exceeded, peek, scan, reverse_scan, char_at return -1
// this will not affect any correctness issues, and will make the code look better
static const char INVALID_CHAR = -1;
static const int64_t PARSER_NODE_SIZE = sizeof(ParseNode);
static const int64_t FIEXED_PARAM_NODE_SIZE = PARSER_NODE_SIZE + sizeof(ParamList);
struct ObRawSql {
explicit ObRawSql() :
raw_sql_(nullptr), raw_sql_len_(0),
cur_pos_(0), search_end_(false) {}
inline void init(const char *raw_sql, const int64_t len)
{
cur_pos_ = 0;
raw_sql_ = raw_sql;
raw_sql_len_ = len;
}
inline bool is_search_end()
{
return search_end_ || cur_pos_ > raw_sql_len_ - 1;
}
inline char peek()
{
if (cur_pos_ >= raw_sql_len_ - 1) {
return INVALID_CHAR;
}
return raw_sql_[cur_pos_ + 1];
}
inline char scan(const int64_t offset)
{
if (cur_pos_ + offset >= raw_sql_len_) {
search_end_ = true;
cur_pos_ = raw_sql_len_;
return INVALID_CHAR;
}
cur_pos_ += offset;
return raw_sql_[cur_pos_];
}
inline char scan() { return scan(1); }
inline char reverse_scan()
{
if (cur_pos_ <= 0 || cur_pos_ >= raw_sql_len_ + 1) {
search_end_ = true;
return INVALID_CHAR;
}
return raw_sql_[--cur_pos_];
}
inline char char_at(int64_t idx)
{
if (idx < 0 || idx >= raw_sql_len_) {
return INVALID_CHAR;
}
return raw_sql_[idx];
}
inline const char *ptr(const int64_t pos)
{
if (pos < 0 || pos >= raw_sql_len_) {
return nullptr;
}
return &(raw_sql_[pos]);
}
int64_t strncasecmp(int64_t pos, const char *str, const int64_t size);
inline int64_t strncasecmp(const char *str, const int64_t size)
{
return strncasecmp(cur_pos_, str, size);
}
// Access a character (no bounds check)
// char operator[] (const int64_t idx) const { return raw_sql_[idx]; }
// For debug
common::ObString to_string() const
{
if (OB_UNLIKELY(nullptr == raw_sql_ || 0 == raw_sql_len_)) {
return common::ObString(0, nullptr);
}
return common::ObString(raw_sql_len_, raw_sql_);
}
const char *raw_sql_;
int64_t raw_sql_len_;
int64_t cur_pos_;
bool search_end_;
};
protected:
/**
* Check whether it is a specify character and whether it is a multi byte specify
@ -572,7 +586,7 @@ protected:
int process_interval();
int process_insert_or_replace(const char *str, const int64_t size);
int process_values(const char *str);
virtual int process_values(const char *str) = 0;
int get_one_insert_row_str(ObRawSql &raw_sql,
ObString &str,
@ -640,7 +654,8 @@ public:
static_cast<ProcessIdfFunc>(&ObFastParserMysql::process_identifier));
}
~ObFastParserMysql() {}
virtual int process_values(const char *str) override;
ObIArray<ObValuesTokenPos> &get_values_tokens() { return values_tokens_; }
private:
ObSQLMode sql_mode_;
int parse_next_token();
@ -656,8 +671,8 @@ private:
int process_string(const char quote);
int process_zero_identifier();
int process_identifier_begin_with_n();
private:
ObSEArray<ObValuesTokenPos, 4> values_tokens_;
DISALLOW_COPY_AND_ASSIGN(ObFastParserMysql);
};
@ -675,7 +690,7 @@ public:
static_cast<ProcessIdfFunc>(&ObFastParserOracle::process_identifier));
}
~ObFastParserOracle() {}
virtual int process_values(const char *str) override;
private:
int parse_next_token();
int process_identifier(bool is_number_begin);