OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParserWrapper Class Reference

#include <ParserWrapper.h>

Public Types

enum  DMLType : int { DMLType::Insert = 0, DMLType::Delete, DMLType::Update, DMLType::NotDML }
 
enum  QueryType {
  QueryType::Unknown, QueryType::Read, QueryType::Write, QueryType::SchemaRead,
  QueryType::SchemaWrite
}
 

Public Member Functions

 ParserWrapper (std::string query_string)
 
std::string process (std::string user, std::string passwd, std::string catalog, std::string sql_string, const bool legacy_syntax)
 
virtual ~ParserWrapper ()
 
DMLType getDMLType () const
 
QueryType getQueryType () const
 
bool isUpdateDelete () const
 

Public Attributes

bool is_ddl = false
 
bool is_update_dml = false
 
bool is_ctas = false
 
bool is_itas = false
 
bool is_copy = false
 
bool is_copy_to = false
 
bool is_validate = false
 
bool is_other_explain = false
 
bool is_refresh = false
 

Private Attributes

DMLType dml_type_ = DMLType::NotDML
 
QueryType query_type_ = QueryType::Unknown
 

Static Private Attributes

static const std::vector
< std::string > 
ddl_cmd
 
static const std::vector
< std::string > 
update_dml_cmd
 

Detailed Description

Definition at line 91 of file ParserWrapper.h.

Member Enumeration Documentation

enum ParserWrapper::DMLType : int
strong
Enumerator
Insert 
Delete 
Update 
NotDML 

Definition at line 94 of file ParserWrapper.h.

94 : int { Insert = 0, Delete, Update, NotDML };
Enumerator
Unknown 
Read 
Write 
SchemaRead 
SchemaWrite 

Definition at line 96 of file ParserWrapper.h.

96 { Unknown, Read, Write, SchemaRead, SchemaWrite };

Constructor & Destructor Documentation

ParserWrapper::ParserWrapper ( std::string  query_string)

Definition at line 104 of file ParserWrapper.cpp.

References ExplainInfo::isOtherExplain(), update_dml_cmd, and anonymous_namespace{ParserWrapper.cpp}::validate_no_leading_comments().

104  {
105  validate_no_leading_comments(query_string);
106 
107  is_other_explain = ExplainInfo(query_string).isOtherExplain();
108 
110  for (std::string ddl : ddl_cmd) {
111  if (boost::istarts_with(query_string, ddl)) {
113  is_ddl = true;
114 
115  if (ddl == "CREATE") {
116  boost::regex ctas_regex{
117  R"(CREATE\s+(TEMPORARY\s+|\s*)+TABLE.*(\"|\s)AS(\(|\s)+(SELECT|WITH).*)",
118  boost::regex::extended | boost::regex::icase};
119  if (boost::regex_match(query_string, ctas_regex)) {
120  is_ctas = true;
121  }
122  } else if (ddl == "COPY") {
123  is_copy = true;
124  // now check if it is COPY TO
125  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s+.*)",
126  boost::regex::extended | boost::regex::icase};
127  if (boost::regex_match(query_string, copy_to)) {
129  is_copy_to = true;
130  } else {
132  }
133  } else if (ddl == "SHOW") {
135  } else if (ddl == "KILL") {
137  } else if (ddl == "VALIDATE") {
139  // needs to execute in a different context from other DDL
140  is_validate = true;
141  } else if (ddl == "ALTER") {
142  boost::regex alter_system_regex{R"(ALTER\s+(SYSTEM|SESSION).*)",
143  boost::regex::extended | boost::regex::icase};
144  if (boost::regex_match(query_string, alter_system_regex)) {
146  }
147  } else if (ddl == "ARCHIVE" || ddl == "DUMP") {
149  } else if (ddl == "REFRESH") {
150  is_refresh = true;
151  }
152  return;
153  }
154  }
155 
156  for (int i = 0; i < update_dml_cmd.size(); i++) {
157  is_update_dml = boost::istarts_with(query_string, ParserWrapper::update_dml_cmd[i]);
158  if (is_update_dml) {
160  dml_type_ = (DMLType)(i);
161  break;
162  }
163  }
164 
165  if (dml_type_ == DMLType::Insert) {
166  boost::regex itas_regex{R"(INSERT\s+INTO\s+.*(\s+|\(|\")SELECT(\s|\(|\").*)",
167  boost::regex::extended | boost::regex::icase};
168  if (boost::regex_match(query_string, itas_regex)) {
169  is_itas = true;
170  return;
171  }
172  }
173 }
QueryType query_type_
void validate_no_leading_comments(const std::string &query_str)
DMLType dml_type_
bool isOtherExplain() const
Definition: ParserWrapper.h:79
static const std::vector< std::string > ddl_cmd
static const std::vector< std::string > update_dml_cmd

