26 #include <boost/algorithm/string.hpp>
45 if (boost::istarts_with(query_string,
explain_str)) {
48 explain_type_ = ExplainType::Calcite;
51 explain_type_ = ExplainType::OptimizedIR;
58 actual_query_ = boost::trim_copy(query_string.substr(
plan_explain_str.size()));
60 explain_type_ = ExplainType::ExecutionPlan;
62 actual_query_ = boost::trim_copy(query_string.substr(
explain_str.size()));
67 if (inner.is_ddl || inner.is_update_dml) {
68 explain_type_ = ExplainType::Other;
74 "ARCHIVE",
"ALTER",
"COPY",
"CREATE",
"DROP",
"DUMP",
"EVALUATE",
75 "GRANT",
"KILL",
"OPTIMIZE",
"REFRESH",
"RENAME",
"RESTORE",
"REVOKE",
76 "SHOW",
"TRUNCATE",
"REASSIGN",
"VALIDATE",
"CLEAR",
"PAUSE",
"RESUME"};
85 if (boost::starts_with(query_str,
"--") || boost::starts_with(query_str,
"//") ||
86 boost::starts_with(query_str,
"/*")) {
87 throw std::runtime_error(
88 "SQL statements starting with comments are currently not allowed.");
102 query_type_ = QueryType::Read;
103 for (std::string ddl : ddl_cmd) {
104 if (boost::istarts_with(query_string, ddl)) {
105 query_type_ = QueryType::SchemaWrite;
108 if (ddl ==
"CREATE") {
109 boost::regex ctas_regex{
110 R
"(CREATE\s+(TEMPORARY\s+|\s*)+TABLE.*(\"|\s)AS(\(|\s)+(SELECT|WITH).*)",
111 boost::regex::extended | boost::regex::icase};
112 if (boost::regex_match(query_string, ctas_regex)) {
115 }
else if (ddl ==
"COPY") {
118 boost::regex copy_to{R
"(COPY\s*\(([^#])(.+)\)\s+TO\s+.*)",
119 boost::regex::extended | boost::regex::icase};
120 if (boost::regex_match(query_string, copy_to)) {
121 query_type_ = QueryType::Read;
124 query_type_ = QueryType::Write;
126 }
else if (ddl ==
"SHOW") {
127 query_type_ = QueryType::SchemaRead;
128 }
else if (ddl ==
"KILL") {
129 query_type_ = QueryType::Unknown;
130 }
else if (ddl ==
"VALIDATE") {
131 query_type_ = QueryType::Unknown;
134 }
else if (ddl ==
"ALTER") {
135 boost::regex alter_system_regex{R
"(ALTER\s+(SYSTEM|SESSION).*)",
136 boost::regex::extended | boost::regex::icase};
137 if (boost::regex_match(query_string, alter_system_regex)) {
138 query_type_ = QueryType::Unknown;
140 }
else if (ddl ==
"ARCHIVE" || ddl ==
"DUMP") {
141 query_type_ = QueryType::SchemaRead;
142 }
else if (ddl ==
"REFRESH") {
149 for (
int i = 0; i < update_dml_cmd.size(); i++) {
152 query_type_ = QueryType::Write;
158 if (dml_type_ == DMLType::Insert) {
159 boost::regex itas_regex{R
"(INSERT\s+INTO\s+.*(\s+|\(|\")SELECT(\s|\(|\").*)",
160 boost::regex::extended | boost::regex::icase};
161 if (boost::regex_match(query_string, itas_regex)) {
Classes used to wrap parser calls for calcite redirection.
const std::string plan_explain_str
void validate_no_leading_comments(const std::string &query_str)
const std::string plan_explain_detailed_str
const std::string calcite_explain_str
bool isOtherExplain() const
static const std::vector< std::string > ddl_cmd
const std::string optimize_str
const std::string optimized_explain_str
const std::string explain_str
static const std::vector< std::string > update_dml_cmd
const std::string validate_str
ParserWrapper(std::string query_string)