OmniSciDB  72180abbfe
 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 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 61 of file ParserWrapper.cpp.

References g_enable_fsi, logger::IR, and update_dml_cmd.

61  {
63  if (boost::istarts_with(query_string, calcite_explain_str)) {
64  actual_query = boost::trim_copy(query_string.substr(calcite_explain_str.size()));
66  if (inner.is_ddl || inner.is_update_dml) {
68  return;
69  } else {
71  return;
72  }
73  }
74 
75  if (boost::istarts_with(query_string, optimized_explain_str)) {
76  actual_query = boost::trim_copy(query_string.substr(optimized_explain_str.size()));
78  if (inner.is_ddl || inner.is_update_dml) {
80  return;
81  } else {
83  return;
84  }
85  }
86 
87  if (boost::istarts_with(query_string, plan_explain_str)) {
88  actual_query = boost::trim_copy(query_string.substr(plan_explain_str.size()));
90  if (inner.is_ddl || inner.is_update_dml) {
92  return;
93  } else {
95  return;
96  }
97  }
98 
99  if (boost::istarts_with(query_string, explain_str)) {
100  actual_query = boost::trim_copy(query_string.substr(explain_str.size()));
102  if (inner.is_ddl || inner.is_update_dml) {
104  return;
105  } else {
107  return;
108  }
109  }
110 
111  if (boost::istarts_with(query_string, optimize_str)) {
113  is_optimize = true;
114  return;
115  }
116 
117  if (boost::istarts_with(query_string, validate_str)) {
118  is_validate = true;
119  return;
120  }
122  for (std::string ddl : ddl_cmd) {
123  is_ddl = boost::istarts_with(query_string, ddl);
124  if (is_ddl) {
126  if (g_enable_fsi) {
127  std::string fsi_regex_pattern{
128  R"((CREATE|DROP|ALTER)\s+(SERVER|FOREIGN\s+TABLE).*)"};
129 
130  boost::regex fsi_regex{fsi_regex_pattern,
131  boost::regex::extended | boost::regex::icase};
132  boost::regex refresh_regex{R"(REFRESH\s+FOREIGN\s+TABLES.*)",
133  boost::regex::extended | boost::regex::icase};
134 
135  if (boost::regex_match(query_string, fsi_regex) ||
136  boost::regex_match(query_string, refresh_regex)) {
137  is_calcite_ddl_ = true;
138  is_legacy_ddl_ = false;
139  return;
140  }
141  }
142  if (ddl == "CREATE") {
143  boost::regex ctas_regex{R"(CREATE\s+TABLE.*AS.*SELECT.*)",
144  boost::regex::extended | boost::regex::icase};
145  if (boost::regex_match(query_string, ctas_regex)) {
146  is_ctas = true;
147  }
148  } else if (ddl == "COPY") {
149  is_copy = true;
150  // now check if it is COPY TO
151  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s+.*)",
152  boost::regex::extended | boost::regex::icase};
153  if (boost::regex_match(query_string, copy_to)) {
155  is_copy_to = true;
156  } else {
158  }
159  } else if (ddl == "SHOW") {
161  boost::regex show_create_table_regex{
162  R"(SHOW\s+CREATE\s+TABLE\s+.*)",
163  boost::regex::extended | boost::regex::icase};
164  if (!boost::regex_match(query_string, show_create_table_regex)) {
165  is_calcite_ddl_ = true;
166  is_legacy_ddl_ = false;
167  return;
168  }
169  }
170 
172  return;
173  }
174  }
175 
176  for (int i = 0; i < update_dml_cmd.size(); i++) {
177  is_update_dml = boost::istarts_with(query_string, ParserWrapper::update_dml_cmd[i]);
178  if (is_update_dml) {
180  dml_type_ = (DMLType)(i);
181  break;
182  }
183  }
184 
185  if (dml_type_ == DMLType::Insert) {
186  boost::regex insert_regex{R"(INSERT\s+INTO.*VALUES\s*\(.*)",
187  boost::regex::extended | boost::regex::icase};
188  if (!boost::regex_match(query_string, insert_regex)) {
189  boost::regex itas_regex{R"(INSERT\s+INTO.*SELECT.*)",
190  boost::regex::extended | boost::regex::icase};
191  if (boost::regex_match(query_string, itas_regex)) {
192  is_itas = true;
193  }
194  }
195  }
196 }
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
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:90
ParserWrapper::~ParserWrapper ( )
virtual

Definition at line 198 of file ParserWrapper.cpp.

198 {}

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

References is_calcite_ddl_.

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

Definition at line 81 of file ParserWrapper.h.

References Calcite, and explain_type_.

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

Definition at line 95 of file ParserWrapper.h.

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

95  {
97  isCalcitePermissableDml(read_only_mode) &&
99  }
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 103 of file ParserWrapper.h.

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

Referenced by isCalcitePathPermissable().

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

References explain_type_, and Other.

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

Definition at line 85 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:

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 121 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"}

Definition at line 118 of file ParserWrapper.h.

DMLType ParserWrapper::dml_type_ = DMLType::NotDML
private

Definition at line 114 of file ParserWrapper.h.

Referenced by getDMLType().

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

Definition at line 120 of file ParserWrapper.h.

bool ParserWrapper::is_calcite_ddl_ = false
private

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

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

Definition at line 122 of file ParserWrapper.h.

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

Definition at line 123 of file ParserWrapper.h.

QueryType ParserWrapper::query_type_ = QueryType::Unknown
private

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

Referenced by ParserWrapper().

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

Definition at line 125 of file ParserWrapper.h.


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