+ Here is the call graph for this function:

ParserWrapper::~ParserWrapper ( )
virtual

Definition at line 175 of file ParserWrapper.cpp.

175 {}

Member Function Documentation

DMLType ParserWrapper::getDMLType ( ) const
inline

Definition at line 116 of file ParserWrapper.h.

References dml_type_.

116 { return dml_type_; }
DMLType dml_type_
QueryType ParserWrapper::getQueryType ( ) const
inline

Definition at line 118 of file ParserWrapper.h.

References query_type_.

118 { return query_type_; }
QueryType query_type_
bool ParserWrapper::isUpdateDelete ( ) const
inline

Definition at line 120 of file ParserWrapper.h.

References Delete, dml_type_, and Update.

std::string ParserWrapper::process ( std::string  user,
std::string  passwd,
std::string  catalog,
std::string  sql_string,
const bool  legacy_syntax 
)

Member Data Documentation

const std::vector< std::string > ParserWrapper::ddl_cmd
staticprivate
Initial value:
= {
"ARCHIVE", "ALTER", "COPY", "CREATE", "DROP", "DUMP", "EVALUATE",
"GRANT", "KILL", "OPTIMIZE", "REFRESH", "RENAME", "RESTORE", "REVOKE",
"SHOW", "TRUNCATE", "REASSIGN", "VALIDATE", "CLEAR", "PAUSE", "RESUME"}

Definition at line 128 of file ParserWrapper.h.

DMLType ParserWrapper::dml_type_ = DMLType::NotDML
private

Definition at line 125 of file ParserWrapper.h.

Referenced by getDMLType(), and isUpdateDelete().

bool ParserWrapper::is_copy = false

Definition at line 110 of file ParserWrapper.h.

bool ParserWrapper::is_copy_to = false

Definition at line 111 of file ParserWrapper.h.

bool ParserWrapper::is_ctas = false

Definition at line 108 of file ParserWrapper.h.

bool ParserWrapper::is_ddl = false

Definition at line 106 of file ParserWrapper.h.

bool ParserWrapper::is_itas = false

Definition at line 109 of file ParserWrapper.h.

bool ParserWrapper::is_other_explain = false

Definition at line 113 of file ParserWrapper.h.

bool ParserWrapper::is_refresh = false

Definition at line 114 of file ParserWrapper.h.

bool ParserWrapper::is_update_dml = false

Definition at line 107 of file ParserWrapper.h.

bool ParserWrapper::is_validate = false

Definition at line 112 of file ParserWrapper.h.

QueryType ParserWrapper::query_type_ = QueryType::Unknown
private

Definition at line 126 of file ParserWrapper.h.

Referenced by getQueryType().

const std::vector< std::string > ParserWrapper::update_dml_cmd
staticprivate
Initial value:
= {"INSERT",
"DELETE",
"UPDATE"}

Definition at line 129 of file ParserWrapper.h.

Referenced by ParserWrapper().


The documentation for this class was generated from the following files: