OmniSciDB  0fdbebe030
 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
}
 

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

Member Enumeration Documentation

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

Definition at line 67 of file ParserWrapper.h.

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

Definition at line 69 of file ParserWrapper.h.

69 { None, IR, OptimizedIR, Calcite, ExecutionPlan, Other };

Constructor & Destructor Documentation

ParserWrapper::ParserWrapper ( std::string  query_string)

Definition at line 60 of file ParserWrapper.cpp.

References g_enable_fsi, logger::IR, and update_dml_cmd.

60  {
61  if (boost::istarts_with(query_string, calcite_explain_str)) {
62  actual_query = boost::trim_copy(query_string.substr(calcite_explain_str.size()));
64  if (inner.is_ddl || inner.is_update_dml) {
66  return;
67  } else {
69  return;
70  }
71  }
72 
73  if (boost::istarts_with(query_string, optimized_explain_str)) {
74  actual_query = boost::trim_copy(query_string.substr(optimized_explain_str.size()));
76  if (inner.is_ddl || inner.is_update_dml) {
78  return;
79  } else {
81  return;
82  }
83  }
84 
85  if (boost::istarts_with(query_string, plan_explain_str)) {
86  actual_query = boost::trim_copy(query_string.substr(plan_explain_str.size()));
88  if (inner.is_ddl || inner.is_update_dml) {
90  return;
91  } else {
93  return;
94  }
95  }
96 
97  if (boost::istarts_with(query_string, explain_str)) {
98  actual_query = boost::trim_copy(query_string.substr(explain_str.size()));
100  if (inner.is_ddl || inner.is_update_dml) {
102  return;
103  } else {
105  return;
106  }
107  }
108 
109  if (boost::istarts_with(query_string, optimize_str)) {
110  is_optimize = true;
111  return;
112  }
113 
114  if (boost::istarts_with(query_string, validate_str)) {
115  is_validate = true;
116  return;
117  }
118  for (std::string ddl : ddl_cmd) {
119  is_ddl = boost::istarts_with(query_string, ddl);
120  if (is_ddl) {
121  if (g_enable_fsi) {
122  boost::regex fsi_regex{R"((CREATE|DROP)\s+(SERVER|FOREIGN\s+TABLE).*)",
123  boost::regex::extended | boost::regex::icase};
124  if (boost::regex_match(query_string, fsi_regex)) {
125  is_calcite_ddl_ = true;
126  is_legacy_ddl_ = false;
127  return;
128  }
129  }
130  if (ddl == "CREATE") {
131  boost::regex ctas_regex{R"(CREATE\s+TABLE.*AS.*SELECT.*)",
132  boost::regex::extended | boost::regex::icase};
133  if (boost::regex_match(query_string, ctas_regex)) {
134  is_ctas = true;
135  }
136  } else if (ddl == "COPY") {
137  is_copy = true;
138  // now check if it is COPY TO
139  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s+.*)",
140  boost::regex::extended | boost::regex::icase};
141  if (boost::regex_match(query_string, copy_to)) {
142  is_copy_to = true;
143  }
144  } else if (ddl == "SHOW") {
145  is_calcite_ddl_ = true;
146  is_legacy_ddl_ = false;
147  return;
148  }
149 
151  return;
152  }
153  }
154 
155  for (int i = 0; i < update_dml_cmd.size(); i++) {
156  is_update_dml = boost::istarts_with(query_string, ParserWrapper::update_dml_cmd[i]);
157  if (is_update_dml) {
158  dml_type_ = (DMLType)(i);
159  break;
160  }
161  }
162 
163  if (dml_type_ == DMLType::Insert) {
164  boost::regex insert_regex{R"(INSERT\s+INTO.*VALUES\s*\(.*)",
165  boost::regex::extended | boost::regex::icase};
166  if (!boost::regex_match(query_string, insert_regex)) {
167  boost::regex itas_regex{R"(INSERT\s+INTO.*SELECT.*)",
168  boost::regex::extended | boost::regex::icase};
169  if (boost::regex_match(query_string, itas_regex)) {
170  is_itas = true;
171  }
172  }
173  }
174 }
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:87
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:89
ParserWrapper::~ParserWrapper ( )
virtual

Definition at line 176 of file ParserWrapper.cpp.

176 {}

Member Function Documentation

DMLType ParserWrapper::getDMLType ( ) const
inline

Definition at line 89 of file ParserWrapper.h.

References dml_type_.

Referenced by isCalcitePermissableDml().

89 { return dml_type_; }
DMLType dml_type_

+ Here is the caller graph for this function:

ExplainType ParserWrapper::getExplainType ( ) const
inline

Definition at line 93 of file ParserWrapper.h.

References explain_type_.

93 { return explain_type_; }
ExplainType explain_type_
bool ParserWrapper::isCalciteDdl ( ) const
inline

Definition at line 137 of file ParserWrapper.h.

References is_calcite_ddl_.

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

Definition at line 95 of file ParserWrapper.h.

References Calcite, and explain_type_.

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

Definition at line 109 of file ParserWrapper.h.

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

109  {
111  isCalcitePermissableDml(read_only_mode) &&
113  }
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 117 of file ParserWrapper.h.

References Delete, getDMLType(), is_update_dml, OnlyDeletes, OnlyUpdates, Unsupported, Update, UpdatesAndDeletes, and yield_dml_path_selector().

Referenced by isCalcitePathPermissable().

117  {
118  if (read_only_mode) {
119  return !is_update_dml; // If we're read-only, no DML is permissable
120  }
121 
122  // TODO: A good place for if-constexpr
123  switch (yield_dml_path_selector()) {
132  default:
133  return false;
134  }
135  }
DMLType getDMLType() const
Definition: ParserWrapper.h:89
constexpr CalciteDMLPathSelection yield_dml_path_selector()
Definition: ParserWrapper.h:40

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

References explain_type_, and Other.

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

Definition at line 99 of file ParserWrapper.h.

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

Referenced by MapDHandler::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 87 of file ParserWrapper.h.

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

Definition at line 146 of file ParserWrapper.h.

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

Definition at line 143 of file ParserWrapper.h.

DMLType ParserWrapper::dml_type_ = DMLType::NotDML
private

Definition at line 140 of file ParserWrapper.h.

Referenced by getDMLType().

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

Definition at line 145 of file ParserWrapper.h.

bool ParserWrapper::is_calcite_ddl_ = false
private

Definition at line 153 of file ParserWrapper.h.

Referenced by isCalciteDdl(), and isCalcitePathPermissable().

bool ParserWrapper::is_copy = false

Definition at line 83 of file ParserWrapper.h.

bool ParserWrapper::is_copy_to = false

Definition at line 84 of file ParserWrapper.h.

bool ParserWrapper::is_ctas = false

Definition at line 81 of file ParserWrapper.h.

bool ParserWrapper::is_ddl = false

Definition at line 79 of file ParserWrapper.h.

bool ParserWrapper::is_itas = false

Definition at line 82 of file ParserWrapper.h.

bool ParserWrapper::is_legacy_ddl_ = false
private

Definition at line 152 of file ParserWrapper.h.

Referenced by isCalcitePathPermissable().

bool ParserWrapper::is_optimize = false

Definition at line 85 of file ParserWrapper.h.

Referenced by isCalcitePathPermissable().

bool ParserWrapper::is_update_dml = false

Definition at line 80 of file ParserWrapper.h.

Referenced by isCalcitePermissableDml().

bool ParserWrapper::is_validate = false

Definition at line 86 of file ParserWrapper.h.

Referenced by isCalcitePathPermissable().

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

Definition at line 149 of file ParserWrapper.h.

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

Definition at line 147 of file ParserWrapper.h.

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

Definition at line 148 of file ParserWrapper.h.

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

Definition at line 144 of file ParserWrapper.h.

Referenced by ParserWrapper().

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

Definition at line 150 of file ParserWrapper.h.


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