OmniSciDB  dfae7c3b14
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

◆ DMLType

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

◆ ExplainType

Enumerator
None 
IR 
OptimizedIR 
Calcite 
ExecutionPlan 
Other 

Definition at line 49 of file ParserWrapper.h.

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

◆ QueryType

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

Definition at line 62 of file ParserWrapper.cpp.

References g_enable_fsi, logger::IR, and update_dml_cmd.

62  {
64  if (boost::istarts_with(query_string, calcite_explain_str)) {
65  actual_query = boost::trim_copy(query_string.substr(calcite_explain_str.size()));
67  if (inner.is_ddl || inner.is_update_dml) {
69  return;
70  } else {
72  return;
73  }
74  }
75 
76  if (boost::istarts_with(query_string, optimized_explain_str)) {
77  actual_query = boost::trim_copy(query_string.substr(optimized_explain_str.size()));
79  if (inner.is_ddl || inner.is_update_dml) {
81  return;
82  } else {
84  return;
85  }
86  }
87 
88  if (boost::istarts_with(query_string, plan_explain_str)) {
89  actual_query = boost::trim_copy(query_string.substr(plan_explain_str.size()));
91  if (inner.is_ddl || inner.is_update_dml) {
93  return;
94  } else {
96  return;
97  }
98  }
99 
100  if (boost::istarts_with(query_string, explain_str)) {
101  actual_query = boost::trim_copy(query_string.substr(explain_str.size()));
103  if (inner.is_ddl || inner.is_update_dml) {
105  return;
106  } else {
108  return;
109  }
110  }
111 
112  if (boost::istarts_with(query_string, optimize_str)) {
114  is_optimize = true;
115  return;
116  }
117 
118  if (boost::istarts_with(query_string, validate_str)) {
119  is_validate = true;
120  return;
121  }
123  for (std::string ddl : ddl_cmd) {
124  is_ddl = boost::istarts_with(query_string, ddl);
125  if (is_ddl) {
127  if (g_enable_fsi) {
128  std::string fsi_regex_pattern{
129  R"((CREATE|DROP|ALTER)\s+(SERVER|FOREIGN\s+TABLE).*)"};
130 
131  boost::regex fsi_regex{fsi_regex_pattern,
132  boost::regex::extended | boost::regex::icase};
133  boost::regex refresh_regex{R"(REFRESH\s+FOREIGN\s+TABLES.*)",
134  boost::regex::extended | boost::regex::icase};
135 
136  if (boost::regex_match(query_string, fsi_regex) ||
137  boost::regex_match(query_string, refresh_regex)) {
138  is_calcite_ddl_ = true;
139  is_legacy_ddl_ = false;
140  return;
141  }
142  }
143  if (ddl == "CREATE") {
144  boost::regex ctas_regex{R"(CREATE\s+TABLE.*AS.*SELECT.*)",
145  boost::regex::extended | boost::regex::icase};
146  if (boost::regex_match(query_string, ctas_regex)) {
147  is_ctas = true;
148  }
149  } else if (ddl == "COPY") {
150  is_copy = true;
151  // now check if it is COPY TO
152  boost::regex copy_to{R"(COPY\s*\(([^#])(.+)\)\s+TO\s+.*)",
153  boost::regex::extended | boost::regex::icase};
154  if (boost::regex_match(query_string, copy_to)) {
156  is_copy_to = true;
157  } else {
159  }
160  } else if (ddl == "SHOW") {
162  boost::regex show_create_table_regex{
163  R"(SHOW\s+CREATE\s+TABLE\s+.*)",
164  boost::regex::extended | boost::regex::icase};
165  if (!boost::regex_match(query_string, show_create_table_regex)) {
166  is_calcite_ddl_ = true;
167  is_legacy_ddl_ = false;
168  return;
169  }
170  } else if (ddl == "KILL") {
172  is_calcite_ddl_ = true;
173  is_legacy_ddl_ = false;
174  return;
175  }
177  return;
178  }
179  }
180 
181  for (int i = 0; i < update_dml_cmd.size(); i++) {
182  is_update_dml = boost::istarts_with(query_string, ParserWrapper::update_dml_cmd[i]);
183  if (is_update_dml) {
185  dml_type_ = (DMLType)(i);
186  break;
187  }
188  }
189 
190  if (dml_type_ == DMLType::Insert) {
191  boost::regex insert_regex{R"(INSERT\s+INTO.*VALUES\s*\(.*)",
192  boost::regex::extended | boost::regex::icase};
193  if (!boost::regex_match(query_string, insert_regex)) {
194  boost::regex itas_regex{R"(INSERT\s+INTO.*SELECT.*)",
195  boost::regex::extended | boost::regex::icase};
196  if (boost::regex_match(query_string, itas_regex)) {
197  is_itas = true;
198  }
199  }
200  }
201 }
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
bool g_enable_fsi
Definition: Catalog.cpp:91
ExplainType explain_type_

