OmniSciDB  72180abbfe
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParserWrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
25 #pragma once
26 
27 #include <boost/regex.hpp>
28 #include <string>
29 #include <vector>
30 
31 struct ExplainInfo {
32  bool explain;
36 
37  static ExplainInfo defaults() { return ExplainInfo{false, false, false, false}; }
38 
39  bool justExplain() const { return explain || explain_plan || explain_optimized; }
40 
41  bool justCalciteExplain() const { return calcite_explain; }
42 };
43 
45  public:
46  // HACK: This needs to go away as calcite takes over parsing
47  enum class DMLType : int { Insert = 0, Delete, Update, Upsert, NotDML };
48 
50 
52 
53  ParserWrapper(std::string query_string);
54  std::string process(std::string user,
55  std::string passwd,
56  std::string catalog,
57  std::string sql_string,
58  const bool legacy_syntax);
59  virtual ~ParserWrapper();
60 
61  bool is_ddl = false;
62  // is_update_dml does not imply UPDATE,
63  // but rather any of the statement types: INSERT DELETE UPDATE UPSERT
64  bool is_update_dml = false;
65  bool is_ctas = false;
66  bool is_itas = false;
67  bool is_copy = false;
68  bool is_copy_to = false;
69  bool is_optimize = false;
70  bool is_validate = false;
71  std::string actual_query;
72 
73  DMLType getDMLType() const { return dml_type_; }
74 
76 
78 
79  QueryType getQueryType() const { return query_type_; }
80 
82 
84 
85  bool isSelectExplain() const {
89  }
90 
91  bool isIRExplain() const {
93  }
94 
95  bool isCalcitePathPermissable(bool read_only_mode = false) {
97  isCalcitePermissableDml(read_only_mode) &&
99  }
100 
101  bool isOtherExplain() const { return explain_type_ == ExplainType::Other; }
102 
103  bool isCalcitePermissableDml(bool read_only_mode) {
104  if (read_only_mode) {
105  return !is_update_dml; // If we're read-only, no update/delete DML is permissable
106  }
109  }
110 
111  bool isCalciteDdl() const { return is_calcite_ddl_; }
112 
113  private:
117 
118  static const std::vector<std::string> ddl_cmd;
119  static const std::vector<std::string> update_dml_cmd;
120  static const std::string explain_str;
121  static const std::string calcite_explain_str;
122  static const std::string optimized_explain_str;
123  static const std::string plan_explain_str;
124  static const std::string optimize_str;
125  static const std::string validate_str;
126 
127  bool is_legacy_ddl_ = false;
128  bool is_calcite_ddl_ = false;
129 };
QueryType query_type_
static const std::string optimize_str
static ExplainInfo defaults()
Definition: ParserWrapper.h:37
bool isCalciteDdl() const
virtual ~ParserWrapper()
ExplainType getExplainType() const
Definition: ParserWrapper.h:77
static const std::string optimized_explain_str
bool isPlanExplain() const
Definition: ParserWrapper.h:83
bool isSelectExplain() const
Definition: ParserWrapper.h:85
ExplainInfo getExplainInfo() const
bool isIRExplain() const
Definition: ParserWrapper.h:91
std::string process(std::string user, std::string passwd, std::string catalog, std::string sql_string, const bool legacy_syntax)
static const std::string calcite_explain_str
std::string actual_query
Definition: ParserWrapper.h:71
bool isCalcitePathPermissable(bool read_only_mode=false)
Definition: ParserWrapper.h:95
DMLType dml_type_
bool justExplain() const
Definition: ParserWrapper.h:39
bool explain_plan
Definition: ParserWrapper.h:34
QueryType getQueryType() const
Definition: ParserWrapper.h:79
static const std::vector< std::string > ddl_cmd
DMLType getDMLType() const
Definition: ParserWrapper.h:73
bool calcite_explain
Definition: ParserWrapper.h:35
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 isCalcitePermissableDml(bool read_only_mode)
bool explain_optimized
Definition: ParserWrapper.h:33
ParserWrapper(std::string query_string)
bool isCalciteExplain() const
Definition: ParserWrapper.h:81
ExplainType explain_type_
bool isOtherExplain() const
bool justCalciteExplain() const
Definition: ParserWrapper.h:41