OmniSciDB  1dac507f6e
 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::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
 
ExplainType getExplainType () const
 
bool isCalciteExplain () const
 
bool isSelectExplain () const
 
bool isIRExplain () const
 
bool isCalcitePathPermissable (bool read_only_mode=false)
 
bool isOtherExplain () const
 
bool isCalcitePermissableDml (bool read_only_mode)
 

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
 

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 optimize_str = {"optimize"}
 
static const std::string validate_str = {"validate"}
 

Detailed Description

Definition at line 51 of file ParserWrapper.h.

Member Enumeration Documentation

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

Definition at line 54 of file ParserWrapper.h.

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

Definition at line 56 of file ParserWrapper.h.

56 { None, IR, OptimizedIR, Calcite, Other };

Constructor & Destructor Documentation

ParserWrapper::ParserWrapper ( std::string  query_string)

Definition at line 57 of file ParserWrapper.cpp.

References logger::IR, and update_dml_cmd.

57  {
58  if (boost::istarts_with(query_string, calcite_explain_str)) {
59  actual_query = boost::trim_copy(query_string.substr(calcite_explain_str.size()));
61  if (inner.is_ddl || inner.is_update_dml) {
63  return;
64  } else {
66  return;
67  }
68  }
69 
70  if (boost::istarts_with(query_string, optimized_explain_str)) {
71  actual_query = boost::trim_copy(query_string.substr(optimized_explain_str.size()));
73  if (inner.is_ddl || inner.is_update_dml) {
75  return;
76  } else {
78  return;
79  }
80  }
81 
82  if (boost::istarts_with(query_string, explain_str)) {
83  actual_query = boost::trim_copy(query_string.substr(explain_str.size()));
85  if (inner.is_ddl || inner.is_update_dml) {
87  return;
88  } else {
90  return;
91  }
92  }
93 
94  if (boost::istarts_with(query_string, optimize_str)) {
95  is_optimize = true;
96  return;
97  }
98 
99  if (boost::istarts_with(query_string, validate_str)) {
100  is_validate = true;
101  return;
102  }
103 
104  for (std::string ddl : ddl_cmd) {
105  is_ddl = boost::istarts_with(query_string, ddl);
106  if (is_ddl) {
107  if (ddl == "CREATE") {
108  boost::regex ctas_regex{R"(CREATE\s+TABLE.*AS.*SELECT.*)",
109  boost::regex::extended | boost::regex::icase};
110  if (boost::regex_match(query_string, ctas_regex)) {
111  is_ctas = true;
112  }
113  } else if (ddl == "COPY") {
114  is_copy = true;
115  // now check if it is COPY TO
116  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s+.*)",
117  boost::regex::extended | boost::regex::icase};
118  if (boost::regex_match(query_string, copy_to)) {
119  is_copy_to = true;
120  }
121  }
122  return;
123  }
124  }
125 
126  for (int i = 0; i < update_dml_cmd.size(); i++) {
127  is_update_dml = boost::istarts_with(query_string, ParserWrapper::update_dml_cmd[i]);
128  if (is_update_dml) {
129  dml_type_ = (DMLType)(i);
130  break;
131  }
132  }
133 
134  if (dml_type_ == DMLType::Insert) {
135  boost::regex insert_regex{R"(INSERT\s+INTO.*VALUES\s*\(.*)",
136  boost::regex::extended | boost::regex::icase};
137  if (!boost::regex_match(query_string, insert_regex)) {
138  boost::regex itas_regex{R"(INSERT\s+INTO.*SELECT.*)",
139  boost::regex::extended | boost::regex::icase};
140  if (boost::regex_match(query_string, itas_regex)) {
141  is_itas = true;
142  }
143  }
144  }
145 }
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:74
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
ExplainType explain_type_
ParserWrapper::~ParserWrapper ( )
virtual

Definition at line 147 of file ParserWrapper.cpp.

147 {}

Member Function Documentation

DMLType ParserWrapper::getDMLType ( ) const
inline

Definition at line 76 of file ParserWrapper.h.

References dml_type_.

Referenced by isCalcitePermissableDml().

76 { return dml_type_; }
DMLType dml_type_

+ Here is the caller graph for this function:

ExplainType ParserWrapper::getExplainType ( ) const
inline

Definition at line 78 of file ParserWrapper.h.

References explain_type_.

78 { return explain_type_; }
ExplainType explain_type_
bool ParserWrapper::isCalciteExplain ( ) const
inline

Definition at line 80 of file ParserWrapper.h.

References Calcite, and explain_type_.

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

Definition at line 91 of file ParserWrapper.h.

References explain_type_, is_ddl, is_optimize, is_validate, isCalcitePermissableDml(), and Other.

91  {
92  return (!is_ddl && !is_optimize && !is_validate &&
93  isCalcitePermissableDml(read_only_mode) &&
95  }
bool isCalcitePermissableDml(bool read_only_mode)
Definition: ParserWrapper.h:99
ExplainType explain_type_

+ Here is the call graph for this function:

bool ParserWrapper::isCalcitePermissableDml ( bool  read_only_mode)
inline

Definition at line 99 of file ParserWrapper.h.

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

Referenced by isCalcitePathPermissable().

99  {
100  if (read_only_mode) {
101  return !is_update_dml; // If we're read-only, no DML is permissable
102  }
103 
104  // TODO: A good place for if-constexpr
105  switch (yield_dml_path_selector()) {
114  default:
115  return false;
116  }
117  }
DMLType getDMLType() const
Definition: ParserWrapper.h:76
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 97 of file ParserWrapper.h.

References explain_type_, and Other.

bool ParserWrapper::isSelectExplain ( ) const
inline

Definition at line 82 of file ParserWrapper.h.

References Calcite, 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 74 of file ParserWrapper.h.

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

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

DMLType ParserWrapper::dml_type_ = DMLType::NotDML
private

Definition at line 120 of file ParserWrapper.h.

Referenced by getDMLType().

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

Definition at line 125 of file ParserWrapper.h.

ExplainType ParserWrapper::explain_type_ = ExplainType::None
private
bool ParserWrapper::is_copy = false

Definition at line 70 of file ParserWrapper.h.

bool ParserWrapper::is_copy_to = false

Definition at line 71 of file ParserWrapper.h.

bool ParserWrapper::is_ctas = false

Definition at line 68 of file ParserWrapper.h.

bool ParserWrapper::is_ddl = false

Definition at line 66 of file ParserWrapper.h.

Referenced by isCalcitePathPermissable().

bool ParserWrapper::is_itas = false

Definition at line 69 of file ParserWrapper.h.

bool ParserWrapper::is_optimize = false

Definition at line 72 of file ParserWrapper.h.

Referenced by isCalcitePathPermissable().

bool ParserWrapper::is_update_dml = false

Definition at line 67 of file ParserWrapper.h.

Referenced by isCalcitePermissableDml().

bool ParserWrapper::is_validate = false

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

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

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