OmniSciDB  7bf56492aa
 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 #include "Shared/ConfigResolve.h"
32 
33 enum class CalciteDMLPathSelection : int {
34  Unsupported = 0,
35  OnlyUpdates = 1,
36  OnlyDeletes = 2,
38 };
39 
41  int selector = 0;
42  if (std::is_same<CalciteDeletePathSelector, PreprocessorTrue>::value) {
43  selector |= 0x02;
44  }
45  if (std::is_same<CalciteUpdatePathSelector, PreprocessorTrue>::value) {
46  selector |= 0x01;
47  }
48  return static_cast<CalciteDMLPathSelection>(selector);
49 }
50 
51 struct ExplainInfo {
52  bool explain;
56 
57  static ExplainInfo defaults() { return ExplainInfo{false, false, false, false}; }
58 
59  bool justExplain() const { return explain || explain_plan || explain_optimized; }
60 
61  bool justCalciteExplain() const { return calcite_explain; }
62 };
63 
65  public:
66  // HACK: This needs to go away as calcite takes over parsing
67  enum class DMLType : int { Insert = 0, Delete, Update, Upsert, NotDML };
68 
70 
71  ParserWrapper(std::string query_string);
72  std::string process(std::string user,
73  std::string passwd,
74  std::string catalog,
75  std::string sql_string,
76  const bool legacy_syntax);
77  virtual ~ParserWrapper();
78 
79  bool is_ddl = false;
80  bool is_update_dml = false;
81  bool is_ctas = false;
82  bool is_itas = false;
83  bool is_copy = false;
84  bool is_copy_to = false;
85  bool is_optimize = false;
86  bool is_validate = false;
87  std::string actual_query;
88 
89  DMLType getDMLType() const { return dml_type_; }
90 
92 
94 
96 
98 
99  bool isSelectExplain() const {
103  }
104 
105  bool isIRExplain() const {
107  }
108 
109  bool isCalcitePathPermissable(bool read_only_mode = false) {
111  isCalcitePermissableDml(read_only_mode) &&
113  }
114 
115  bool isOtherExplain() const { return explain_type_ == ExplainType::Other; }
116 
117  bool isCalcitePermissableDml(bool read_only_mode) {
118  if (read_only_mode) {
119  return !is_update_dml; // If we're read-only, no DML is permissable
120  }
121 
122  // TODO: A good place for if-constexpr
123  switch (yield_dml_path_selector()) {
132  default:
133  return false;
134  }
135  }
136 
137  bool isCalciteDdl() const { return is_calcite_ddl_; }
138 
139  private:
142 
143  static const std::vector<std::string> ddl_cmd;
144  static const std::vector<std::string> update_dml_cmd;
145  static const std::string explain_str;
146  static const std::string calcite_explain_str;
147  static const std::string optimized_explain_str;
148  static const std::string plan_explain_str;
149  static const std::string optimize_str;
150  static const std::string validate_str;
151 
152  bool is_legacy_ddl_ = false;
153  bool is_calcite_ddl_ = false;
154 };
static const std::string optimize_str
static ExplainInfo defaults()
Definition: ParserWrapper.h:57
bool isCalciteDdl() const
virtual ~ParserWrapper()
ExplainType getExplainType() const
Definition: ParserWrapper.h:93
CalciteDMLPathSelection
Definition: ParserWrapper.h:33
static const std::string optimized_explain_str
bool isPlanExplain() const
Definition: ParserWrapper.h:97
bool isSelectExplain() const
Definition: ParserWrapper.h:99
ExplainInfo getExplainInfo() const
bool isIRExplain() const
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:87
bool isCalcitePathPermissable(bool read_only_mode=false)
DMLType dml_type_
bool justExplain() const
Definition: ParserWrapper.h:59
bool explain_plan
Definition: ParserWrapper.h:54
static const std::vector< std::string > ddl_cmd
DMLType getDMLType() const
Definition: ParserWrapper.h:89
bool calcite_explain
Definition: ParserWrapper.h:55
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:53
constexpr CalciteDMLPathSelection yield_dml_path_selector()
Definition: ParserWrapper.h:40
ParserWrapper(std::string query_string)
bool isCalciteExplain() const
Definition: ParserWrapper.h:95
ExplainType explain_type_
bool isOtherExplain() const
bool justCalciteExplain() const
Definition: ParserWrapper.h:61