◆ ~ParserWrapper()

ParserWrapper::~ParserWrapper ( )
virtual

Definition at line 203 of file ParserWrapper.cpp.

203 {}

Member Function Documentation

◆ getDMLType()

DMLType ParserWrapper::getDMLType ( ) const
inline

Definition at line 73 of file ParserWrapper.h.

73 { return dml_type_; }
DMLType dml_type_

◆ getExplainInfo()

◆ getExplainType()

ExplainType ParserWrapper::getExplainType ( ) const
inline

Definition at line 77 of file ParserWrapper.h.

77 { return explain_type_; }
ExplainType explain_type_

◆ getQueryType()

QueryType ParserWrapper::getQueryType ( ) const
inline

Definition at line 79 of file ParserWrapper.h.

79 { return query_type_; }
QueryType query_type_

◆ isCalciteDdl()

bool ParserWrapper::isCalciteDdl ( ) const
inline

Definition at line 111 of file ParserWrapper.h.

111 { return is_calcite_ddl_; }

◆ isCalciteExplain()

bool ParserWrapper::isCalciteExplain ( ) const
inline

Definition at line 81 of file ParserWrapper.h.

◆ isCalcitePathPermissable()

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

Definition at line 95 of file ParserWrapper.h.

95  {
97  isCalcitePermissableDml(read_only_mode) &&
99  }
bool isCalcitePermissableDml(bool read_only_mode)
ExplainType explain_type_

◆ isCalcitePermissableDml()

bool ParserWrapper::isCalcitePermissableDml ( bool  read_only_mode)
inline

Definition at line 103 of file ParserWrapper.h.

References Delete, and Update.

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

◆ isIRExplain()

bool ParserWrapper::isIRExplain ( ) const
inline

◆ isOtherExplain()

bool ParserWrapper::isOtherExplain ( ) const
inline

Definition at line 101 of file ParserWrapper.h.

◆ isPlanExplain()

bool ParserWrapper::isPlanExplain ( ) const
inline

◆ isSelectExplain()

bool ParserWrapper::isSelectExplain ( ) const
inline

Definition at line 85 of file ParserWrapper.h.

References logger::IR.

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

◆ calcite_explain_str

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

Definition at line 121 of file ParserWrapper.h.

◆ ddl_cmd

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

◆ dml_type_

DMLType ParserWrapper::dml_type_ = DMLType::NotDML
private

Definition at line 114 of file ParserWrapper.h.

◆ explain_str

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

Definition at line 120 of file ParserWrapper.h.

◆ explain_type_

ExplainType ParserWrapper::explain_type_ = ExplainType::None
private

Definition at line 115 of file ParserWrapper.h.

◆ is_calcite_ddl_

bool ParserWrapper::is_calcite_ddl_ = false
private

Definition at line 128 of file ParserWrapper.h.

◆ is_copy

bool ParserWrapper::is_copy = false

Definition at line 67 of file ParserWrapper.h.

◆ is_copy_to

bool ParserWrapper::is_copy_to = false

Definition at line 68 of file ParserWrapper.h.

◆ is_ctas

bool ParserWrapper::is_ctas = false

Definition at line 65 of file ParserWrapper.h.

◆ is_ddl

bool ParserWrapper::is_ddl = false

Definition at line 61 of file ParserWrapper.h.

◆ is_itas

bool ParserWrapper::is_itas = false

Definition at line 66 of file ParserWrapper.h.

◆ is_legacy_ddl_

bool ParserWrapper::is_legacy_ddl_ = false
private

Definition at line 127 of file ParserWrapper.h.

◆ is_optimize

bool ParserWrapper::is_optimize = false

Definition at line 69 of file ParserWrapper.h.

◆ is_update_dml

bool ParserWrapper::is_update_dml = false

Definition at line 64 of file ParserWrapper.h.

◆ is_validate

bool ParserWrapper::is_validate = false

Definition at line 70 of file ParserWrapper.h.

◆ optimize_str

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

Definition at line 124 of file ParserWrapper.h.

◆ optimized_explain_str

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

Definition at line 122 of file ParserWrapper.h.

◆ plan_explain_str

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

Definition at line 123 of file ParserWrapper.h.

◆ query_type_

QueryType ParserWrapper::query_type_ = QueryType::Unknown
private

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

Referenced by ParserWrapper().

◆ validate_str

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: