OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 65 of file ParserWrapper.cpp.

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

65  {
67  if (boost::istarts_with(query_string, calcite_explain_str)) {
68  actual_query = boost::trim_copy(query_string.substr(calcite_explain_str.size()));
70  if (inner.is_ddl || inner.is_update_dml) {
72  return;
73  } else {
75  return;
76  }
77  }
78 
79  if (boost::istarts_with(query_string, optimized_explain_str)) {
80  actual_query = boost::trim_copy(query_string.substr(optimized_explain_str.size()));
82  if (inner.is_ddl || inner.is_update_dml) {
84  return;
85  } else {
87  return;
88  }
89  }
90 
91  if (boost::istarts_with(query_string, plan_explain_str)) {
92  actual_query = boost::trim_copy(query_string.substr(plan_explain_str.size()));
94  if (inner.is_ddl || inner.is_update_dml) {
96  return;
97  } else {
99  return;
100  }
101  }
102 
103  if (boost::istarts_with(query_string, explain_str)) {
104  actual_query = boost::trim_copy(query_string.substr(explain_str.size()));
106  if (inner.is_ddl || inner.is_update_dml) {
108  return;
109  } else {
111  return;
112  }
113  }
114 
115  if (boost::istarts_with(query_string, optimize_str)) {
117  is_optimize = true;
118  return;
119  }
120 
121  if (boost::istarts_with(query_string, validate_str)) {
122  is_validate = true;
123  return;
124  }
125 
127  for (std::string ddl : ddl_cmd) {
128  is_ddl = boost::istarts_with(query_string, ddl);
129  if (is_ddl) {
131  if (g_enable_fsi) {
132  std::string fsi_regex_pattern{
133  R"((CREATE|DROP|ALTER)\s+(SERVER|FOREIGN\s+TABLE).*)"};
134 
135  boost::regex fsi_regex{fsi_regex_pattern,
136  boost::regex::extended | boost::regex::icase};
137  boost::regex refresh_regex{R"(REFRESH\s+FOREIGN\s+TABLES.*)",
138  boost::regex::extended | boost::regex::icase};
139 
140  if (boost::regex_match(query_string, fsi_regex) ||
141  boost::regex_match(query_string, refresh_regex)) {
142  is_calcite_ddl_ = true;
143  is_legacy_ddl_ = false;
144  return;
145  }
146  }
147  if (ddl == "CREATE") {
148  boost::regex ctas_regex{R"(CREATE\s+TABLE.*(\"|\s)AS(\(|\s)+(SELECT|WITH).*)",
149  boost::regex::extended | boost::regex::icase};
150  if (boost::regex_match(query_string, ctas_regex)) {
151  is_ctas = true;
152  } else {
153  boost::regex create_table_regex{R"(CREATE\s+TABLE.*)",
154  boost::regex::extended | boost::regex::icase};
155  boost::regex create_view_regex{R"(CREATE\s+VIEW.*)",
156  boost::regex::extended | boost::regex::icase};
158  (boost::regex_match(query_string, create_table_regex) ||
159  boost::regex_match(query_string, create_view_regex))) {
160  is_calcite_ddl_ = true;
161  is_legacy_ddl_ = false;
162  return;
163  }
164  }
165  } else if (ddl == "COPY") {
166  is_copy = true;
167  // now check if it is COPY TO
168  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s+.*)",
169  boost::regex::extended | boost::regex::icase};
170  if (boost::regex_match(query_string, copy_to)) {
172  is_copy_to = true;
173  } else {
175  }
176  } else if (ddl == "SHOW") {
178  boost::regex show_create_table_regex{
179  R"(SHOW\s+CREATE\s+TABLE\s+.*)",
180  boost::regex::extended | boost::regex::icase};
181  if (!boost::regex_match(query_string, show_create_table_regex)) {
182  is_calcite_ddl_ = true;
183  is_legacy_ddl_ = false;
184  return;
185  }
186  } else if (ddl == "DROP") {
187  boost::regex drop_table_regex{R"(DROP\s+TABLE.*)",
188  boost::regex::extended | boost::regex::icase};
189  boost::regex drop_view_regex{R"(DROP\s+VIEW.*)",
190  boost::regex::extended | boost::regex::icase};
192  (boost::regex_match(query_string, drop_table_regex) ||
193  boost::regex_match(query_string, drop_view_regex))) {
194  is_calcite_ddl_ = true;
195  is_legacy_ddl_ = false;
196  return;
197  }
198  } else if (ddl == "KILL") {
200  is_calcite_ddl_ = true;
201  is_legacy_ddl_ = false;
202  return;
203  } else if (ddl == "RENAME") {
205  is_calcite_ddl_ = true;
206  is_legacy_ddl_ = false;
207  return;
208  } else if (ddl == "ALTER") {
210  boost::regex alter_table_regex{R"(ALTER\s+TABLE.*)",
211  boost::regex::extended | boost::regex::icase};
213  boost::regex_match(query_string, alter_table_regex)) {
214  is_calcite_ddl_ = true;
215  is_legacy_ddl_ = false;
216  return;
217  }
218  }
220  return;
221  }
222  }
223 
224  for (int i = 0; i < update_dml_cmd.size(); i++) {
225  is_update_dml = boost::istarts_with(query_string, ParserWrapper::update_dml_cmd[i]);
226  if (is_update_dml) {
228  dml_type_ = (DMLType)(i);
229  break;
230  }
231  }
232 
233  if (dml_type_ == DMLType::Insert) {
234  boost::regex itas_regex{R"(INSERT\s+INTO\s+.*(\s+|\(|\")SELECT(\s|\(|\").*)",
235  boost::regex::extended | boost::regex::icase};
236  if (boost::regex_match(query_string, itas_regex)) {
237  is_itas = true;
238  return;
239  }
240  }
241 }
QueryType query_type_
static const std::string optimize_str
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:74
static const std::string validate_str
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:92
ParserWrapper::~ParserWrapper ( )
virtual

Definition at line 243 of file ParserWrapper.cpp.

243 {}

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_itas, is_update_dml, and Update.

Referenced by isCalcitePathPermissable().

110  {
111  if (is_itas) {
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",
"GRANT",
"CREATE",
"DROP",
"DUMP",
"OPTIMIZE",
"REFRESH",
"RENAME",
"RESTORE",
"REVOKE",
"SHOW",
"TRUNCATE",
"KILL"}

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.

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: