26 #include <boost/algorithm/string.hpp>
46 if (boost::istarts_with(query_string,
explain_str)) {
49 explain_type_ = ExplainType::CalciteDetail;
54 explain_type_ = ExplainType::Calcite;
58 explain_type_ = ExplainType::OptimizedIR;
65 actual_query_ = boost::trim_copy(query_string.substr(
plan_explain_str.size()));
67 explain_type_ = ExplainType::ExecutionPlan;
69 actual_query_ = boost::trim_copy(query_string.substr(
explain_str.size()));
74 if (inner.is_ddl || inner.is_update_dml) {
75 explain_type_ = ExplainType::Other;
81 "ARCHIVE",
"ALTER",
"COPY",
"CREATE",
"DROP",
"DUMP",
"EVALUATE",
82 "GRANT",
"KILL",
"OPTIMIZE",
"REFRESH",
"RENAME",
"RESTORE",
"REVOKE",
83 "SHOW",
"TRUNCATE",
"REASSIGN",
"VALIDATE",
"CLEAR",
"PAUSE",
"RESUME"};
92 if (boost::starts_with(query_str,
"--") || boost::starts_with(query_str,
"//") ||
93 boost::starts_with(query_str,
"/*")) {
94 throw std::runtime_error(
95 "SQL statements starting with comments are currently not allowed.");
109 query_type_ = QueryType::Read;
110 for (std::string ddl : ddl_cmd) {
111 if (boost::istarts_with(query_string, ddl)) {
112 query_type_ = QueryType::SchemaWrite;
115 if (ddl ==
"CREATE") {
116 boost::regex ctas_regex{
117 R
"(CREATE\s+(TEMPORARY\s+|\s*)+TABLE.*(\"|\s)AS(\(|\s)+(SELECT|WITH).*)",
118 boost::regex::extended | boost::regex::icase};
119 if (boost::regex_match(query_string, ctas_regex)) {
122 }
else if (ddl ==
"COPY") {
125 boost::regex copy_to{R
"(COPY\s*\(([^#])(.+)\)\s+TO\s+.*)",
126 boost::regex::extended | boost::regex::icase};
127 if (boost::regex_match(query_string, copy_to)) {
128 query_type_ = QueryType::Read;
131 query_type_ = QueryType::Write;
133 }
else if (ddl ==
"SHOW") {
134 query_type_ = QueryType::SchemaRead;
135 }
else if (ddl ==
"KILL") {
136 query_type_ = QueryType::Unknown;
137 }
else if (ddl ==
"VALIDATE") {
138 query_type_ = QueryType::Unknown;
141 }
else if (ddl ==
"ALTER") {
142 boost::regex alter_system_regex{R
"(ALTER\s+(SYSTEM|SESSION).*)",
143 boost::regex::extended | boost::regex::icase};
144 if (boost::regex_match(query_string, alter_system_regex)) {
145 query_type_ = QueryType::Unknown;
147 }
else if (ddl ==
"ARCHIVE" || ddl ==
"DUMP") {
148 query_type_ = QueryType::SchemaRead;
149 }
else if (ddl ==
"REFRESH") {
156 for (
int i = 0; i < update_dml_cmd.size(); i++) {
159 query_type_ = QueryType::Write;
165 if (dml_type_ == DMLType::Insert) {
166 boost::regex itas_regex{R
"(INSERT\s+INTO\s+.*(\s+|\(|\")SELECT(\s|\(|\").*)",
167 boost::regex::extended | boost::regex::icase};
168 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 calcite_explain_detailed_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)