OmniSciDB  04ee39c94c
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

◆ DMLType

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 };

◆ ExplainType

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::ParserWrapper ( std::string  query_string)

Definition at line 54 of file ParserWrapper.cpp.

References logger::IR, and update_dml_cmd.

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

Definition at line 144 of file ParserWrapper.cpp.

144 {}

Member Function Documentation

◆ getDMLType()

DMLType ParserWrapper::getDMLType ( ) const
inline

Definition at line 76 of file ParserWrapper.h.

76 { return dml_type_; }
DMLType dml_type_

◆ getExplainType()

ExplainType ParserWrapper::getExplainType ( ) const
inline

Definition at line 78 of file ParserWrapper.h.

78 { return explain_type_; }
ExplainType explain_type_

◆ isCalciteExplain()

bool ParserWrapper::isCalciteExplain ( ) const
inline

Definition at line 80 of file ParserWrapper.h.

◆ isCalcitePathPermissable()

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

Definition at line 91 of file ParserWrapper.h.

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_

◆ isCalcitePermissableDml()

bool ParserWrapper::isCalcitePermissableDml ( bool  read_only_mode)
inline

Definition at line 99 of file ParserWrapper.h.

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

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:

◆ isIRExplain()

bool ParserWrapper::isIRExplain ( ) const
inline

◆ isOtherExplain()

bool ParserWrapper::isOtherExplain ( ) const
inline

Definition at line 97 of file ParserWrapper.h.

◆ isSelectExplain()

bool ParserWrapper::isSelectExplain ( ) const
inline

Definition at line 82 of file ParserWrapper.h.

References logger::IR.

Referenced by MapDHandler::parse_to_plan(), and MapDHandler::parse_to_ra().

+ Here is the caller graph for this function:

◆ process()

std::string ParserWrapper::process ( std::string  user,
std::string  passwd,
std::string  catalog,
std::string  sql_string,
const bool  legacy_syntax 
)

Member Data Documentation

◆ actual_query

std::string ParserWrapper::actual_query

Definition at line 74 of file ParserWrapper.h.

◆ calcite_explain_str

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

Definition at line 126 of file ParserWrapper.h.

◆ ddl_cmd

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

Definition at line 123 of file ParserWrapper.h.

◆ dml_type_

DMLType ParserWrapper::dml_type_ = DMLType::NotDML
private

Definition at line 120 of file ParserWrapper.h.

◆ explain_str

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

Definition at line 125 of file ParserWrapper.h.

◆ explain_type_

ExplainType ParserWrapper::explain_type_ = ExplainType::None
private

Definition at line 121 of file ParserWrapper.h.

◆ is_copy

bool ParserWrapper::is_copy = false

Definition at line 70 of file ParserWrapper.h.

◆ is_copy_to

bool ParserWrapper::is_copy_to = false

Definition at line 71 of file ParserWrapper.h.

◆ is_ctas

bool ParserWrapper::is_ctas = false

Definition at line 68 of file ParserWrapper.h.

◆ is_ddl

bool ParserWrapper::is_ddl = false

Definition at line 66 of file ParserWrapper.h.

◆ is_itas

bool ParserWrapper::is_itas = false

Definition at line 69 of file ParserWrapper.h.

◆ is_optimize

bool ParserWrapper::is_optimize = false

Definition at line 72 of file ParserWrapper.h.

◆ is_update_dml

bool ParserWrapper::is_update_dml = false

Definition at line 67 of file ParserWrapper.h.

◆ is_validate

bool ParserWrapper::is_validate = false

Definition at line 73 of file ParserWrapper.h.

◆ optimize_str

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

Definition at line 128 of file ParserWrapper.h.

◆ optimized_explain_str

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

Definition at line 127 of file ParserWrapper.h.

◆ update_dml_cmd

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().

◆ validate_str

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: