OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 <string>
28 #include <vector>
29 
31 
32 struct ExplainInfo {
33  bool explain;
37 
38  static ExplainInfo defaults() { return ExplainInfo{false, false, false, false}; }
39 
40  bool justExplain() const { return explain || explain_plan || explain_optimized; }
41 
42  bool justCalciteExplain() const { return calcite_explain; }
43 };
44 
46  public:
47  // HACK: This needs to go away as calcite takes over parsing
48  enum class DMLType : int { Insert = 0, Delete, Update, Upsert, NotDML };
49 
51 
53 
54  ParserWrapper(std::string query_string);
55  std::string process(std::string user,
56  std::string passwd,
57  std::string catalog,
58  std::string sql_string,
59  const bool legacy_syntax);
60  virtual ~ParserWrapper();
61 
62  bool is_ddl_ = false;
63  // is_update_dml does not imply UPDATE,
64  // but rather any of the statement types: INSERT DELETE UPDATE UPSERT
65  bool is_update_dml = false;
66  bool is_ctas = false;
67  bool is_itas = false;
68  bool is_copy = false;
69  bool is_copy_to = false;
70  bool is_validate = false;
71 
72  DMLType getDMLType() const { return dml_type_; }
73 
75 
77 
78  QueryType getQueryType() const { return query_type_; }
79 
80  bool isUpdateDelete() const {
82  }
83 
85 
87 
88  bool isSelectExplain() const {
92  }
93 
94  bool isIRExplain() const {
96  }
97 
98  bool isCalcitePathPermissable(bool read_only_mode = false) {
99  if (is_ddl_) {
100  return isCalcitePermissableDdl(read_only_mode);
101  }
102  return (!is_validate && isCalcitePermissableDml(read_only_mode) &&
104  }
105 
106  bool isOtherExplain() const { return explain_type_ == ExplainType::Other; }
107 
108  bool isCalcitePermissableDml(bool read_only_mode = false) {
109  if (is_itas || is_ctas) {
110  return !read_only_mode;
111  }
112  if (read_only_mode) {
113  return !is_update_dml; // If we're read-only, no update/delete DML is permissable
114  }
118  }
119 
120  bool isCalcitePermissableDdl(bool read_only_mode) {
121  if (read_only_mode) {
122  // If we're read-only, no Write/SchemaWrite DDL is permissable
124  }
125  return true;
126  }
127 
128  bool isDdl() const { return is_ddl_; }
129 
130  std::string ActualQuery() { return actual_query_; }
131 
132  private:
133  void initExplainType(std::string query_string);
134  std::string actual_query_;
135 
139 
140  static const std::vector<std::string> ddl_cmd;
141  static const std::vector<std::string> update_dml_cmd;
142 
143  bool is_legacy_ddl_ = false;
144  bool is_calcite_ddl_ = false;
145 };
QueryType query_type_
static ExplainInfo defaults()
Definition: ParserWrapper.h:38
virtual ~ParserWrapper()
ExplainType getExplainType() const
Definition: ParserWrapper.h:76
bool isPlanExplain() const
Definition: ParserWrapper.h:86
std::string actual_query_
bool isCalcitePermissableDml(bool read_only_mode=false)
bool isSelectExplain() const
Definition: ParserWrapper.h:88
std::string ActualQuery()
ExplainInfo getExplainInfo() const
bool isIRExplain() const
Definition: ParserWrapper.h:94
std::string process(std::string user, std::string passwd, std::string catalog, std::string sql_string, const bool legacy_syntax)
bool isCalcitePathPermissable(bool read_only_mode=false)
Definition: ParserWrapper.h:98
DMLType dml_type_
bool justExplain() const
Definition: ParserWrapper.h:40
bool explain_plan
Definition: ParserWrapper.h:35
QueryType getQueryType() const
Definition: ParserWrapper.h:78
void initExplainType(std::string query_string)
static const std::vector< std::string > ddl_cmd
DMLType getDMLType() const
Definition: ParserWrapper.h:72
bool calcite_explain
Definition: ParserWrapper.h:36
static const std::vector< std::string > update_dml_cmd
bool isDdl() const
bool explain_optimized
Definition: ParserWrapper.h:34
ParserWrapper(std::string query_string)
bool isCalciteExplain() const
Definition: ParserWrapper.h:84
ExplainType explain_type_
bool isUpdateDelete() const
Definition: ParserWrapper.h:80
bool isOtherExplain() const
bool isCalcitePermissableDdl(bool read_only_mode)
bool justCalciteExplain() const
Definition: ParserWrapper.h:42