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

#include <ParserWrapper.h>

+ Collaboration diagram for ParserWrapper:

Public Types

enum  DMLType : int {
  DMLType::Insert = 0, DMLType::Delete, DMLType::Update, DMLType::Upsert,
  DMLType::NotDML
}
 
enum  ExplainType {
  ExplainType::None, ExplainType::IR, ExplainType::OptimizedIR, ExplainType::Calcite,
  ExplainType::ExecutionPlan, ExplainType::Other
}
 
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
 
ExplainInfo getExplainInfo () const
 
ExplainType getExplainType () const
 
QueryType getQueryType () const
 
bool isUpdateDelete () const
 
bool isCalciteExplain () const
 
bool isPlanExplain () const
 
bool isSelectExplain () const
 
bool isIRExplain () const
 
bool isCalcitePathPermissable (bool read_only_mode=false)
 
bool isOtherExplain () const
 
bool isCalcitePermissableDml (bool read_only_mode=false)
 
bool isCalcitePermissableDdl (bool read_only_mode)
 
bool isDdl () const
 
std::string ActualQuery ()
 

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
 

Private Member Functions

void initExplainType (std::string query_string)
 

Private Attributes

std::string actual_query_
 
DMLType dml_type_ = DMLType::NotDML
 
ExplainType explain_type_ = ExplainType::None
 
QueryType query_type_ = QueryType::Unknown
 
bool is_legacy_ddl_ = false
 
bool is_calcite_ddl_ = false
 

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 45 of file ParserWrapper.h.

Member Enumeration Documentation

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

Definition at line 48 of file ParserWrapper.h.

48 : int { Insert = 0, Delete, Update, Upsert, NotDML };
Enumerator
None 
IR 
OptimizedIR 
Calcite 
ExecutionPlan 
Other 

Definition at line 50 of file ParserWrapper.h.

Enumerator
Unknown 
Read 
Write 
SchemaRead 
SchemaWrite 

Definition at line 52 of file ParserWrapper.h.

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

Constructor & Destructor Documentation

ParserWrapper::ParserWrapper ( std::string  query_string)

Definition at line 76 of file ParserWrapper.cpp.

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

76  {
77  validate_no_leading_comments(query_string);
78 
79  // init explain_type_ and actual_info_
80  initExplainType(query_string);
81 
83  for (std::string ddl : ddl_cmd) {
84  if (boost::istarts_with(query_string, ddl)) {
86  is_ddl_ = true;
87 
88  if (ddl == "CREATE") {
89  boost::regex ctas_regex{
90  R"(CREATE\s+(TEMPORARY\s+|\s*)+TABLE.*(\"|\s)AS(\(|\s)+(SELECT|WITH).*)",
91  boost::regex::extended | boost::regex::icase};
92  if (boost::regex_match(query_string, ctas_regex)) {
93  is_ctas = true;
94  }
95  } else if (ddl == "COPY") {
96  is_copy = true;
97  // now check if it is COPY TO
98  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s+.*)",
99  boost::regex::extended | boost::regex::icase};
100  if (boost::regex_match(query_string, copy_to)) {
102  is_copy_to = true;
103  } else {
105  }
106  } else if (ddl == "SHOW") {
108 
109  } else if (ddl == "KILL") {
111  } else if (ddl == "VALIDATE") {
113  // needs to execute in a different context from other DDL
114  is_validate = true;
115  } else if (ddl == "ALTER") {
116  boost::regex alter_system_regex{R"(ALTER\s+(SYSTEM).*)",
117  boost::regex::extended | boost::regex::icase};
118  if (boost::regex_match(query_string, alter_system_regex)) {
120  }
121  } else if (ddl == "ARCHIVE" || ddl == "DUMP") {
123  }
124  return;
125  }
126  }
127 
128  for (int i = 0; i < update_dml_cmd.size(); i++) {
129  is_update_dml = boost::istarts_with(query_string, ParserWrapper::update_dml_cmd[i]);
130  if (is_update_dml) {
132  dml_type_ = (DMLType)(i);
133  break;
134  }
135  }
136 
137  if (dml_type_ == DMLType::Insert) {
138  boost::regex itas_regex{R"(INSERT\s+INTO\s+.*(\s+|\(|\")SELECT(\s|\(|\").*)",
139  boost::regex::extended | boost::regex::icase};
140  if (boost::regex_match(query_string, itas_regex)) {
141  is_itas = true;
142  return;
143  }
144  }
145 }
QueryType query_type_
void validate_no_leading_comments(const std::string &query_str)
DMLType dml_type_
void initExplainType(std::string query_string)
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 147 of file ParserWrapper.cpp.

147 {}

Member Function Documentation

std::string ParserWrapper::ActualQuery ( )
inline

Definition at line 130 of file ParserWrapper.h.

References actual_query_.

130 { return actual_query_; }
std::string actual_query_
DMLType ParserWrapper::getDMLType ( ) const
inline

Definition at line 72 of file ParserWrapper.h.

References dml_type_.

Referenced by isCalcitePermissableDml().

72 { return dml_type_; }
DMLType dml_type_

+ Here is the caller graph for this function:

ExplainType ParserWrapper::getExplainType ( ) const
inline

Definition at line 76 of file ParserWrapper.h.

References explain_type_.

76 { return explain_type_; }
ExplainType explain_type_
QueryType ParserWrapper::getQueryType ( ) const
inline

Definition at line 78 of file ParserWrapper.h.

References query_type_.

78 { return query_type_; }
QueryType query_type_
void ParserWrapper::initExplainType ( std::string  query_string)
private

Definition at line 149 of file ParserWrapper.cpp.

References anonymous_namespace{ParserWrapper.cpp}::calcite_explain_str, anonymous_namespace{ParserWrapper.cpp}::explain_str, logger::IR, None, anonymous_namespace{ParserWrapper.cpp}::optimized_explain_str, and anonymous_namespace{ParserWrapper.cpp}::plan_explain_str.

149  {
150  // sets explain_type_ and caches a trimmed actual_query_
152 
153  if (boost::istarts_with(query_string, calcite_explain_str)) {
154  actual_query_ = boost::trim_copy(query_string.substr(calcite_explain_str.size()));
156  if (inner.isDdl() || inner.is_update_dml) {
158  } else {
160  }
161 
162  } else if (boost::istarts_with(query_string, optimized_explain_str)) {
163  actual_query_ = boost::trim_copy(query_string.substr(optimized_explain_str.size()));
165  if (inner.isDdl() || inner.is_update_dml) {
167  } else {
169  }
170 
171  } else if (boost::istarts_with(query_string, plan_explain_str)) {
172  actual_query_ = boost::trim_copy(query_string.substr(plan_explain_str.size()));
174  if (inner.isDdl() || inner.is_update_dml) {
176  } else {
178  }
179 
180  } else if (boost::istarts_with(query_string, explain_str)) {
181  actual_query_ = boost::trim_copy(query_string.substr(explain_str.size()));
183  if (inner.isDdl() || inner.is_update_dml) {
185  } else {
187  }
188  }
189 }
std::string actual_query_
ExplainType explain_type_
bool ParserWrapper::isCalciteExplain ( ) const
inline

Definition at line 84 of file ParserWrapper.h.

References Calcite, and explain_type_.

bool ParserWrapper::isCalcitePathPermissable ( bool  read_only_mode = false)
inline

Definition at line 98 of file ParserWrapper.h.

References explain_type_, is_ddl_, is_validate, isCalcitePermissableDdl(), isCalcitePermissableDml(), and Other.

