OmniSciDB  94e8789169
 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)
 
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 64 of file ParserWrapper.cpp.

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

64  {
66  if (boost::istarts_with(query_string, calcite_explain_str)) {
67  actual_query = boost::trim_copy(query_string.substr(calcite_explain_str.size()));
69  if (inner.is_ddl || inner.is_update_dml) {
71  return;
72  } else {
74  return;
75  }
76  }
77 
78  if (boost::istarts_with(query_string, optimized_explain_str)) {
79  actual_query = boost::trim_copy(query_string.substr(optimized_explain_str.size()));
81  if (inner.is_ddl || inner.is_update_dml) {
83  return;
84  } else {
86  return;
87  }
88  }
89 
90  if (boost::istarts_with(query_string, plan_explain_str)) {
91  actual_query = boost::trim_copy(query_string.substr(plan_explain_str.size()));
93  if (inner.is_ddl || inner.is_update_dml) {
95  return;
96  } else {
98  return;
99  }
100  }
101 
102  if (boost::istarts_with(query_string, explain_str)) {
103  actual_query = boost::trim_copy(query_string.substr(explain_str.size()));
105  if (inner.is_ddl || inner.is_update_dml) {
107  return;
108  } else {
110  return;
111  }
112  }
113 
114  if (boost::istarts_with(query_string, optimize_str)) {
116  is_optimize = true;
117  return;
118  }
119 
120  if (boost::istarts_with(query_string, validate_str)) {
121  is_validate = true;
122  return;
123  }
125  for (std::string ddl : ddl_cmd) {
126  is_ddl = boost::istarts_with(query_string, ddl);
127  if (is_ddl) {
129  if (g_enable_fsi) {
130  std::string fsi_regex_pattern{
131  R"((CREATE|DROP|ALTER)\s+(SERVER|FOREIGN\s+TABLE).*)"};
132 
133  boost::regex fsi_regex{fsi_regex_pattern,
134  boost::regex::extended | boost::regex::icase};
135  boost::regex refresh_regex{R"(REFRESH\s+FOREIGN\s+TABLES.*)",
136  boost::regex::extended | boost::regex::icase};
137 
138  if (boost::regex_match(query_string, fsi_regex) ||
139  boost::regex_match(query_string, refresh_regex)) {
140  is_calcite_ddl_ = true;
141  is_legacy_ddl_ = false;
142  return;
143  }
144  }
145  if (ddl == "CREATE") {
146  boost::regex ctas_regex{R"(CREATE\s+TABLE.*(\"|\s)AS(\(|\s)+(SELECT|WITH).*)",
147  boost::regex::extended | boost::regex::icase};
148  if (boost::regex_match(query_string, ctas_regex)) {
149  is_ctas = true;
150  } else {
151  boost::regex create_table_regex{R"(CREATE\s+TABLE.*)",
152  boost::regex::extended | boost::regex::icase};
153  boost::regex create_view_regex{R"(CREATE\s+VIEW.*)",
154  boost::regex::extended | boost::regex::icase};
156  (boost::regex_match(query_string, create_table_regex) ||
157  boost::regex_match(query_string, create_view_regex))) {
158  is_calcite_ddl_ = true;
159  is_legacy_ddl_ = false;
160  return;
161  }
162  }
163  } else if (ddl == "COPY") {
164  is_copy = true;
165  // now check if it is COPY TO
166  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s+.*)",
167  boost::regex::extended | boost::regex::icase};
168  if (boost::regex_match(query_string, copy_to)) {
170  is_copy_to = true;
171  } else {
173  }
174  } else if (ddl == "SHOW") {
176  boost::regex show_create_table_regex{
177  R"(SHOW\s+CREATE\s+TABLE\s+.*)",
178  boost::regex::extended | boost::regex::icase};
179  if (!boost::regex_match(query_string, show_create_table_regex)) {
180  is_calcite_ddl_ = true;
181  is_legacy_ddl_ = false;
182  return;
183  }
184  } else if (ddl == "DROP") {
186  boost::regex drop_table_regex{R"(DROP\s+TABLE.*)",
187  boost::regex::extended | boost::regex::icase};
188  boost::regex drop_view_regex{R"(DROP\s+VIEW.*)",
189  boost::regex::extended | boost::regex::icase};
191  (boost::regex_match(query_string, drop_table_regex) ||
192  boost::regex_match(query_string, drop_view_regex))) {
193  is_calcite_ddl_ = true;
194  is_legacy_ddl_ = false;
195  return;
196  }
197  } else if (ddl == "KILL") {
199  is_calcite_ddl_ = true;
200  is_legacy_ddl_ = false;
201  return;
202  }
204  return;
205  }
206  }
207 
208  for (int i = 0; i < update_dml_cmd.size(); i++) {
209  is_update_dml = boost::istarts_with(query_string, ParserWrapper::update_dml_cmd[i]);
210  if (is_update_dml) {
212  dml_type_ = (DMLType)(i);
213  break;
214  }
215  }
216 
217  if (dml_type_ == DMLType::Insert) {
218  boost::regex insert_regex{R"(INSERT\s+INTO.*VALUES\s*\(.*)",
219  boost::regex::extended | boost::regex::icase};
220  if (!boost::regex_match(query_string, insert_regex)) {
221  boost::regex itas_regex{R"(INSERT\s+INTO.*(\s|\(|\")+SELECT.*)",
222  boost::regex::extended | boost::regex::icase};
223  if (boost::regex_match(query_string, itas_regex)) {
224  is_itas = true;
225  }
226  }
227  }
228 }
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:72
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:91
ParserWrapper::~ParserWrapper ( )
virtual

Definition at line 230 of file ParserWrapper.cpp.

230 {}

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

References is_calcite_ddl_.

115 { 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, isCalcitePermissableDml(), and Other.

99  {
101  isCalcitePermissableDml(read_only_mode) &&
103  }
bool isCalcitePermissableDml(bool read_only_mode)
ExplainType explain_type_

+ Here is the call graph for this function:

bool ParserWrapper::isCalcitePermissableDml ( bool  read_only_mode)
inline

Definition at line 107 of file ParserWrapper.h.

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

Referenced by isCalcitePathPermissable().

107  {
108  if (read_only_mode) {
109  return !is_update_dml; // If we're read-only, no update/delete DML is permissable
110  }
113  }
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 105 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 125 of file ParserWrapper.h.

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

Definition at line 122 of file ParserWrapper.h.

DMLType ParserWrapper::dml_type_ = DMLType::NotDML
private

Definition at line 118 of file ParserWrapper.h.

Referenced by getDMLType(), and isUpdateDelete().

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

Definition at line 124 of file ParserWrapper.h.

bool ParserWrapper::is_calcite_ddl_ = false
private

Definition at line 132 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.

bool ParserWrapper::is_legacy_ddl_ = false
private

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

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

Definition at line 126 of file ParserWrapper.h.

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

Definition at line 127 of file ParserWrapper.h.

QueryType ParserWrapper::query_type_ = QueryType::Unknown
private

Definition at line 120 of file ParserWrapper.h.

Referenced by getQueryType().

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

Definition at line 123 of file ParserWrapper.h.

Referenced by ParserWrapper().

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

Definition at line 129 of file ParserWrapper.h.


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