OmniSciDB  d2f719934e
 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 isCalciteDdl () 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_optimize = false
 
bool is_validate = false
 
std::string actual_query
 

Private Attributes

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
 
static const std::string explain_str = {"explain"}
 
static const std::string calcite_explain_str = {"explain calcite"}
 
static const std::string optimized_explain_str = {"explain optimized"}
 
static const std::string plan_explain_str = {"explain plan"}
 
static const std::string optimize_str = {"optimize"}
 
static const std::string validate_str = {"validate"}
 

Detailed Description

Definition at line 44 of file ParserWrapper.h.

Member Enumeration Documentation

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

Definition at line 47 of file ParserWrapper.h.

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

Definition at line 49 of file ParserWrapper.h.

49 { None, IR, OptimizedIR, Calcite, ExecutionPlan, Other };
Enumerator
Unknown 
Read 
Write 
SchemaRead 
SchemaWrite 

Definition at line 51 of file ParserWrapper.h.

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

Constructor & Destructor Documentation

ParserWrapper::ParserWrapper ( std::string  query_string)

Definition at line 67 of file ParserWrapper.cpp.

References g_enable_calcite_ddl_parser, g_enable_fsi, i, logger::IR, and update_dml_cmd.

67  {
69  if (boost::istarts_with(query_string, calcite_explain_str)) {
70  actual_query = boost::trim_copy(query_string.substr(calcite_explain_str.size()));
72  if (inner.is_ddl || inner.is_update_dml) {
74  return;
75  } else {
77  return;
78  }
79  }
80 
81  if (boost::istarts_with(query_string, optimized_explain_str)) {
82  actual_query = boost::trim_copy(query_string.substr(optimized_explain_str.size()));
84  if (inner.is_ddl || inner.is_update_dml) {
86  return;
87  } else {
89  return;
90  }
91  }
92 
93  if (boost::istarts_with(query_string, plan_explain_str)) {
94  actual_query = boost::trim_copy(query_string.substr(plan_explain_str.size()));
96  if (inner.is_ddl || inner.is_update_dml) {
98  return;
99  } else {
101  return;
102  }
103  }
104 
105  if (boost::istarts_with(query_string, explain_str)) {
106  actual_query = boost::trim_copy(query_string.substr(explain_str.size()));
108  if (inner.is_ddl || inner.is_update_dml) {
110  return;
111  } else {
113  return;
114  }
115  }
116 
118  for (std::string ddl : ddl_cmd) {
119  is_ddl = boost::istarts_with(query_string, ddl);
120  if (is_ddl) {
122  if (g_enable_fsi) {
123  std::string fsi_regex_pattern{
124  R"((CREATE|DROP|ALTER)\s+(SERVER|FOREIGN\s+TABLE).*)"};
125 
126  boost::regex fsi_regex{fsi_regex_pattern,
127  boost::regex::extended | boost::regex::icase};
128  boost::regex refresh_regex{R"(REFRESH\s+FOREIGN\s+TABLES.*)",
129  boost::regex::extended | boost::regex::icase};
130 
131  if (boost::regex_match(query_string, fsi_regex) ||
132  boost::regex_match(query_string, refresh_regex)) {
133  is_calcite_ddl_ = true;
134  is_legacy_ddl_ = false;
135  return;
136  }
137  }
138  if (ddl == "CREATE") {
139  boost::regex ctas_regex{
140  R"(CREATE\s+(TEMPORARY\s+|\s*)+TABLE.*(\"|\s)AS(\(|\s)+(SELECT|WITH).*)",
141  boost::regex::extended | boost::regex::icase};
142  if (boost::regex_match(query_string, ctas_regex)) {
143  is_ctas = true;
144  // why is TEMPORARY being processed in legacy still
145  boost::regex temp_regex{R"(\s+TEMPORARY\s+)",
146  boost::regex::extended | boost::regex::icase};
147  if (boost::regex_match(query_string, temp_regex)) {
148  is_calcite_ddl_ = false;
149  is_legacy_ddl_ = true;
150  }
151  } else {
152  boost::regex create_regex{
153  R"(CREATE\s+(DATABASE|DATAFRAME|(TEMPORARY\s+|\s*)+TABLE|ROLE|USER|VIEW).*)",
154  boost::regex::extended | boost::regex::icase};
156  boost::regex_match(query_string, create_regex)) {
157  is_calcite_ddl_ = true;
158  is_legacy_ddl_ = false;
159  return;
160  }
161  }
162  } else if (ddl == "COPY") {
163  is_copy = true;
164  is_calcite_ddl_ = true;
165  is_legacy_ddl_ = false;
166  // now check if it is COPY TO
167  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s+.*)",
168  boost::regex::extended | boost::regex::icase};
169  if (boost::regex_match(query_string, copy_to)) {
171  is_copy_to = true;
172  } else {
174  }
175  } else if (ddl == "SHOW") {
177  is_calcite_ddl_ = true;
178  is_legacy_ddl_ = false;
179  return;
180  } else if (ddl == "DROP") {
181  boost::regex drop_regex{R"(DROP\s+(TABLE|ROLE|VIEW|DATABASE|USER).*)",
182  boost::regex::extended | boost::regex::icase};
184  (boost::regex_match(query_string, drop_regex))) {
185  is_calcite_ddl_ = true;
186  is_legacy_ddl_ = false;
187  return;
188  }
189  } else if (ddl == "KILL") {
191  is_calcite_ddl_ = true;
192  is_legacy_ddl_ = false;
193  return;
194  } else if (ddl == "VALIDATE") {
196  is_calcite_ddl_ = true;
197  is_legacy_ddl_ = false;
198  // needs to execute in a different context from other DDL
199  is_validate = true;
200  return;
201  } else if (ddl == "RENAME") {
203  boost::regex rename_regex{R"(RENAME\s+TABLE.*)",
204  boost::regex::extended | boost::regex::icase};
206  boost::regex_match(query_string, rename_regex)) {
207  is_calcite_ddl_ = true;
208  is_legacy_ddl_ = false;
209  return;
210  }
211  } else if (ddl == "ALTER") {
212  boost::regex alter_regex{R"(ALTER\s+(TABLE|DATABASE|USER).*)",
213  boost::regex::extended | boost::regex::icase};
214  boost::regex alter_system_regex{R"(ALTER\s+(SYSTEM).*)",
215  boost::regex::extended | boost::regex::icase};
216 
218  boost::regex_match(query_string, alter_regex)) {
220  is_calcite_ddl_ = true;
221  is_legacy_ddl_ = false;
222  return;
223  } else {
224  if (boost::regex_match(query_string, alter_system_regex)) {
226  is_calcite_ddl_ = true;
227  is_legacy_ddl_ = false;
228  return;
229  }
230  }
231 
232  } else if (ddl == "GRANT") {
233  boost::regex grant_regex{R"(GRANT.*)",
234  boost::regex::extended | boost::regex::icase};
236  boost::regex_match(query_string, grant_regex)) {
237  is_calcite_ddl_ = true;
238  is_legacy_ddl_ = false;
239  return;
240  }
241  } else if (ddl == "REVOKE") {
242  boost::regex revoke_regex{R"(REVOKE.*)",
243  boost::regex::extended | boost::regex::icase};
245  boost::regex_match(query_string, revoke_regex)) {
246  is_calcite_ddl_ = true;
247  is_legacy_ddl_ = false;
248  return;
249  }
250  } else if (ddl == "REASSIGN") {
252  is_calcite_ddl_ = true;
253  is_legacy_ddl_ = false;
254  return;
255  } else if (ddl == "ARCHIVE" || ddl == "DUMP" || ddl == "OPTIMIZE" ||
256  ddl == "RESTORE" || ddl == "TRUNCATE") {
257  if (ddl == "ARCHIVE" || ddl == "DUMP") {
259  } else {
261  }
262  is_calcite_ddl_ = true;
263  is_legacy_ddl_ = false;
264  return;
265  }
266 
267  // ctas may look like ddl, but is neither legacy_dll nor calcite_ddl
268  if (!is_ctas) {
270  }
271  return;
272  }
273  }
274 
275  for (int i = 0; i < update_dml_cmd.size(); i++) {
276  is_update_dml = boost::istarts_with(query_string, ParserWrapper::update_dml_cmd[i]);
277  if (is_update_dml) {
279  dml_type_ = (DMLType)(i);
280  break;
281  }
282  }
283 
284  if (dml_type_ == DMLType::Insert) {
285  boost::regex itas_regex{R"(INSERT\s+INTO\s+.*(\s+|\(|\")SELECT(\s|\(|\").*)",
286  boost::regex::extended | boost::regex::icase};
287  if (boost::regex_match(query_string, itas_regex)) {
288  is_itas = true;
289  return;
290  }
291  }
292 }
QueryType query_type_
static const std::string optimized_explain_str
static const std::string calcite_explain_str
std::string actual_query
Definition: ParserWrapper.h:71
DMLType dml_type_
static const std::vector< std::string > ddl_cmd
bool g_enable_calcite_ddl_parser
Definition: ParserNode.cpp:76
static const std::string explain_str
static const std::vector< std::string > update_dml_cmd
static const std::string plan_explain_str
ExplainType explain_type_
bool g_enable_fsi
Definition: Catalog.cpp:94
ParserWrapper::~ParserWrapper ( )
virtual

Definition at line 294 of file ParserWrapper.cpp.

294 {}

Member Function Documentation

DMLType ParserWrapper::getDMLType ( ) const
inline

Definition at line 73 of file ParserWrapper.h.

References dml_type_.

Referenced by isCalcitePermissableDml().

73 { return dml_type_; }
DMLType dml_type_

+ Here is the caller graph for this function:

ExplainType ParserWrapper::getExplainType ( ) const
inline

Definition at line 77 of file ParserWrapper.h.

References explain_type_.

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

Definition at line 79 of file ParserWrapper.h.

References query_type_.

79 { return query_type_; }
QueryType query_type_
bool ParserWrapper::isCalciteDdl ( ) const
inline

Definition at line 129 of file ParserWrapper.h.

References is_calcite_ddl_.

129 { return is_calcite_ddl_; }
bool ParserWrapper::isCalciteExplain ( ) const
inline

Definition at line 85 of file ParserWrapper.h.

References Calcite, and explain_type_.

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

Definition at line 99 of file ParserWrapper.h.

References explain_type_, is_calcite_ddl_, is_legacy_ddl_, is_optimize, is_validate, isCalcitePermissableDdl(), isCalcitePermissableDml(), and Other.

99  {
100  if (is_calcite_ddl_) {
101  return isCalcitePermissableDdl(read_only_mode);
102  }
103  return (!is_legacy_ddl_ && !is_optimize && !is_validate &&
104  isCalcitePermissableDml(read_only_mode) &&
106  }
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 121 of file ParserWrapper.h.

References query_type_, SchemaWrite, and Write.

Referenced by isCalcitePathPermissable().

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

+ Here is the caller graph for this function:

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

Definition at line 110 of file ParserWrapper.h.

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

Referenced by isCalcitePathPermissable().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ParserWrapper::isIRExplain ( ) const
inline
bool ParserWrapper::isOtherExplain ( ) const
inline

Definition at line 108 of file ParserWrapper.h.

References explain_type_, and Other.

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

Definition at line 89 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

Definition at line 71 of file ParserWrapper.h.

const std::string ParserWrapper::calcite_explain_str = {"explain calcite"}
staticprivate

Definition at line 139 of file ParserWrapper.h.

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

DMLType ParserWrapper::dml_type_ = DMLType::NotDML
private

Definition at line 132 of file ParserWrapper.h.

Referenced by getDMLType(), and isUpdateDelete().

const std::string ParserWrapper::explain_str = {"explain"}
staticprivate

Definition at line 138 of file ParserWrapper.h.

bool ParserWrapper::is_calcite_ddl_ = false
private

Definition at line 146 of file ParserWrapper.h.

Referenced by isCalciteDdl(), and isCalcitePathPermissable().

bool ParserWrapper::is_copy = false

Definition at line 67 of file ParserWrapper.h.

bool ParserWrapper::is_copy_to = false

Definition at line 68 of file ParserWrapper.h.

bool ParserWrapper::is_ctas = false

Definition at line 65 of file ParserWrapper.h.

Referenced by isCalcitePermissableDml().

bool ParserWrapper::is_ddl = false

Definition at line 61 of file ParserWrapper.h.

bool ParserWrapper::is_itas = false

Definition at line 66 of file ParserWrapper.h.

Referenced by isCalcitePermissableDml().

bool ParserWrapper::is_legacy_ddl_ = false
private

Definition at line 145 of file ParserWrapper.h.

Referenced by isCalcitePathPermissable().

bool ParserWrapper::is_optimize = false

Definition at line 69 of file ParserWrapper.h.

Referenced by isCalcitePathPermissable().

bool ParserWrapper::is_update_dml = false

Definition at line 64 of file ParserWrapper.h.

Referenced by isCalcitePermissableDml().

bool ParserWrapper::is_validate = false

Definition at line 70 of file ParserWrapper.h.

Referenced by isCalcitePathPermissable().

const std::string ParserWrapper::optimize_str = {"optimize"}
staticprivate

Definition at line 142 of file ParserWrapper.h.

const std::string ParserWrapper::optimized_explain_str = {"explain optimized"}
staticprivate

Definition at line 140 of file ParserWrapper.h.

const std::string ParserWrapper::plan_explain_str = {"explain plan"}
staticprivate

Definition at line 141 of file ParserWrapper.h.

QueryType ParserWrapper::query_type_ = QueryType::Unknown
private

Definition at line 134 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 137 of file ParserWrapper.h.

Referenced by ParserWrapper().

const std::string ParserWrapper::validate_str = {"validate"}
staticprivate

Definition at line 143 of file ParserWrapper.h.


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