98  {
99  if (is_ddl_) {
100  return isCalcitePermissableDdl(read_only_mode);
101  }
102  return (!is_validate && isCalcitePermissableDml(read_only_mode) &&
104  }
bool isCalcitePermissableDml(bool read_only_mode=false)
ExplainType explain_type_
bool isCalcitePermissableDdl(bool read_only_mode)

+ Here is the call graph for this function:

bool ParserWrapper::isCalcitePermissableDdl ( bool  read_only_mode)
inline

Definition at line 120 of file ParserWrapper.h.

References query_type_, SchemaWrite, and Write.

Referenced by isCalcitePathPermissable().

120  {
121  if (read_only_mode) {
122  // If we're read-only, no Write/SchemaWrite DDL is permissable
124  }
125  return true;
126  }
QueryType query_type_

+ Here is the caller graph for this function:

bool ParserWrapper::isCalcitePermissableDml ( bool  read_only_mode = false)
inline

Definition at line 108 of file ParserWrapper.h.

References Delete, getDMLType(), Insert, is_ctas, is_itas, is_update_dml, and Update.

Referenced by isCalcitePathPermissable().

108  {
109  if (is_itas || is_ctas) {
110  return !read_only_mode;
111  }
112  if (read_only_mode) {
113  return !is_update_dml; // If we're read-only, no update/delete DML is permissable
114  }
118  }
DMLType getDMLType() const
Definition: ParserWrapper.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ParserWrapper::isDdl ( ) const
inline

Definition at line 128 of file ParserWrapper.h.

References is_ddl_.

128 { return is_ddl_; }
bool ParserWrapper::isIRExplain ( ) const
inline
bool ParserWrapper::isOtherExplain ( ) const
inline

Definition at line 106 of file ParserWrapper.h.

References explain_type_, and Other.

bool ParserWrapper::isPlanExplain ( ) const
inline
bool ParserWrapper::isSelectExplain ( ) const
inline

Definition at line 88 of file ParserWrapper.h.

References Calcite, ExecutionPlan, explain_type_, IR, and OptimizedIR.

Referenced by DBHandler::parse_to_ra().

+ Here is the caller graph for this function:

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

Member Data Documentation

std::string ParserWrapper::actual_query_
private

Definition at line 134 of file ParserWrapper.h.

Referenced by ActualQuery().

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

Definition at line 140 of file ParserWrapper.h.

DMLType ParserWrapper::dml_type_ = DMLType::NotDML
private

Definition at line 136 of file ParserWrapper.h.

Referenced by getDMLType(), and isUpdateDelete().

bool ParserWrapper::is_calcite_ddl_ = false
private

Definition at line 144 of file ParserWrapper.h.

bool ParserWrapper::is_copy = false

Definition at line 68 of file ParserWrapper.h.

bool ParserWrapper::is_copy_to = false

Definition at line 69 of file ParserWrapper.h.

bool ParserWrapper::is_ctas = false

Definition at line 66 of file ParserWrapper.h.

Referenced by isCalcitePermissableDml().

bool ParserWrapper::is_ddl_ = false

Definition at line 62 of file ParserWrapper.h.

Referenced by isCalcitePathPermissable(), and isDdl().

bool ParserWrapper::is_itas = false

Definition at line 67 of file ParserWrapper.h.

Referenced by isCalcitePermissableDml().

bool ParserWrapper::is_legacy_ddl_ = false
private

Definition at line 143 of file ParserWrapper.h.

bool ParserWrapper::is_update_dml = false

Definition at line 65 of file ParserWrapper.h.

Referenced by isCalcitePermissableDml().

bool ParserWrapper::is_validate = false

Definition at line 70 of file ParserWrapper.h.

Referenced by isCalcitePathPermissable().

QueryType ParserWrapper::query_type_ = QueryType::Unknown
private

Definition at line 138 of file ParserWrapper.h.

Referenced by getQueryType(), and isCalcitePermissableDdl().

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

Definition at line 141 of file ParserWrapper.h.

Referenced by ParserWrapper().


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